summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ExampleSet.java38
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java22
2 files changed, 60 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleSet.java b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleSet.java
new file mode 100644
index 0000000..5a29e90
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleSet.java
@@ -0,0 +1,38 @@
+package org.zwobble.hobgoblin.compiler;
+
+import org.zwobble.hobgoblin.compiler.filesystem.HobgoblinCompilerFiles;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.stream.Stream;
+
+public class ExampleSet {
+ public static Stream<ExampleSet> exampleSets() {
+ return exampleSetDirectories()
+ .map(exampleDirectory -> new ExampleSet(exampleDirectory.toPath()));
+ }
+
+ /// The directory of each example set.
+ private static Stream<File> exampleSetDirectories() {
+ var examplesRoot = HobgoblinCompilerFiles.getRoot().resolve("examples");
+
+ return Arrays.stream(examplesRoot.toFile()
+ .listFiles(file -> file.isDirectory()));
+ }
+
+ private final Path path;
+
+ private ExampleSet(Path path) {
+ this.path = path;
+ }
+
+ public String name() {
+ return this.path.getFileName().toString();
+ }
+
+ public Path path() {
+ return this.path;
+ }
+}
+
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
new file mode 100644
index 0000000..354cb08
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
@@ -0,0 +1,22 @@
+package org.zwobble.hobgoblin.compiler;
+
+import org.junit.jupiter.api.DynamicTest;
+import org.junit.jupiter.api.TestFactory;
+
+import java.io.IOException;
+import java.util.stream.Stream;
+
+public class ExampleTests {
+ @TestFactory
+ public Stream<DynamicTest> tests() {
+ return ExampleSet.exampleSets()
+ .map(exampleSet -> DynamicTest.dynamicTest(
+ exampleSet.name(),
+ () -> runTest(exampleSet)
+ ));
+ }
+
+ private void runTest(ExampleSet exampleSet) throws IOException {
+ HobgoblinCompiler.compile(exampleSet.path());
+ }
+}