Skip to content

Commit

Permalink
Merge branch 'nullable-references'
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Aubry committed Sep 27, 2019
2 parents 6e9311a + ce13a34 commit b3cf637
Show file tree
Hide file tree
Showing 174 changed files with 1,580 additions and 2,099 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ReceiptTest
private readonly StringWriter _buffer = new StringWriter();

private readonly ISerializer _serializer = new SerializerBuilder()
.WithNamingConvention(new CamelCaseNamingConvention())
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();

[Benchmark(Description = "Serialize vlatest")]
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet.AotTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static void TrySerialize<T>(string testName, T graph)
{
var output = new StringWriter();
var serializer = new SerializerBuilder()
.WithNamingConvention(new CamelCaseNamingConvention())
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
PerformTest(testName, () => serializer.Serialize(output, graph));
}
Expand All @@ -52,7 +52,7 @@ private static void TryDeserialize<T>(string testName, string yaml)
{
var input = new StringReader(yaml);
var deserializer = new DeserializerBuilder()
.WithNamingConvention(new CamelCaseNamingConvention())
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
PerformTest(testName, () => deserializer.Deserialize<T>(input));
}
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet.Samples/DeserializeObjectGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Main()
var input = new StringReader(Document);

var deserializer = new DeserializerBuilder()
.WithNamingConvention(new CamelCaseNamingConvention())
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();

var order = deserializer.Deserialize<Order>(input);
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet.Samples/DeserializingMultipleDocuments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public void Main()
var parser = new Parser(input);

// Consume the stream start event "manually"
parser.Expect<StreamStart>();
parser.Consume<StreamStart>();

while (parser.Accept<DocumentStart>())
while (parser.Accept<DocumentStart>(out var _))
{
// Deserialize the document
var doc = deserializer.Deserialize<List<string>>(parser);
Expand Down
4 changes: 2 additions & 2 deletions YamlDotNet.Samples/YamlDotNet.Samples.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet.Test/Core/EmitterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void UnicodeInScalarsCanBeSingleQuotedWhenOutputEncodingSupportsIt(string
)
);
var buffer = new MemoryStream();
#if NETCOREAPP2_1
#if (NETCOREAPP2_1 || NETCOREAPP3_0)
// Code pages such as Cyrillic are not recognized by default in
// .NET Core. We need to register this provider.
// https://msdn.microsoft.com/en-us/library/mt643899(v=vs.110).aspx#Remarks
Expand Down
6 changes: 3 additions & 3 deletions YamlDotNet.Test/Serialization/DateTimeConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public void Given_Values_WriteYaml_ShouldReturn_Result(int year, int month, int
var obj = new TestObject() { DateTime = dt };

var builder = new SerializerBuilder();
builder.WithNamingConvention(new CamelCaseNamingConvention());
builder.WithNamingConvention(CamelCaseNamingConvention.Instance);
builder.WithTypeConverter(new DateTimeConverter());

var serialiser = builder.Build();
Expand Down Expand Up @@ -507,7 +507,7 @@ public void Given_Values_WithLocale_WriteYaml_ShouldReturn_Result(int year, int
var obj = new TestObject() { DateTime = dt };

var builder = new SerializerBuilder();
builder.WithNamingConvention(new CamelCaseNamingConvention());
builder.WithNamingConvention(CamelCaseNamingConvention.Instance);
builder.WithTypeConverter(new DateTimeConverter(provider: culture));

var serialiser = builder.Build();
Expand Down Expand Up @@ -538,7 +538,7 @@ public void Given_Values_WithFormats_WriteYaml_ShouldReturn_Result_WithFirstForm
var obj = new TestObject() { DateTime = dt };

var builder = new SerializerBuilder();
builder.WithNamingConvention(new CamelCaseNamingConvention());
builder.WithNamingConvention(CamelCaseNamingConvention.Instance);
builder.WithTypeConverter(new DateTimeConverter(kind, formats: new [] {format, "G"}));

var serialiser = builder.Build();
Expand Down
8 changes: 4 additions & 4 deletions YamlDotNet.Test/Serialization/NamingConventionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class NamingConventionTests
[InlineData("thisIsATest", "ThisIsATest")]
public void AppliesCamelCaseConvention(string expectedName, string input)
{
ShouldApplyConventionGiven(input, expectedName, new CamelCaseNamingConvention());
ShouldApplyConventionGiven(input, expectedName, CamelCaseNamingConvention.Instance);
}

[Theory]
Expand All @@ -45,7 +45,7 @@ public void AppliesCamelCaseConvention(string expectedName, string input)
[InlineData("ThisIsATest", "thisIsATest")]
public void AppliesPascalCaseConvention(string expectedName, string input)
{
ShouldApplyConventionGiven(input, expectedName, new PascalCaseNamingConvention());
ShouldApplyConventionGiven(input, expectedName, PascalCaseNamingConvention.Instance);
}

[Theory]
Expand All @@ -54,7 +54,7 @@ public void AppliesPascalCaseConvention(string expectedName, string input)
[InlineData("this-is-a-test", "this-is-a-test")]
public void AppliesHyphenatedConvention(string expectedName, string input)
{
ShouldApplyConventionGiven(input, expectedName, new HyphenatedNamingConvention());
ShouldApplyConventionGiven(input, expectedName, HyphenatedNamingConvention.Instance);
}

[Theory]
Expand All @@ -63,7 +63,7 @@ public void AppliesHyphenatedConvention(string expectedName, string input)
[InlineData("this_is_a_test", "this-is-a-test")]
public void AppliesUnderscoredConvention(string expectedName, string input)
{
ShouldApplyConventionGiven(input, expectedName, new UnderscoredNamingConvention());
ShouldApplyConventionGiven(input, expectedName, UnderscoredNamingConvention.Instance);
}

private void ShouldApplyConventionGiven(string input, string expectedName, INamingConvention convention)
Expand Down
37 changes: 19 additions & 18 deletions YamlDotNet.Test/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,10 @@ public void RoundtripAliasOverride()
var writer = new StringWriter();
var input = new NameConvention { AliasTest = "Fourth" };

var attribute = new YamlMemberAttribute();
attribute.Alias = "fourthOverride";
var attribute = new YamlMemberAttribute
{
Alias = "fourthOverride"
};

var serializer = new SerializerBuilder()
.WithAttributeOverride<NameConvention>(nc => nc.AliasTest, attribute)
Expand Down Expand Up @@ -675,7 +677,7 @@ public void DeserializeTwoDocuments()
"aaa: 222",
"..."));

reader.Expect<StreamStart>();
reader.Consume<StreamStart>();
var one = Deserializer.Deserialize<Simple>(reader);
var two = Deserializer.Deserialize<Simple>(reader);

Expand All @@ -695,12 +697,12 @@ public void DeserializeThreeDocuments()
"aaa: 333",
"..."));

reader.Expect<StreamStart>();
reader.Consume<StreamStart>();
var one = Deserializer.Deserialize<Simple>(reader);
var two = Deserializer.Deserialize<Simple>(reader);
var three = Deserializer.Deserialize<Simple>(reader);

reader.Accept<StreamEnd>().Should().BeTrue("reader should have reached StreamEnd");
reader.Accept<StreamEnd>(out var _).Should().BeTrue("reader should have reached StreamEnd");
one.ShouldBeEquivalentTo(new { aaa = "111" });
two.ShouldBeEquivalentTo(new { aaa = "222" });
three.ShouldBeEquivalentTo(new { aaa = "333" });
Expand Down Expand Up @@ -1220,7 +1222,7 @@ public void IgnoreExtraPropertiesIfWantedNamingScheme()
);

DeserializerBuilder
.WithNamingConvention(new CamelCaseNamingConvention())
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.IgnoreUnmatchedProperties();

var actual = Deserializer.Deserialize<SimpleScratch>(UsingReaderFor(text));
Expand Down Expand Up @@ -1325,16 +1327,16 @@ public static IEnumerable<object[]> SpecialFloats
new FloatTestCase("double.NaN", double.NaN, ".nan"),
new FloatTestCase("double.PositiveInfinity", double.PositiveInfinity, ".inf"),
new FloatTestCase("double.NegativeInfinity", double.NegativeInfinity, "-.inf"),
new FloatTestCase("double.Epsilon", double.Epsilon, "4.9406564584124654E-324"),
new FloatTestCase("double.MinValue", double.MinValue, "-1.7976931348623157E+308"),
new FloatTestCase("double.MaxValue", double.MaxValue, "1.7976931348623157E+308"),
new FloatTestCase("double.Epsilon", double.Epsilon, double.Epsilon.ToString("G17", CultureInfo.InvariantCulture)),
new FloatTestCase("double.MinValue", double.MinValue, double.MinValue.ToString("G17", CultureInfo.InvariantCulture)),
new FloatTestCase("double.MaxValue", double.MaxValue, double.MaxValue.ToString("G17", CultureInfo.InvariantCulture)),

new FloatTestCase("float.NaN", float.NaN, ".nan"),
new FloatTestCase("float.PositiveInfinity", float.PositiveInfinity, ".inf"),
new FloatTestCase("float.NegativeInfinity", float.NegativeInfinity, "-.inf"),
new FloatTestCase("float.Epsilon", float.Epsilon, "1.40129846E-45"),
new FloatTestCase("float.MinValue", float.MinValue, "-3.40282347E+38"),
new FloatTestCase("float.MaxValue", float.MaxValue, "3.40282347E+38")
new FloatTestCase("float.Epsilon", float.Epsilon, float.Epsilon.ToString("G17", CultureInfo.InvariantCulture)),
new FloatTestCase("float.MinValue", float.MinValue, float.MinValue.ToString("G17", CultureInfo.InvariantCulture)),
new FloatTestCase("float.MaxValue", float.MaxValue, float.MaxValue.ToString("G17", CultureInfo.InvariantCulture))
}
.Select(tc => new object[] { tc });
}
Expand Down Expand Up @@ -1402,7 +1404,7 @@ public class Foo
[Fact]
public void AttributeOverridesAndNamingConventionDoNotConflict()
{
var namingConvention = new CamelCaseNamingConvention();
var namingConvention = CamelCaseNamingConvention.Instance;

var yamlMember = new YamlMemberAttribute
{
Expand Down Expand Up @@ -1447,8 +1449,7 @@ public class CommentWrapper<T> : IYamlConvertible

public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
{
var comment = parser.Allow<Comment>();
if (comment != null)
if (parser.TryConsume<Comment>(out var comment))
{
Comment = comment.Value;
}
Expand Down Expand Up @@ -1579,7 +1580,7 @@ public void RegisteringATypeConverterPreventsTheTypeFromBeingVisited()
public void NamingConventionIsNotAppliedBySerializerWhenApplyNamingConventionsIsFalse()
{
var sut = new SerializerBuilder()
.WithNamingConvention(new CamelCaseNamingConvention())
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();

var yaml = sut.Serialize(new NamingConventionDisabled { NoConvention = "value" });
Expand All @@ -1591,7 +1592,7 @@ public void NamingConventionIsNotAppliedBySerializerWhenApplyNamingConventionsIs
public void NamingConventionIsNotAppliedByDeserializerWhenApplyNamingConventionsIsFalse()
{
var sut = new DeserializerBuilder()
.WithNamingConvention(new CamelCaseNamingConvention())
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();

var yaml = "NoConvention: value";
Expand Down Expand Up @@ -1810,7 +1811,7 @@ public bool Accepts(Type type)

public object ReadYaml(IParser parser, Type type)
{
var scalar = parser.Expect<Scalar>();
var scalar = parser.Consume<Scalar>();
return new NonSerializable { Text = scalar.Value };
}

Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet.Test/YamlDotNet.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net46;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net46;netcoreapp3.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<AssemblyOriginatorKeyFile>..\YamlDotNet.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down

0 comments on commit b3cf637

Please sign in to comment.