Ejemplo n.º 1
0
        public void CanRoundtripTestcase()
        {
            string testcase = GetTestcase();
            var    ast      = WebIDLParser.Parse(new StringReader(testcase));
            string actual   = WebIDLFormatter.Format(ast);

            //File.WriteAllText("Result.webidl", actual);

            var expectedLines = testcase.Replace("\r\n", "\n").Split('\n');
            var actualLines   = actual.Replace("\r\n", "\n").Split('\n').Select(Normalize).Where(s => s != "").ToArray();
            int actualIndex   = 0;

            for (int expectedIndex = 0; expectedIndex < expectedLines.Length; expectedIndex++)
            {
                string expectedLine = Normalize(expectedLines[expectedIndex].Trim());
                if (expectedLine == "")
                {
                    continue;
                }
                if (actualIndex == actualLines.Length)
                {
                    Assert.Fail("Testcase line #{0}:\nWas \"{1}\".\nNo more expected lines.", expectedIndex + 1, expectedLines[expectedIndex]);
                }
                if (expectedLine != actualLines[actualIndex])
                {
                    Assert.Fail("Testcase line #{0}:\nWas \"{1}\".\nexpected \"{2}\".", expectedIndex + 1, actualLines[actualIndex], expectedLines[expectedIndex]);
                }
                actualIndex++;
            }
        }
Ejemplo n.º 2
0
        public void CanResolveTestcase()
        {
            string testcase = GetTestcase();
            var    ast      = WebIDLParser.Parse(new StringReader(testcase));
            var    resolved = WebIDLResolver.Resolve(new[] { ast });

            Assert.AreEqual(resolved.Item2.Count, 0, "Errors:" + Environment.NewLine + string.Join(Environment.NewLine, resolved.Item2));
        }
Ejemplo n.º 3
0
        private void AssertCorrect(string webidl, string expected)
        {
            var    ast      = WebIDLParser.Parse(new StringReader(webidl));
            var    resolved = WebIDLResolver.Resolve(new[] { ast });
            string actual   = (resolved.Item2.Count > 0 ? string.Join("\n", resolved.Item2.Select(s => "error: " + s)) + "\n\n": "") + Format(resolved.Item1);

            Assert.That(actual.Trim().Replace("\r\n", "\n"), Is.EqualTo(expected.Trim().Replace("\r\n", "\n")), "Expected:\n" + expected + "\n\nActual:\n" + actual);
        }