Skip to content

Commit

Permalink
Don't accidentally assert the the source code line endings in the uni…
Browse files Browse the repository at this point in the history
…t test
  • Loading branch information
lilith committed Jan 29, 2024
1 parent c32a3dd commit 431e672
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Tomlyn.Tests/SyntaxTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -110,19 +110,20 @@ class PropMetaTestTable : ITomlMetadataProvider{
[Test]
public void TestPropertySpan()
{
var input = @"[mytable]
key = 15
val = true
";
var input = """
[mytable]
key = 15
val = true
""";
var doc = Toml.Parse(input);

var instance = doc.ToModel<PropMetaTestDoc>();
Assert.True(instance.Mytable.PropertiesMetadata?.ContainsProperty("key"));
if (instance.Mytable.PropertiesMetadata?.TryGetProperty("key", out var keyMeta) == true){
Assert.That(keyMeta.Span.Start.Line, Is.EqualTo(1));
Assert.That(keyMeta.Span.Start.Column, Is.EqualTo(0));
// TextPosition adds 1 to line and column in ToString
Assert.That(keyMeta.Span.ToString(), Is.EqualTo("(2,1)-(2,9)"));
Assert.That(keyMeta.Span.End.Line, Is.EqualTo(1));
// End of line may differ depending on line endings in source control, don't assert
}

var table = doc.ToModel();
Expand All @@ -131,7 +132,7 @@ public void TestPropertySpan()

Assert.True(myTableProperties?.ContainsProperty("key"));
if (myTableProperties?.TryGetProperty("key", out var keyMeta2) == true){
Assert.That(keyMeta2.Span.ToString(), Is.EqualTo("(2,1)-(2,9)"));
Assert.That(keyMeta2.Span.ToString().StartsWith("(2,1)-(2,"));
}
}
}
Expand Down

0 comments on commit 431e672

Please sign in to comment.