-
-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72641d1
commit 6a98f68
Showing
6 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
YamlDotNet.Test/Analyzers/StaticGenerator/ObjectTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// 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 | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
using Xunit; | ||
using YamlDotNet.Serialization; | ||
|
||
namespace YamlDotNet.Test.Analyzers.StaticGenerator | ||
{ | ||
public class ObjectTests | ||
{ | ||
[Fact] | ||
public void InheritedMembersWorks() | ||
{ | ||
var deserializer = new StaticDeserializerBuilder(new StaticContext()).Build(); | ||
var yaml = @"NotInherited: hello | ||
Inherited: world | ||
"; | ||
var actual = deserializer.Deserialize<SerializedInheritedClass>(yaml); | ||
Assert.Equal("hello", actual.NotInherited); | ||
Assert.Equal("world", actual.Inherited); | ||
var serializer = new StaticSerializerBuilder(new StaticContext()).Build(); | ||
var actualYaml = serializer.Serialize(actual); | ||
Assert.Equal(yaml, actualYaml); | ||
} | ||
|
||
[Fact] | ||
public void RegularObjectWorks() | ||
{ | ||
var deserializer = new StaticDeserializerBuilder(new StaticContext()).Build(); | ||
var yaml = @"Prop1: hello | ||
Prop2: 1 | ||
Hello: world | ||
Inner: | ||
Prop1: a | ||
Prop2: 2 | ||
"; | ||
var actual = deserializer.Deserialize<RegularObjectOuter>(yaml); | ||
Assert.Equal("hello", actual.Prop1); | ||
Assert.Equal(1, actual.Prop2); | ||
Assert.Equal("world", actual.Member); | ||
Assert.Equal("I am ignored", actual.Ignored); | ||
Assert.NotNull(actual.Inner); | ||
Assert.Equal("a", actual.Inner.Prop1); | ||
Assert.Equal(2, actual.Inner.Prop2); | ||
|
||
var serializer = new StaticSerializerBuilder(new StaticContext()).Build(); | ||
var actualYaml = serializer.Serialize(actual); | ||
yaml = @"Prop1: hello | ||
Prop2: 1 | ||
# A Description | ||
Hello: ""world"" | ||
Inner: | ||
Prop1: a | ||
Prop2: 2 | ||
"; | ||
Assert.Equal(yaml, actualYaml); | ||
} | ||
} | ||
public class InheritedClass | ||
{ | ||
public string Inherited { get; set; } | ||
} | ||
|
||
[YamlSerializable] | ||
public class SerializedInheritedClass : InheritedClass | ||
{ | ||
public string NotInherited { get; set; } | ||
} | ||
|
||
[YamlSerializable] | ||
public class RegularObjectOuter | ||
{ | ||
public string Prop1 { get; set; } | ||
public int Prop2 { get; set; } | ||
[YamlMember(Alias = "Hello", Description = "A Description", ScalarStyle = YamlDotNet.Core.ScalarStyle.DoubleQuoted)] | ||
public string Member { get; set; } | ||
[YamlIgnore] | ||
public string Ignored { get; set; } = "I am ignored"; | ||
public RegularObjectInner Inner { get; set; } | ||
} | ||
|
||
[YamlSerializable] | ||
public class RegularObjectInner | ||
{ | ||
public string Prop1 { get; set; } | ||
public int Prop2 { get; set; } | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
YamlDotNet.Test/Analyzers/StaticGenerator/RootCollectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using System.Collections.Generic; | ||
using Xunit; | ||
using YamlDotNet.Serialization; | ||
|
||
namespace YamlDotNet.Test.Analyzers.StaticGenerator | ||
{ | ||
public class RootCollectionTests | ||
{ | ||
[Fact] | ||
public void RootArrayWorks() | ||
{ | ||
var deserializer = new StaticDeserializerBuilder(new StaticContext()).Build(); | ||
var yaml = @" | ||
- Test: hello | ||
- Test: world | ||
"; | ||
|
||
var actual = deserializer.Deserialize<RootObject[]>(yaml); | ||
Assert.Equal("hello", actual[0].Test); | ||
Assert.Equal("world", actual[1].Test); | ||
} | ||
|
||
[Fact] | ||
public void RootListWorks() | ||
{ | ||
var deserializer = new StaticDeserializerBuilder(new StaticContext()).Build(); | ||
var yaml = @" | ||
- Test: hello | ||
- Test: world | ||
"; | ||
|
||
var actual = deserializer.Deserialize<List<RootObject>>(yaml); | ||
Assert.Equal("hello", actual[0].Test); | ||
Assert.Equal("world", actual[1].Test); | ||
} | ||
} | ||
[YamlSerializable] | ||
public class RootObject | ||
{ | ||
public string Test { get; set; } | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
YamlDotNet.Test/Analyzers/StaticGenerator/StaticAoTContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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 | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
using YamlDotNet.Serialization; | ||
|
||
namespace YamlDotNet.Test.Analyzers.StaticGenerator | ||
{ | ||
[YamlStaticContext] | ||
public partial class StaticContext : YamlDotNet.Serialization.StaticContext | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters