diff --git a/VYaml.SourceGenerator/VYamlIncrementalSourceGenerator.cs b/VYaml.SourceGenerator/VYamlIncrementalSourceGenerator.cs index de9ddc2..609c786 100644 --- a/VYaml.SourceGenerator/VYamlIncrementalSourceGenerator.cs +++ b/VYaml.SourceGenerator/VYamlIncrementalSourceGenerator.cs @@ -69,7 +69,7 @@ class Comparer : IEqualityComparer<(GeneratorAttributeSyntaxContext, Compilation public bool Equals((GeneratorAttributeSyntaxContext, Compilation) x, (GeneratorAttributeSyntaxContext, Compilation) y) { - return x.Item1.TargetNode.Equals(y.Item1.TargetNode); + return x.Item1.TargetNode.IsEquivalentTo(y.Item1.TargetNode); } public int GetHashCode((GeneratorAttributeSyntaxContext, Compilation) obj) diff --git a/VYaml.Tests/Parser/YamlParserTest.cs b/VYaml.Tests/Parser/YamlParserTest.cs index 3fed6a6..9e624c9 100644 --- a/VYaml.Tests/Parser/YamlParserTest.cs +++ b/VYaml.Tests/Parser/YamlParserTest.cs @@ -1,3 +1,4 @@ +using System; using System.Buffers; using System.Collections.Generic; using System.Text; diff --git a/VYaml.Tests/Serialization/SerializerTest.cs b/VYaml.Tests/Serialization/SerializerTest.cs index 7d9f269..8468dfd 100644 --- a/VYaml.Tests/Serialization/SerializerTest.cs +++ b/VYaml.Tests/Serialization/SerializerTest.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using NUnit.Framework; using VYaml.Internal; @@ -150,5 +151,13 @@ public void DeserializeHighDigitNumber() Assert.That(documents["id2"], Is.InstanceOf()); Assert.That(documents["id3"], Is.InstanceOf()); } + + [Test] + public void Deserialize_Empty() + { + var empty = new ReadOnlyMemory(Array.Empty()); + var result1 = YamlSerializer.Deserialize(empty); + Assert.That(result1, Is.Null); + } } } diff --git a/VYaml.Unity/Assets/Tests/Parser/YamlParserTest.cs b/VYaml.Unity/Assets/Tests/Parser/YamlParserTest.cs index 3fed6a6..9e624c9 100644 --- a/VYaml.Unity/Assets/Tests/Parser/YamlParserTest.cs +++ b/VYaml.Unity/Assets/Tests/Parser/YamlParserTest.cs @@ -1,3 +1,4 @@ +using System; using System.Buffers; using System.Collections.Generic; using System.Text; diff --git a/VYaml.Unity/Assets/Tests/Serialization/SerializerTest.cs b/VYaml.Unity/Assets/Tests/Serialization/SerializerTest.cs index 7d9f269..8468dfd 100644 --- a/VYaml.Unity/Assets/Tests/Serialization/SerializerTest.cs +++ b/VYaml.Unity/Assets/Tests/Serialization/SerializerTest.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using NUnit.Framework; using VYaml.Internal; @@ -150,5 +151,13 @@ public void DeserializeHighDigitNumber() Assert.That(documents["id2"], Is.InstanceOf()); Assert.That(documents["id3"], Is.InstanceOf()); } + + [Test] + public void Deserialize_Empty() + { + var empty = new ReadOnlyMemory(Array.Empty()); + var result1 = YamlSerializer.Deserialize(empty); + Assert.That(result1, Is.Null); + } } } diff --git a/VYaml.Unity/Assets/VYaml/Runtime/Serialization/YamlSerializer.cs b/VYaml.Unity/Assets/VYaml/Runtime/Serialization/YamlSerializer.cs index d4437af..c0aed71 100644 --- a/VYaml.Unity/Assets/VYaml/Runtime/Serialization/YamlSerializer.cs +++ b/VYaml.Unity/Assets/VYaml/Runtime/Serialization/YamlSerializer.cs @@ -132,6 +132,7 @@ public static T Deserialize(ref YamlParser parser, YamlSerializerOptions? opt contextLocal.Reset(); parser.SkipHeader(); + if (parser.End) return default!; var formatter = options.Resolver.GetFormatterWithVerify(); return contextLocal.DeserializeWithAlias(formatter, ref parser); diff --git a/VYaml/Serialization/YamlSerializer.cs b/VYaml/Serialization/YamlSerializer.cs index d4437af..c0aed71 100644 --- a/VYaml/Serialization/YamlSerializer.cs +++ b/VYaml/Serialization/YamlSerializer.cs @@ -132,6 +132,7 @@ public static T Deserialize(ref YamlParser parser, YamlSerializerOptions? opt contextLocal.Reset(); parser.SkipHeader(); + if (parser.End) return default!; var formatter = options.Resolver.GetFormatterWithVerify(); return contextLocal.DeserializeWithAlias(formatter, ref parser);