Skip to content

Commit

Permalink
test: fix serialization tests on Windows
Browse files Browse the repository at this point in the history
Serialization tests were relying on string comparison, which fails
because of line endings on Windows (string literals in source have LF
newlines). Fixed by using JsonNode to parse and compare the
serialization output with the expected text.
  • Loading branch information
wlsnmrk committed Jun 20, 2024
1 parent 9b195d6 commit cff68ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Chickensoft.LogicBlocks.Tests.Serialization;

using System.Text.Json;
using System.Text.Json.Nodes;
using Chickensoft.Collections;
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks.Tests.Fixtures;
Expand Down Expand Up @@ -31,10 +32,10 @@ public partial record B {

var options = CreateOptions();

var json = JsonSerializer.Serialize(logic, options);
var jsonText = JsonSerializer.Serialize(logic, options);
var jsonNode = JsonNode.Parse(jsonText);

json.ShouldBe(
/*lang=json,strict*/
var jsonExpectedText = /*lang=json,strict*/
"""
{
"$type": "serializable_logic_block",
Expand All @@ -60,8 +61,9 @@ public partial record B {
}
}
}
"""
);
""";
var jsonExpectedNode = JsonNode.Parse(jsonExpectedText);
JsonNode.DeepEquals(jsonNode, jsonExpectedNode).ShouldBeTrue();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Chickensoft.LogicBlocks.Tutorial.Tests;

using System.Text.Json;
using System.Text.Json.Nodes;
using Chickensoft.Serialization;
using Shouldly;
using Xunit;
Expand All @@ -19,10 +20,10 @@ public class SerializableLogicBlockTest {

var logic = new SerializableLogicBlock();

var json = JsonSerializer.Serialize(logic, options);
var jsonText = JsonSerializer.Serialize(logic, options);
var jsonNode = JsonNode.Parse(jsonText);

json.ShouldBe(
/*language=json*/
var jsonExpectedText = /*language=json*/
"""
{
"$type": "serializable_logic",
Expand All @@ -37,8 +38,10 @@ public class SerializableLogicBlockTest {
"values": {}
}
}
"""
);
""";
var jsonExpectedNode = JsonNode.Parse(jsonExpectedText);

JsonNode.DeepEquals(jsonNode, jsonExpectedNode).ShouldBeTrue();
}

[Fact]
Expand Down

0 comments on commit cff68ff

Please sign in to comment.