Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer and deserializer builders #204

Merged
merged 5 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void Main(string[] args)
runner.Run(new Program(), args);
}

private readonly Serializer _serializer = new Serializer();
private readonly Serializer _serializer = new SerializerBuilder().Build();

public void Serialize(TextWriter writer, object graph)
{
Expand Down
22 changes: 2 additions & 20 deletions YamlDotNet.Test/Core/EmitterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ public void CompareOriginalAndEmittedText(string filename)
var stream = Yaml.StreamFrom(filename);

var originalEvents = ParsingEventsOf(stream.ReadToEnd());
originalEvents.Run(x => Dump.WriteLine(x));
var emittedText = EmittedTextFrom(originalEvents);
Dump.WriteLine(emittedText);
var emittedEvents = ParsingEventsOf(emittedText);
emittedEvents.Run(x => Dump.WriteLine(x));

emittedEvents.ShouldAllBeEquivalentTo(originalEvents,
opt => opt.Excluding(@event => @event.Start)
Expand Down Expand Up @@ -101,7 +98,6 @@ public void PlainScalarCanBeFollowedByDocumentWithVersion()

var yaml = EmittedTextFrom(events);

Dump.WriteLine(yaml);
yaml.Should().Contain(Lines("test", "...", "%YAML 1.1", "--- test"));
}

Expand All @@ -114,7 +110,6 @@ public void PlainScalarCanBeFollowedByDocumentWithDefaultTags()

var yaml = EmittedTextFrom(events);

Dump.WriteLine(yaml);
yaml.Should().Contain(Lines("test", "--- test"));
}

Expand All @@ -127,7 +122,6 @@ public void PlainScalarCanBeFollowedByDocumentWithCustomTags()

var yaml = EmittedTextFrom(events);

Dump.WriteLine(yaml);
yaml.Should().Contain(Lines("test", "...", FooTag, ExTag, ExExTag, "--- test"));
}

Expand All @@ -140,8 +134,6 @@ public void BlockCanBeFollowedByImplicitDocument()

var yaml = EmittedTextFrom(events);

Dump.WriteLine(yaml);

yaml.Should().Contain(Lines("- 'test'", "--- test"));
}

Expand All @@ -154,7 +146,6 @@ public void BlockCanBeFollowedByDocumentWithVersion()

var yaml = EmittedTextFrom(events);

Dump.WriteLine(yaml);
yaml.Should().Contain(Lines("- 'test'", "...", "%YAML 1.1", "--- test"));
}

Expand All @@ -167,7 +158,6 @@ public void BlockCanBeFollowedByDocumentWithDefaultTags()

var yaml = EmittedTextFrom(events);

Dump.WriteLine(yaml);
yaml.Should().Contain(Lines("- 'test'", "--- test"));
}

Expand All @@ -180,7 +170,6 @@ public void BlockCanBeFollowedByDocumentWithCustomTags()

var yaml = EmittedTextFrom(events);

Dump.WriteLine(yaml);
yaml.Should().Contain(Lines("- 'test'", "...", FooTag, ExTag, ExExTag, "--- test"));
}

Expand All @@ -193,7 +182,6 @@ public void FoldedStyleDoesNotLooseCharacters(string text)

var yaml = EmittedTextFrom(StreamedDocumentWith(events));

Dump.WriteLine(yaml);
yaml.Should().Contain("world");
}

Expand All @@ -204,7 +192,6 @@ public void FoldedStyleIsSelectedWhenNewLinesAreFoundInLiteral()

var yaml = EmittedTextFrom(StreamedDocumentWith(events));

Dump.WriteLine(yaml);
yaml.Should().Contain(">");
}

Expand All @@ -221,7 +208,6 @@ public void FoldedStyleDoesNotGenerateExtraLineBreaks()
var sequence = (YamlSequenceNode)stream.Documents[0].RootNode;
var scalar = (YamlScalarNode)sequence.Children[0];

Dump.WriteLine(yaml);
scalar.Value.Should().Be("hello\nworld");
}

Expand All @@ -237,7 +223,6 @@ public void FoldedStyleDoesNotCollapseLineBreaks()
var sequence = (YamlSequenceNode)stream.Documents[0].RootNode;
var scalar = (YamlScalarNode)sequence.Children[0];

Dump.WriteLine("${0}$", yaml);
scalar.Value.Should().Be(">+\n");
}

Expand All @@ -251,15 +236,13 @@ public void FoldedStylePreservesNewLines()
FoldedScalar(input));

var yaml = EmittedTextFrom(StreamedDocumentWith(events));
Dump.WriteLine(yaml);

var stream = new YamlStream();
stream.Load(new StringReader(yaml));

var mapping = (YamlMappingNode)stream.Documents[0].RootNode;
var value = (YamlScalarNode)mapping.Children.First().Value;

Dump.WriteLine(value.Value);
value.Value.Should().Be(input);
}

Expand All @@ -278,7 +261,6 @@ public void CommentsAreEmittedCorrectly()

var yaml = EmittedTextFrom(StreamedDocumentWith(events));

Dump.WriteLine("${0}$", yaml);
yaml.Should()
.Contain("# Top comment")
.And.Contain("# Second line")
Expand Down Expand Up @@ -362,8 +344,8 @@ public void SingleQuotesAreDoubleQuoted(string input)
{
var events = StreamOf(DocumentWith(new Scalar(input)));
var yaml = EmittedTextFrom(events);
string expected = string.Format("\"{0}\"", input);

var expected = string.Format("\"{0}\"", input);

yaml.Should().Contain(expected);
}
Expand Down
17 changes: 8 additions & 9 deletions YamlDotNet.Test/Core/EventsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class EventsHelper
protected const bool Implicit = true;
protected const string TagYaml = "tag:yaml.org,2002:";

protected static readonly TagDirective[] DefaultTags = new[] {
protected static readonly TagDirective[] DefaultTags =
{
new TagDirective("!", "!"),
new TagDirective("!!", TagYaml)
};
Expand Down Expand Up @@ -182,15 +183,17 @@ public ScalarBuilder T(string tag)

public ScalarBuilder ImplicitPlain
{
get {
get
{
plainImplicit = true;
return this;
}
}

public ScalarBuilder ImplicitQuoted
{
get {
get
{
quotedImplicit = true;
return this;
}
Expand Down Expand Up @@ -264,7 +267,8 @@ public MappingStartBuilder T(string tag)

public MappingStartBuilder Explicit
{
get {
get
{
@implicit = false;
return this;
}
Expand Down Expand Up @@ -303,10 +307,6 @@ protected void AssertEvent(ParsingEvent expected, ParsingEvent actual, int event
var expectedValue = property.GetValue(expected, null);
if (expectedValue is IEnumerable && !(expectedValue is string))
{
Dump.Write("\t{0} = {{", property.Name);
Dump.Write(string.Join(", ", (IEnumerable)value));
Dump.WriteLine("}");

if (expectedValue is ICollection && value is ICollection)
{
var expectedCount = ((ICollection)expectedValue).Count;
Expand All @@ -327,7 +327,6 @@ protected void AssertEvent(ParsingEvent expected, ParsingEvent actual, int event
}
else
{
Dump.WriteLine("\t{0} = {1}", property.Name, value);
value.Should().Be(expectedValue, "Compared property {0} in parse event {1}", property.Name, eventNumber);
}
}
Expand Down
8 changes: 4 additions & 4 deletions YamlDotNet.Test/Core/InsertionQueueTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -66,7 +66,7 @@ public void ShouldCorrectlyDequeueElementsAfterEnqueuing()
public void ShouldCorrectlyDequeueElementsWhenIntermixingEnqueuing()
{
var queue = CreateQueue();

WithTheRange(0, 10).Run(queue.Enqueue);
PerformTimes(5, queue.Dequeue);
WithTheRange(10, 15).Run(queue.Enqueue);
Expand Down
27 changes: 17 additions & 10 deletions YamlDotNet.Test/Core/LookAheadBufferTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -112,7 +112,8 @@ public void ShouldHaveReadTwiceAfterSkippingOneCharacter()

buffer.Peek(2);

using (OnlyTheseCalls) {
using (OnlyTheseCalls)
{
buffer.Skip(1);

buffer.Peek(3).Should().Be('e');
Expand All @@ -130,7 +131,8 @@ public void ShouldHaveReadOnceAfterSkippingFiveCharacters()
buffer.Skip(1);
buffer.Peek(3);

using (OnlyTheseCalls) {
using (OnlyTheseCalls)
{
buffer.Skip(4);

buffer.Peek(0).Should().Be('f');
Expand All @@ -150,7 +152,8 @@ public void ShouldHaveReadOnceAfterSkippingSixCharacters()
buffer.Skip(4);
buffer.Peek(0);

using (OnlyTheseCalls) {
using (OnlyTheseCalls)
{
buffer.Skip(1);

buffer.Peek(0).Should().Be('g');
Expand All @@ -159,7 +162,8 @@ public void ShouldHaveReadOnceAfterSkippingSixCharacters()
}

[Fact]
public void ShouldHaveReadOnceAfterSkippingSevenCharacters() {
public void ShouldHaveReadOnceAfterSkippingSevenCharacters()
{
var reader = CreateFakeReader(TestString);
var buffer = CreateBuffer(reader, Capacity);

Expand All @@ -169,7 +173,8 @@ public void ShouldHaveReadOnceAfterSkippingSevenCharacters() {
buffer.Skip(4);
buffer.Peek(1);

using (OnlyTheseCalls) {
using (OnlyTheseCalls)
{
buffer.Skip(2);

buffer.Peek(0).Should().Be('h');
Expand All @@ -189,7 +194,8 @@ public void ShouldHaveReadOnceAfterSkippingEightCharacters()
buffer.Skip(4);
buffer.Peek(2);

using (OnlyTheseCalls) {
using (OnlyTheseCalls)
{
buffer.Skip(3);

buffer.Peek(0).Should().Be('i');
Expand All @@ -209,7 +215,8 @@ public void ShouldHaveReadOnceAfterSkippingNineCharacters()
buffer.Skip(4);
buffer.Peek(3);

using (OnlyTheseCalls) {
using (OnlyTheseCalls)
{
buffer.Skip(4);

buffer.Peek(0).Should().Be('\0');
Expand Down
Loading