diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/03-inductive-data-types/hobgoblin.json5 | 2 | ||||
| -rw-r--r-- | examples/03-inductive-data-types/output/java-junit/.gitignore (renamed from examples/03-inductive-data-types/output/java/.gitignore) | 0 | ||||
| l--------- | examples/03-inductive-data-types/output/java-junit/pom.xml | 1 | ||||
| -rw-r--r-- | examples/03-inductive-data-types/output/java-junit/src/test/java/org/zwobble/example/ArithmeticTests.java | 34 | ||||
| -rw-r--r-- | examples/03-inductive-data-types/output/java/pom.xml | 40 | ||||
| -rw-r--r-- | examples/03-inductive-data-types/output/java/src/main/java/org/zwobble/example/Main.java | 17 |
6 files changed, 36 insertions, 58 deletions
diff --git a/examples/03-inductive-data-types/hobgoblin.json5 b/examples/03-inductive-data-types/hobgoblin.json5 index 12713d4..8a073ac 100644 --- a/examples/03-inductive-data-types/hobgoblin.json5 +++ b/examples/03-inductive-data-types/hobgoblin.json5 @@ -8,7 +8,7 @@ generators: [ { generator: "java-types", - path: "output/java/src/gen/java", + path: "output/java-junit/src/gen/java", }, { generator: "rust-types", diff --git a/examples/03-inductive-data-types/output/java/.gitignore b/examples/03-inductive-data-types/output/java-junit/.gitignore index ff511d4..ff511d4 100644 --- a/examples/03-inductive-data-types/output/java/.gitignore +++ b/examples/03-inductive-data-types/output/java-junit/.gitignore diff --git a/examples/03-inductive-data-types/output/java-junit/pom.xml b/examples/03-inductive-data-types/output/java-junit/pom.xml new file mode 120000 index 0000000..445fa65 --- /dev/null +++ b/examples/03-inductive-data-types/output/java-junit/pom.xml @@ -0,0 +1 @@ +../../../templates/java-junit/pom.xml
\ No newline at end of file diff --git a/examples/03-inductive-data-types/output/java-junit/src/test/java/org/zwobble/example/ArithmeticTests.java b/examples/03-inductive-data-types/output/java-junit/src/test/java/org/zwobble/example/ArithmeticTests.java new file mode 100644 index 0000000..5623af5 --- /dev/null +++ b/examples/03-inductive-data-types/output/java-junit/src/test/java/org/zwobble/example/ArithmeticTests.java @@ -0,0 +1,34 @@ +package org.zwobble.example; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import org.zwobble.example.types.arithmetic.Add; +import org.zwobble.example.types.arithmetic.Const; +import org.zwobble.example.types.arithmetic.Expression; + +public class ArithmeticTests { + @Test + public void eval() { + Expression expression = new Add( + new Add( + new Const(42), + new Const(47) + ), + new Const(52) + ); + + int result = eval(expression); + + assertEquals(result, 141); + } + + private int eval(Expression expression) { + return switch (expression) { + case Add(var left, var right) -> + eval(left) + eval(right); + + case Const(var value) -> + value; + }; + } +} diff --git a/examples/03-inductive-data-types/output/java/pom.xml b/examples/03-inductive-data-types/output/java/pom.xml deleted file mode 100644 index 0035469..0000000 --- a/examples/03-inductive-data-types/output/java/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.zwobble.hobgoblin.examples</groupId> - <artifactId>example</artifactId> - <version>1.0-SNAPSHOT</version> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.source>25</maven.compiler.source> - <maven.compiler.target>25</maven.compiler.target> - <exec.mainClass>org.zwobble.example.Main</exec.mainClass> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>3.6.1</version> - <executions> - <execution> - <id>add-source</id> - <phase>generate-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <source>src/gen/java</source> - </sources> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/examples/03-inductive-data-types/output/java/src/main/java/org/zwobble/example/Main.java b/examples/03-inductive-data-types/output/java/src/main/java/org/zwobble/example/Main.java deleted file mode 100644 index 901c9e8..0000000 --- a/examples/03-inductive-data-types/output/java/src/main/java/org/zwobble/example/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.zwobble.example; - -import org.zwobble.example.types.arithmetic.Add; -import org.zwobble.example.types.arithmetic.Const; -import org.zwobble.example.types.arithmetic.Expression; - -public class Main { - public static void main() { - Expression expression = new Add( - new Add( - new Const(42), - new Const(47) - ), - new Const(52) - ); - } -} |
