|
|
@ -2,15 +2,12 @@ package triangle.syntacticAnalyser; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertNotEquals; |
|
|
|
import static org.junit.Assert.assertNotEquals; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertNull; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertThrows; |
|
|
|
import static org.junit.Assert.assertThrows; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.function.ThrowingRunnable; |
|
|
|
import org.junit.function.ThrowingRunnable; |
|
|
|
|
|
|
|
|
|
|
|
import triangle.ErrorReporter; |
|
|
|
import triangle.ErrorReporter; |
|
|
|
import triangle.abstractSyntaxTrees.AbstractSyntaxTree; |
|
|
|
|
|
|
|
import triangle.syntacticAnalyzer.Parser; |
|
|
|
import triangle.syntacticAnalyzer.Parser; |
|
|
|
import triangle.syntacticAnalyzer.Scanner; |
|
|
|
import triangle.syntacticAnalyzer.Scanner; |
|
|
|
import triangle.syntacticAnalyzer.SourceFile; |
|
|
|
import triangle.syntacticAnalyzer.SourceFile; |
|
|
@ -19,10 +16,28 @@ public class TestScanner { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testHi() { |
|
|
|
public void testHi() { |
|
|
|
|
|
|
|
compileExpectSuccess("/hi.tri"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testHiNewComment() { |
|
|
|
|
|
|
|
compileExpectFailure("/hi-newcomment.tri"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testHiNewComment2() { |
|
|
|
|
|
|
|
compileExpectFailure("/hi-newcomment2.tri"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void compileExpectSuccess(String filename) { |
|
|
|
// build.gradle has a line sourceSets.test.resources.srcDir file("$rootDir/programs")
|
|
|
|
// build.gradle has a line sourceSets.test.resources.srcDir file("$rootDir/programs")
|
|
|
|
// which adds the programs directory to the list of places Java can easily find files
|
|
|
|
// which adds the programs directory to the list of places Java can easily find files
|
|
|
|
// getResource() below searches for a file, which is in /programs
|
|
|
|
// getResource() below searches for a file, which is in /programs
|
|
|
|
SourceFile source = SourceFile.ofPath(this.getClass().getResource("/hi.tri").getFile().toString()); |
|
|
|
SourceFile source = SourceFile.ofPath(this.getClass().getResource(filename).getFile().toString()); |
|
|
|
|
|
|
|
|
|
|
|
Scanner scanner = new Scanner(source); |
|
|
|
Scanner scanner = new Scanner(source); |
|
|
|
ErrorReporter reporter = new ErrorReporter(true); |
|
|
|
ErrorReporter reporter = new ErrorReporter(true); |
|
|
@ -32,14 +47,11 @@ public class TestScanner { |
|
|
|
|
|
|
|
|
|
|
|
// we should get to here with no exceptions
|
|
|
|
// we should get to here with no exceptions
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("Problem compiling hi.tri", 0, reporter.getNumErrors()); |
|
|
|
assertEquals("Problem compiling " + filename, 0, reporter.getNumErrors()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void compileExpectFailure(String filename) { |
|
|
|
@Test |
|
|
|
SourceFile source = SourceFile.ofPath(this.getClass().getResource(filename).getFile().toString()); |
|
|
|
public void testHiNewComment() { |
|
|
|
|
|
|
|
SourceFile source = SourceFile.ofPath(this.getClass().getResource("/hi-newcomment.tri").getFile().toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Scanner scanner = new Scanner(source); |
|
|
|
Scanner scanner = new Scanner(source); |
|
|
|
ErrorReporter reporter = new ErrorReporter(true); |
|
|
|
ErrorReporter reporter = new ErrorReporter(true); |
|
|
|
Parser parser = new Parser(scanner, reporter); |
|
|
|
Parser parser = new Parser(scanner, reporter); |
|
|
@ -52,7 +64,7 @@ public class TestScanner { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// currently this program will fail
|
|
|
|
// currently this program will fail
|
|
|
|
assertNotEquals("Problem compiling hi-newcomment.tri", 0, reporter.getNumErrors()); |
|
|
|
assertNotEquals("Problem compiling " + filename, 0, reporter.getNumErrors()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|