Skip to content

Commit

Permalink
Don't write test output for standard tests if they are not failing
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Feb 25, 2022
1 parent 909dd77 commit 12914cd
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions src/Tomlyn.Tests/StandardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ public static void SpecInvalid(string inputName, string toml, string json)

private static void ValidateSpec(string type, string inputName, string toml, string json)
{
Console.WriteLine($"Testing {inputName}");
var doc = Toml.Parse(toml, inputName);
var roundtrip = doc.ToString();
Dump(toml, doc, roundtrip);
switch (type)
{
case ValidSpec:
if (doc.HasErrors || toml != roundtrip)
{
Console.WriteLine($"Testing {inputName}");
Dump(toml, doc, roundtrip);
}
Assert.False(doc.HasErrors, "Unexpected parsing errors");
// Only in the case of a valid spec we check for rountrip
Assert.AreEqual(toml, roundtrip, "The roundtrip doesn't match");
Expand All @@ -65,35 +68,61 @@ private static void ValidateSpec(string type, string inputName, string toml, str
var expectedJsonAsString = expectedJson.ToString(Formatting.Indented);
var computedJsonAsString = computedJson.ToString(Formatting.Indented);

DisplayHeader("json");
Console.WriteLine(computedJsonAsString);
if (expectedJsonAsString != computedJsonAsString)
{
Console.WriteLine($"Testing {inputName}");
Dump(toml, doc, roundtrip);
DisplayHeader("json");
Console.WriteLine(computedJsonAsString);

DisplayHeader("expected json");
Console.WriteLine(expectedJsonAsString);
DisplayHeader("expected json");
Console.WriteLine(expectedJsonAsString);
}

Assert.AreEqual(expectedJsonAsString, computedJsonAsString);

DisplayHeader("toml from model");
var tomlFromModel = Toml.FromModel(model);
Console.WriteLine(tomlFromModel);


var model2 = Toml.ToModel<TomlTable>(tomlFromModel);
var computedJson2 = ModelHelper.ToJson(model2);
var computedJson2AsString = computedJson2.ToString(Formatting.Indented);

DisplayHeader("json2");
Console.WriteLine(computedJson2AsString);
if (expectedJsonAsString != computedJson2AsString)
{
Console.WriteLine($"Testing {inputName}");
Dump(toml, doc, roundtrip);
DisplayHeader("expected json");
Console.WriteLine(expectedJsonAsString);

DisplayHeader("toml from model");
Console.WriteLine(tomlFromModel);

DisplayHeader("json2");
Console.WriteLine(computedJson2AsString);
}

Assert.AreEqual(expectedJsonAsString, computedJson2AsString);
break;
case InvalidSpec:
if (!doc.HasErrors)
{
Console.WriteLine($"Testing {inputName}");
Dump(toml, doc, roundtrip);
}

Assert.True(doc.HasErrors, "The TOML requires parsing/validation errors");
break;
}

{
var docUtf8 = Toml.Parse(Encoding.UTF8.GetBytes(toml), inputName);
var roundtripUtf8 = docUtf8.ToString();
if (roundtrip != roundtripUtf8)
{
Console.WriteLine($"Testing {inputName}");
Dump(toml, doc, roundtrip);
}
Assert.AreEqual(roundtrip, roundtripUtf8, "The UTF8 version doesn't match with the UTF16 version");
}
}
Expand Down

0 comments on commit 12914cd

Please sign in to comment.