public void StructureTest(StructureTestData testData) { using (var sr = new StringReader(testData.Ftl)) { var resource = new Parser().Parse(sr); var resourceJson = AstToJson.ToJson(resource); bool resultsEqual = JToken.DeepEquals(resourceJson, testData.Expected); if (!resultsEqual) { Console.WriteLine("parsed ="); Console.WriteLine(resourceJson); Console.WriteLine("expected ="); Console.WriteLine(testData.Expected); var jdp = new JsonDiffPatch(); var diff = jdp.Diff(resourceJson, testData.Expected); Console.WriteLine("diff ="); Console.WriteLine(diff); } resultsEqual.Should().BeTrue(); // doesn't seem to work -- just returns true // resourceJson.Should().BeEquivalentTo(testData.Expected, // options => options.AllowingInfiniteRecursion().RespectingRuntimeTypes()); } }
public void ReferenceTest(StructureTestData testData) { // The following fixtures produce different ASTs in the tooling parser than // in the reference parser. Skip them for now. var skips = new HashSet <string>() { // Call arguments edge-cases. "call_expressions", // The tooling parser rejects variant keys which contain leading whitespace. // There's even a behavior fixture for this; it must have been a // deliberate decision. "select_expressions", // Broken Attributes break the entire Entry right now. // https://github.com/projectfluent/fluent.js/issues/237 "leading_dots", "variant_lists" }; if (skips.Contains(testData.TestName)) { Assert.Ignore(); } using (var sr = new StringReader(testData.Ftl)) { var resource = new Parser(false).Parse(sr); // Ignore Junk which is parsed differently by the tooling parser, and // which doesn't carry spans nor annotations in the reference parser. resource.Body = resource.Body.Where(x => !(x is Ast.Junk)).ToList(); testData.Expected["body"] = new JArray( ((JArray)testData.Expected["body"]).Where(x => x["type"].ToString() != "Junk")); var resourceJson = AstToJson.ToJson(resource); bool resultsEqual = JToken.DeepEquals(resourceJson, testData.Expected); if (!resultsEqual) { Console.WriteLine("parsed ="); Console.WriteLine(resourceJson); Console.WriteLine("expected ="); Console.WriteLine(testData.Expected); var jdp = new JsonDiffPatch(); var diff = jdp.Diff(resourceJson, testData.Expected); Console.WriteLine("diff ="); Console.WriteLine(diff); } resultsEqual.Should().BeTrue(); } }