public void VisitorVisitTests() { string path = (string)TestContext.DataRow["files"]; string testcontent = File.ReadAllText(path); string[] testparts = testcontent.Split(new string[] { "<<<TEST>>>" }, StringSplitOptions.RemoveEmptyEntries); Assert.IsTrue(testparts.Length >= 2); var sourceUnit = new CodeSourceUnit(testparts[0], path, Encoding.UTF8, Lexer.LexicalStates.INITIAL, LanguageFeatures.Basic); var factory = new AstCounterFactory(sourceUnit); var errors = new TestErrorSink(); GlobalCode ast = null; using (StringReader source_reader = new StringReader(testparts[0])) { sourceUnit.Parse(factory, errors, new TestErrorRecovery()); ast = sourceUnit.Ast; } if (testparts[1].TrimStart().StartsWith(ParserTests.Errors)) { var matches = _errorRegex.Matches(testparts[1]); var knownErrors = matches[0].Groups["Number"].Value.Split(','); Assert.AreEqual(1, matches.Count, path); Assert.AreEqual(knownErrors.Length, errors.Count, path); } else { Assert.AreEqual(0, errors.Count, path); Assert.IsNotNull(ast); // check every node has a parent var checker = new TreeVisitorCheck(); checker.VisitElement(ast); Assert.AreEqual(factory.CreatedElements.Count, checker.VisitedElements.Count, path); Assert.AreEqual(factory.ItemCount, checker.ItemCount, path); Assert.AreEqual(factory.ForeachVarCount, checker.ForeachVarCount, path); //var dictionary = factory.CreatedElements.GroupBy(t => t.GetType()).ToDictionary(g => g.Key); } }
public void VisitorVisitTests() { string path = (string)TestContext.DataRow["files"]; string testcontent = File.ReadAllText(path); string[] testparts = testcontent.Split(new string[] { "<<<TEST>>>" }, StringSplitOptions.RemoveEmptyEntries); Assert.IsTrue(testparts.Length >= 2); var sourceUnit = new CodeSourceUnit(testparts[0], path, Encoding.UTF8, Lexer.LexicalStates.INITIAL, LanguageFeatures.Basic); var factory = new AstCounterFactory(sourceUnit); var errors = new TestErrorSink(); bool expectErrors = testparts[1].TrimStart().StartsWith(ParserTests.Errors); GlobalCode ast = null; Parser parser = new Parser(); using (StringReader source_reader = new StringReader(testparts[0])) { sourceUnit.Parse(factory, errors); ast = sourceUnit.Ast; } if (expectErrors) { Assert.AreEqual(1, errors.Count, path); } else { Assert.AreEqual(0, errors.Count, path); // check every node has a parent var checker = new TreeVisitorCheck(); checker.VisitElement(ast); Assert.AreEqual(factory.CreatedElements.Count, checker.VisitedElements.Count, path); Assert.AreEqual(factory.ItemCount, checker.ItemCount, path); Assert.AreEqual(factory.ForeachVarCount, checker.ForeachVarCount, path); } }