Skip to content

Commit

Permalink
Merge branch 'master' into ec-nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardCooke committed Jul 14, 2024
2 parents a59301b + 2d332ae commit b176139
Show file tree
Hide file tree
Showing 26 changed files with 441 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TestResults
*.orig
Help/*
release/*
/_ReSharper.*
_ReSharper.*
*.pidb
*.userprefs
packages
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ COPY . .
RUN dotnet build -c Release --framework net47 YamlDotNet/YamlDotNet.csproj -o /output/net47
RUN dotnet build -c Release --framework netstandard2.0 YamlDotNet/YamlDotNet.csproj -o /output/netstandard2.0
RUN dotnet build -c Release --framework netstandard2.1 YamlDotNet/YamlDotNet.csproj -o /output/netstandard2.1
RUN dotnet build -c Release --framework net60 YamlDotNet/YamlDotNet.csproj -o /output/net60
RUN dotnet build -c Release --framework net70 YamlDotNet/YamlDotNet.csproj -o /output/net70
RUN dotnet build -c Release --framework net80 YamlDotNet/YamlDotNet.csproj -o /output/net80
RUN dotnet build -c Release --framework net6.0 YamlDotNet/YamlDotNet.csproj -o /output/net6.0
RUN dotnet build -c Release --framework net7.0 YamlDotNet/YamlDotNet.csproj -o /output/net7.0
RUN dotnet build -c Release --framework net8.0 YamlDotNet/YamlDotNet.csproj -o /output/net8.0

RUN dotnet pack -c Release YamlDotNet/YamlDotNet.csproj -o /output/package /p:Version=$PACKAGE_VERSION

RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net80 --logger:"trx;LogFileName=/output/tests.net80.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net70 --logger:"trx;LogFileName=/output/tests.net70.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net60 --logger:"trx;LogFileName=/output/tests.net60.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net8.0 --logger:"trx;LogFileName=/output/tests-net8.0.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net7.0 --logger:"trx;LogFileName=/output/tests-net7.0.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net6.0 --logger:"trx;LogFileName=/output/tests-net6.0.trx" --logger:"console;Verbosity=detailed"

FROM alpine
VOLUME /output
Expand Down
14 changes: 7 additions & 7 deletions Dockerfile.NonEnglish
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ COPY . .
RUN dotnet build -c Release --framework net47 YamlDotNet/YamlDotNet.csproj -o /output/net47
RUN dotnet build -c Release --framework netstandard2.0 YamlDotNet/YamlDotNet.csproj -o /output/netstandard2.0
RUN dotnet build -c Release --framework netstandard2.1 YamlDotNet/YamlDotNet.csproj -o /output/netstandard2.1
RUN dotnet build -c Release --framework net60 YamlDotNet/YamlDotNet.csproj -o /output/net60
RUN dotnet build -c Release --framework net70 YamlDotNet/YamlDotNet.csproj -o /output/net70
RUN dotnet build -c Release --framework net80 YamlDotNet/YamlDotNet.csproj -o /output/net80
RUN dotnet build -c Release --framework net6.0 YamlDotNet/YamlDotNet.csproj -o /output/net6.0
RUN dotnet build -c Release --framework net7.0 YamlDotNet/YamlDotNet.csproj -o /output/net7.0
RUN dotnet build -c Release --framework net8.0 YamlDotNet/YamlDotNet.csproj -o /output/net8.0

RUN dotnet pack -c Release YamlDotNet/YamlDotNet.csproj -o /output/package /p:Version=$PACKAGE_VERSION

Expand All @@ -62,10 +62,10 @@ RUN echo -n "${LC_ALL}" > /etc/locale.gen && \
apt install -y locales && \
locale-gen

RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net80 --logger:"trx;LogFileName=/output/tests.net80.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net70 --logger:"trx;LogFileName=/output/tests.net70.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net60 --logger:"trx;LogFileName=/output/tests.net60.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework netcoreapp3.1 --logger:"trx;LogFileName=/output/tests.netcoreapp3.1.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net8.0 --logger:"trx;LogFileName=/output/tests-net8.0.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net7.0 --logger:"trx;LogFileName=/output/tests-net7.0.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework net6.0 --logger:"trx;LogFileName=/output/tests-net6.0.trx" --logger:"console;Verbosity=detailed"
RUN dotnet test -c Release YamlDotNet.Test/YamlDotNet.Test.csproj --framework netcoreapp3.1 --logger:"trx;LogFileName=/output/tests-netcoreapp3.1.trx" --logger:"console;Verbosity=detailed"

FROM alpine
VOLUME /output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<description>Roslyn Code Generator that will generate a static context for use with YamlDotNet to support ahead-of-time and library trimming.</description>
<summary>Static context generator for YamlDotNet.</summary>
<language>en-US</language>
<license type="file">LICENSE.txt</license>
<license type="expression">MIT</license>
<projectUrl>https://github.com/aaubry/YamlDotNet/wiki</projectUrl>
<iconUrl>http://aaubry.net/images/yamldotnet.png</iconUrl>
<icon>images/yamldotnet.png</icon>
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet.Benchmark/YamlDotNet.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net80</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
87 changes: 87 additions & 0 deletions YamlDotNet.Fsharp.Test/DeserializerTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
module DeserializerTests

open System
open Xunit
open YamlDotNet.Serialization
open YamlDotNet.Serialization.NamingConventions
open FsUnit.Xunit
open System.ComponentModel

[<CLIMutable>]
type Spec = {
EngineType: string
DriveType: string
}

[<CLIMutable>]
type Car = {
Name: string
Year: int
Spec: Spec option
Nickname: string option
}

[<CLIMutable>]
type Person = {
Name: string
MomentOfBirth: DateTime
Cars: Car array
}

[<Fact>]
let Deserialize_YamlWithScalarOptions() =
let yaml = """
name: Jack
momentOfBirth: 1983-04-21T20:21:03.0041599Z
cars:
- name: Mercedes
year: 2018
nickname: Jessy
- name: Honda
year: 2021
"""
let sut = DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let person = sut.Deserialize<Person>(yaml)
person.Name |> should equal "Jack"
person.Cars |> should haveLength 2
person.Cars[0].Name |> should equal "Mercedes"
person.Cars[0].Nickname |> should equal (Some "Jessy")
person.Cars[1].Name |> should equal "Honda"
person.Cars[1].Nickname |> should equal None


[<Fact>]
let Deserialize_YamlWithObjectOptions() =
let yaml = """
name: Jack
momentOfBirth: 1983-04-21T20:21:03.0041599Z
cars:
- name: Mercedes
year: 2018
spec:
engineType: V6
driveType: AWD
- name: Honda
year: 2021
"""
let sut = DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let person = sut.Deserialize<Person>(yaml)
person.Name |> should equal "Jack"
person.Cars |> should haveLength 2

person.Cars[0].Name |> should equal "Mercedes"
person.Cars[0].Spec |> should not' (be null)
person.Cars[0].Spec |> Option.isSome |> should equal true
person.Cars[0].Spec.Value.EngineType |> should equal "V6"
person.Cars[0].Spec.Value.DriveType |> should equal "AWD"

person.Cars[1].Name |> should equal "Honda"
person.Cars[1].Spec |> should be null
person.Cars[1].Spec |> should equal None
person.Cars[1].Nickname |> should equal None
152 changes: 152 additions & 0 deletions YamlDotNet.Fsharp.Test/SerializerTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
module SerializerTests

open System
open Xunit
open YamlDotNet.Serialization
open YamlDotNet.Serialization.NamingConventions
open FsUnit.Xunit
open YamlDotNet.Core

[<CLIMutable>]
type Spec = {
EngineType: string
DriveType: string
}

[<CLIMutable>]
type Car = {
Name: string
Year: int
Spec: Spec option
Nickname: string option
}

[<CLIMutable>]
type Person = {
Name: string
MomentOfBirth: DateTime
KidsSeat: int option
Cars: Car array
}

[<Fact>]
let Serialize_YamlWithScalarOptions() =
let jackTheDriver = {
Name = "Jack"
MomentOfBirth = DateTime(1983, 4, 21, 20, 21, 03, 4)
KidsSeat = Some 1
Cars = [|
{ Name = "Mercedes"
Year = 2018
Nickname = Some "Jessy"
Spec = None };
{ Name = "Honda"
Year = 2021
Nickname = None
Spec = None }
|]
}

let yaml = """name: Jack
momentOfBirth: 1983-04-21T20:21:03.0040000
kidsSeat: 1
cars:
- name: Mercedes
year: 2018
spec:
nickname: Jessy
- name: Honda
year: 2021
spec:
nickname:
"""
let sut = SerializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build()

let person = sut.Serialize(jackTheDriver)
person |> should equal yaml


[<Fact>]
let Serialize_YamlWithScalarOptions_OmitNull() =
let jackTheDriver = {
Name = "Jack"
MomentOfBirth = DateTime(1983, 4, 21, 20, 21, 03, 4)
KidsSeat = Some 1
Cars = [|
{ Name = "Mercedes"
Year = 2018
Nickname = Some "Jessy"
Spec = None };
{ Name = "Honda"
Year = 2021
Nickname = None
Spec = None }
|]
}

let yaml = """name: Jack
momentOfBirth: 1983-04-21T20:21:03.0040000
kidsSeat: 1
cars:
- name: Mercedes
year: 2018
nickname: Jessy
- name: Honda
year: 2021
"""
let sut = SerializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull)
.Build()

let person = sut.Serialize(jackTheDriver)
person |> should equal yaml


[<Fact>]
let Serialize_YamlWithObjectOptions_OmitNull() =
let jackTheDriver = {
Name = "Jack"
MomentOfBirth = DateTime(1983, 4, 21, 20, 21, 03, 4)
KidsSeat = Some 1
Cars = [|
{ Name = "Mercedes"
Year = 2018
Nickname = None
Spec = Some {
EngineType = "V6"
DriveType = "AWD"
} };
{ Name = "Honda"
Year = 2021
Nickname = None
Spec = None }
|]
}

let yaml = """name: Jack
momentOfBirth: 1983-04-21T20:21:03.0040000
kidsSeat: 1
cars:
- name: Mercedes
year: 2018
spec:
engineType: V6
driveType: AWD
- name: Honda
year: 2021
"""
let sut = SerializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull)
.Build()

let person = sut.Serialize(jackTheDriver)
person |> should equal yaml

type TestOmit = {
name: string
plop: int option
}
25 changes: 25 additions & 0 deletions YamlDotNet.Fsharp.Test/YamlDotNet.Fsharp.Test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net47</TargetFrameworks>
<IsPackable>false</IsPackable>
<AssemblyOriginatorKeyFile>..\YamlDotNet.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<LangVersion>8.0</LangVersion>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
<ItemGroup>
<Compile Include="DeserializerTests.fs" />
<Compile Include="SerializerTests.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="FsUnit.xUnit" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\YamlDotNet\YamlDotNet.csproj" />
<ProjectReference Include="..\YamlDotNet.Analyzers.StaticGenerator\YamlDotNet.Analyzers.StaticGenerator.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion YamlDotNet.Samples/YamlDotNet.Samples.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net80</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
16 changes: 10 additions & 6 deletions YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,26 @@ public void LoadSimpleDocument()
Assert.Equal(YamlNodeType.Scalar, stream.Documents[0].RootNode.NodeType);
}

[Fact]
public void AccessingAllNodesOnInfinitelyRecursiveDocumentThrows()
[Theory]
[InlineData("&a [*a]")]
[InlineData("?\n key: &id1\n recursion: *id1\n: foo")]
public void AccessingAllNodesOnInfinitelyRecursiveDocumentThrows(string yaml)
{
var stream = new YamlStream();
stream.Load(Yaml.ParserForText("&a [*a]"));
stream.Load(Yaml.ParserForText(yaml));

var accessAllNodes = new Action(() => stream.Documents.Single().AllNodes.ToList());

accessAllNodes.ShouldThrow<MaximumRecursionLevelReachedException>("because the document is infinitely recursive.");
}

[Fact]
public void InfinitelyRecursiveNodeToStringSucceeds()
[Theory]
[InlineData("&a [*a]")]
[InlineData("?\n key: &id1\n recursion: *id1\n: foo")]
public void InfinitelyRecursiveNodeToStringSucceeds(string yaml)
{
var stream = new YamlStream();
stream.Load(Yaml.ParserForText("&a [*a]"));
stream.Load(Yaml.ParserForText(yaml));

var toString = stream.Documents.Single().RootNode.ToString();

Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet.Test/Serialization/DeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public static IEnumerable<object[]> DeserializeScalarEdgeCases_TestCases
yield return new object[] { decimal.MaxValue, typeof(decimal) };
yield return new object[] { char.MaxValue, typeof(char) };

#if NETCOREAPP3_1_OR_GREATER
#if NET
yield return new object[] { float.MinValue, typeof(float) };
yield return new object[] { float.MaxValue, typeof(float) };
yield return new object[] { double.MinValue, typeof(double) };
Expand Down
Loading

0 comments on commit b176139

Please sign in to comment.