-
-
Save shepherdjerred/4b13eed30431a91d5ad887932ba923c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.shepherdjerred.compiler; | |
import au.com.origin.snapshots.Expect; | |
import au.com.origin.snapshots.junit5.SnapshotExtension; | |
import com.shepherdjerred.compiler.error.LexerException; | |
import com.shepherdjerred.compiler.error.ParserException; | |
import lombok.SneakyThrows; | |
import org.junit.jupiter.api.Test; | |
import org.junit.jupiter.api.extension.ExtendWith; | |
import org.junit.jupiter.params.ParameterizedTest; | |
import org.junit.jupiter.params.provider.MethodSource; | |
import java.io.File; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.Arrays; | |
import java.util.stream.Stream; | |
import static org.junit.jupiter.api.Assertions.assertThrows; | |
@ExtendWith({SnapshotExtension.class}) | |
public class MainTest { | |
private Expect expect; | |
@Test | |
@SneakyThrows | |
public void TestHelloWorld() { | |
var compiler = new TigerCompiler(); | |
var file = "src/test/resources/hello.tiger"; | |
compiler.compile(file, false); | |
} | |
@Test | |
@SneakyThrows | |
public void TestHelloWorldTokens() { | |
Path tokensFile = Paths.get("src/test/resources/hello.tokens"); | |
Files.deleteIfExists(tokensFile); | |
var compiler = new TigerCompiler(); | |
var file = "src/test/resources/hello.tiger"; | |
compiler.compile(file,true); | |
assert Files.exists(tokensFile); | |
expect.toMatchSnapshot(Files.readString(tokensFile)); | |
Files.delete(tokensFile); | |
} | |
public static Stream<String> TestBadLexer() { | |
var files = Paths.get("src/test/resources/official/bad/lexer").toFile().listFiles(); | |
assert files != null; | |
return Arrays.stream(files).map(File::getAbsolutePath); | |
} | |
@ParameterizedTest | |
@MethodSource() | |
public void TestBadLexer(String file) { | |
var compiler = new TigerCompiler(); | |
assertThrows(LexerException.class, () -> compiler.compile(file, false)); | |
} | |
public static Stream<String> TestBadParser() { | |
var files = Paths.get("src/test/resources/official/bad/parser").toFile().listFiles(); | |
assert files != null; | |
return Arrays.stream(files).map(File::getAbsolutePath); | |
} | |
@ParameterizedTest | |
@MethodSource() | |
public void TestBadParser(String file) { | |
var compiler = new TigerCompiler(); | |
assertThrows(ParserException.class, () -> compiler.compile(file, false)); | |
} | |
public static Stream<String> TestGoodSyntax() { | |
var files = Paths.get("src/test/resources/official/happy").toFile().listFiles(); | |
assert files != null; | |
return Arrays.stream(files).map(File::getAbsolutePath); | |
} | |
@SneakyThrows | |
@ParameterizedTest | |
@MethodSource() | |
public void TestGoodSyntax(String file) { | |
var compiler = new TigerCompiler(); | |
compiler.compile(file, false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment