Skip to content

Commit

Permalink
Remove net70, fixed up the fsharp unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardCooke committed Jul 14, 2024
1 parent b176139 commit e0abc6a
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PublishAot>true</PublishAot>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<Nullable>enable</Nullable>
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug-AOT|AnyCPU' ">
Expand Down
36 changes: 17 additions & 19 deletions YamlDotNet.Fsharp.Test/DeserializerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open System
open Xunit
open YamlDotNet.Serialization
open YamlDotNet.Serialization.NamingConventions
open FsUnit.Xunit
open System.ComponentModel

[<CLIMutable>]
Expand Down Expand Up @@ -45,13 +44,12 @@ cars:
.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

Assert.Equal("Jack", person.Name)
Assert.Equal(2, person.Cars.Length)
Assert.Equal("Mercedes", person.Cars[0].Name)
Assert.Equal(Some "Jessy", person.Cars[0].Nickname)// |> should equal (Some "Jessy")
Assert.Equal("Honda", person.Cars[1].Name)
Assert.Equal(None, person.Cars[1].Nickname)

[<Fact>]
let Deserialize_YamlWithObjectOptions() =
Expand All @@ -72,16 +70,16 @@ cars:
.Build()

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

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"
Assert.Equal("Mercedes", person.Cars[0].Name)
Assert.NotNull(person.Cars[0].Spec)
Assert.True(person.Cars[0].Spec |> Option.isSome)
Assert.Equal("V6", person.Cars[0].Spec.Value.EngineType)
Assert.Equal("AWD", person.Cars[0].Spec.Value.DriveType)

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
Assert.Equal("Honda", person.Cars[1].Name)
Assert.Null(person.Cars[1].Spec)
Assert.Equal(None, person.Cars[1].Spec)
Assert.Equal(None, person.Cars[1].Nickname)
10 changes: 4 additions & 6 deletions YamlDotNet.Fsharp.Test/SerializerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ open System
open Xunit
open YamlDotNet.Serialization
open YamlDotNet.Serialization.NamingConventions
open FsUnit.Xunit
open YamlDotNet.Core
open YamlDotNet.Fsharp.Test

[<CLIMutable>]
type Spec = {
Expand Down Expand Up @@ -65,8 +65,7 @@ cars:
.Build()

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

Assert.Equal(yaml.Clean(), person.Clean())

[<Fact>]
let Serialize_YamlWithScalarOptions_OmitNull() =
Expand Down Expand Up @@ -102,8 +101,7 @@ cars:
.Build()

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

Assert.Equal(yaml.Clean(), person.Clean())

[<Fact>]
let Serialize_YamlWithObjectOptions_OmitNull() =
Expand Down Expand Up @@ -144,7 +142,7 @@ cars:
.Build()

let person = sut.Serialize(jackTheDriver)
person |> should equal yaml
Assert.Equal(yaml.Clean(), person.Clean())

type TestOmit = {
name: string
Expand Down
15 changes: 15 additions & 0 deletions YamlDotNet.Fsharp.Test/StringExtensions.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace YamlDotNet.Fsharp.Test

open System.Runtime.CompilerServices

[<Extension>]
type StringExtensions() =
[<Extension>]
static member NormalizeNewLines(x: string) =
x.Replace("\r\n", "\n").Replace("\n", System.Environment.NewLine)
[<Extension>]
static member TrimNewLines(x: string) =
x.TrimEnd('\r').TrimEnd('\n')
[<Extension>]
static member Clean(x: string) =
x.NormalizeNewLines().TrimNewLines()
22 changes: 16 additions & 6 deletions YamlDotNet.Fsharp.Test/YamlDotNet.Fsharp.Test.fsproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net47</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;net47</TargetFrameworks>
<IsPackable>false</IsPackable>
<AssemblyOriginatorKeyFile>..\YamlDotNet.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<LangVersion>8.0</LangVersion>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Compile Include="StringExtensions.fs" />
<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" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\YamlDotNet\YamlDotNet.csproj" />
<ProjectReference Include="..\YamlDotNet.Analyzers.StaticGenerator\YamlDotNet.Analyzers.StaticGenerator.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion YamlDotNet.Samples.Fsharp/YamlDotNet.Samples.Fsharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

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>net8.0;net7.0;net6.0;net47</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;net47</TargetFrameworks>
<IsPackable>false</IsPackable>
<AssemblyOriginatorKeyFile>..\YamlDotNet.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ protected virtual void Traverse<TContext>(IPropertyDescriptor? propertyDescripto
// This is a nullable type, recursively handle it with its underlying type.
// Note that if it contains null, the condition above already took care of it
Traverse(
propertyDescriptor,
"Value",
new ObjectDescriptor(value.Value, nullableUnderlyingType, value.Type, value.ScalarStyle),
new ObjectDescriptor(value.Value, nullableUnderlyingType, value.Type, value.ScalarStyle),
visitor,
context,
path,
Expand All @@ -169,6 +170,7 @@ protected virtual void Traverse<TContext>(IPropertyDescriptor? propertyDescripto
else if (optionUnderlyingType != null && optionValue != null)
{
Traverse(
propertyDescriptor,
"Value",
new ObjectDescriptor(FsharpHelper.GetValue(value), optionUnderlyingType, value.Type, value.ScalarStyle),
visitor,
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Serialization/Utilities/TypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static T ChangeType<T>(object? value, INamingConvention enumNamingConvent
if (destinationType.IsGenericType())
{
var genericTypeDefinition = destinationType.GetGenericTypeDefinition();
if (genericTypeDefinition == typeof(Nullable<>) || FsharpHelper.IsOptionType(genericTypeDefinition))
if (genericTypeDefinition == typeof(Nullable<>) || FsharpHelper.IsOptionType(genericTypeDefinition))
{
var innerType = destinationType.GetGenericArguments()[0];
var convertedValue = ChangeType(value, innerType, culture, enumNamingConvention, typeInspector);
Expand Down
3 changes: 2 additions & 1 deletion YamlDotNet/YamlDotNet.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0;netstandard2.1;net47</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.0;netstandard2.1;net47</TargetFrameworks>

<PackageProjectUrl>https://github.com/aaubry/YamlDotNet</PackageProjectUrl>
<RepositoryUrl>https://github.com/aaubry/YamlDotNet</RepositoryUrl>
Expand All @@ -15,6 +15,7 @@
<NoWarn>1591;1574</NoWarn>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<WarningsAsErrors>true</WarningsAsErrors>

<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
Expand Down

0 comments on commit e0abc6a

Please sign in to comment.