public void ASTBuilderSuccess() { UnitTestParsing testParsing = new UnitTestParsing(); string directorySuccess = "../../../TestCases/Parsing/success/"; DirectoryInfo directory = new DirectoryInfo(directorySuccess); FileInfo[] files = directory.GetFiles(); foreach (var file in files) { testParsing.ParsingFile(file.FullName); var astBuilder = new ASTBuilder(); ASTNode root = astBuilder.Visit(testParsing.tree); Assert.IsFalse(root is null, "AST no created. (root is null)"); Assert.IsTrue(root is ProgramNode, $"AST created with big problems. (root is not a ProgramNode, root is {root})"); } }
public void TopologicalSortFail() { UnitTestParsing testParsing = new UnitTestParsing(); string directoryFail = "../../../TestCases/Algorithm/fail/"; DirectoryInfo directory = new DirectoryInfo(directoryFail); FileInfo[] files = directory.GetFiles(); foreach (var file in files) { var errors = new List <string>(); testParsing.ParsingFile(file.FullName); var astBuilder = new ASTBuilder(); ProgramNode program = astBuilder.Visit(testParsing.tree) as ProgramNode; Algorithm.TopologicalSort(program.Classes, errors); Assert.IsTrue(errors.Count != 0, $"Not found cycles in class dependency in file {file.Name}"); } }
public void TopologicalSortSuccess() { UnitTestParsing testParsing = new UnitTestParsing(); string directorySuccess = "../../../TestCases/Algorithm/success/"; DirectoryInfo directory = new DirectoryInfo(directorySuccess); FileInfo[] files = directory.GetFiles(); foreach (var file in files) { var errors = new List <string>(); testParsing.ParsingFile(file.FullName); var astBuilder = new ASTBuilder(); ProgramNode program = astBuilder.Visit(testParsing.tree) as ProgramNode; Algorithm.TopologicalSort(program.Classes, errors); foreach (var item in errors) { Assert.Fail(file.Name + ": " + item.ToString()); } } }
public void TestSemanticsFail() { UnitTestParsing testParsing = new UnitTestParsing(); string directoryFail = "../../../TestCases/Semantics/fail/"; DirectoryInfo directory = new DirectoryInfo(directoryFail); FileInfo[] files = directory.GetFiles(); foreach (var file in files) { var errors = new List <string>(); List <string> errorParsing = testParsing.ParsingFile(file.FullName); if (errorParsing.Any()) { Assert.IsTrue(errorParsing.Any()); continue; } var astBuilder = new ASTBuilder(); ProgramNode program = astBuilder.Visit(testParsing.tree) as ProgramNode; Scope.Clear(); var scope = new Scope(); program = new Tour1().CheckSemantic(program, scope, errors); if (errors.Any()) { Assert.IsTrue(errors.Any(), file.Name); } else { program = new Tour2().CheckSemantic(program, scope, errors); Assert.IsTrue(errors.Any(), file.Name); } } }
public void TestSemanticsSuccess() { UnitTestParsing testParsing = new UnitTestParsing(); string directorySuccess = "../../../TestCases/Semantics/success/"; DirectoryInfo directory = new DirectoryInfo(directorySuccess); FileInfo[] files = directory.GetFiles(); foreach (var file in files) { var errors = new List <string>(); List <string> errorParsing = testParsing.ParsingFile(file.FullName); foreach (var item in errorParsing) { Assert.Fail($"Parsing error in {file.Name}: {item}"); } var astBuilder = new ASTBuilder(); ProgramNode program = astBuilder.Visit(testParsing.tree) as ProgramNode; Scope.Clear(); var scope = new Scope(); program = new Tour1().CheckSemantic(program, scope, errors); foreach (var item in errors) { Assert.Fail(file.Name + ": " + item.ToString()); } program = new Tour2().CheckSemantic(program, scope, errors); foreach (var item in errors) { Assert.Fail(file.Name + ": " + item.ToString()); } } }