예제 #1
0
        public static JSParserResult RunTest(string sourceName, string resultName)
        {
            var source = TestsHelper.GetEmbeddedText("JsParser.Test.Parser.Source." + sourceName);

            // Fix line endings in test files. All should be unix way, but on some GIT clients it is updated automatically.
            source = source.Replace("\r\n", "\n");

            var settings = new JavascriptParserSettings()
            {
                Filename = sourceName,
            };
            var actualResult = (new JavascriptParser(settings)).Parse(source);

            var outDir = "C:\\js_parser_units_output";

            Directory.CreateDirectory(outDir);

            // Save actual hierarchy xml
            var serialized = SimpleHierarchySerializer.Serialize(actualResult.Nodes);

            File.WriteAllText(outDir + "\\" + resultName, serialized);

            // Load test data
            var resName = "JsParser.Test.Parser.ExpectedResult." + resultName;

            var passed = false;

            if (TestsHelper.CheckEmbeddedRes(resName))
            {
                File.WriteAllText(outDir + "\\" + resultName, SimpleHierarchySerializer.Serialize(actualResult.Nodes));

                var expectedresultSerialized = TestsHelper.GetEmbeddedText(resName);
                var expectedresult           = SimpleHierarchySerializer.Deserialize <CodeNode>(expectedresultSerialized);

                // Save expected hierarchy serialized
                File.WriteAllText(outDir + "\\" + resultName + ".ex", expectedresultSerialized);

                if (HierarchyComparer.Compare(actualResult.Nodes, expectedresult, new CodeNodeAssertComparer()))
                {
                    passed = true;
                }
            }

            Assert.IsTrue(passed);

            return(actualResult);
        }