Skip to content
Snippets Groups Projects
Commit 3299583d authored by Johannes Mey's avatar Johannes Mey
Browse files

update tests

parent 68a444a6
Branches
No related tags found
No related merge requests found
Showing
with 225 additions and 21 deletions
Subproject commit 55ed9bd0f909000b01065307208801659af0af52 Subproject commit aeb1e3f9676705f3a05a54bbce175151825b0d7e
package org.jastadd.preprocessor; package org.jastadd.preprocessor;
import org.jastadd.option.BooleanOption;
import org.jastadd.option.ValueOption; import org.jastadd.option.ValueOption;
import org.jastadd.relast.ast.Document; import org.jastadd.relast.ast.Document;
import org.jastadd.relast.ast.Program; import org.jastadd.relast.ast.Program;
...@@ -19,9 +20,10 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor { ...@@ -19,9 +20,10 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor {
private static final String MUSTACHE_TEMPLATE = "Navigation"; private static final String MUSTACHE_TEMPLATE = "Navigation";
protected ValueOption optionErrorHandling; protected ValueOption optionErrorHandling;
protected BooleanOption optionPrintYaml;
public Main() { public Main() {
super("JastAdd Preprocessor", true); super("Navigation Attribute Generator", true);
} }
public static void main(String[] args) { public static void main(String[] args) {
...@@ -39,6 +41,8 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor { ...@@ -39,6 +41,8 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor {
super.initOptions(); super.initOptions();
optionErrorHandling = addOption(new ValueOption("errorHandling", "null|optional|exception|<exceptionClass> to return null, Optional.empty() or an exception (extending RuntimeException) in case of an error.").acceptAnyValue()); optionErrorHandling = addOption(new ValueOption("errorHandling", "null|optional|exception|<exceptionClass> to return null, Optional.empty() or an exception (extending RuntimeException) in case of an error.").acceptAnyValue());
optionErrorHandling.defaultValue("null"); optionErrorHandling.defaultValue("null");
optionPrintYaml = addOption(new BooleanOption("printYaml", "create YAML file used by Mustache in the ouput directory"));
optionPrintYaml.defaultValue(false);
} }
@Override @Override
...@@ -49,8 +53,6 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor { ...@@ -49,8 +53,6 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor {
boolean useOptionals = false; boolean useOptionals = false;
String value = optionErrorHandling.value(); String value = optionErrorHandling.value();
System.out.println("value is " + value);
System.out.println("value is matched " + optionErrorHandling.isMatched());
switch (value) { switch (value) {
case "null": case "null":
// this is the default case // this is the default case
...@@ -89,12 +91,14 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor { ...@@ -89,12 +91,14 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor {
Path yamlFile = outputBasePath.resolve(navigation.getFileName()); Path yamlFile = outputBasePath.resolve(navigation.getFileName());
Path jragFile = yamlFile.getParent().resolve(MUSTACHE_TEMPLATE + ".jrag"); Path jragFile = yamlFile.getParent().resolve(MUSTACHE_TEMPLATE + ".jrag");
writeToFile(yamlFile, navigation.prettyPrint(false)); if (optionPrintYaml.value() != null && optionPrintYaml.value()) {
writeToFile(yamlFile, navigation.prettyPrint(false));
}
try { try {
javaMustache(MUSTACHE_TEMPLATE, yamlFile.toString(), jragFile.toString()); javaMustache(MUSTACHE_TEMPLATE, navigation.prettyPrint(), jragFile.toString());
} catch (IOException e) { } catch (IOException e) {
throw new CompilerException("Unable to expand template"); throw new CompilerException("Unable to expand template", e);
} }
return 0; return 0;
......
package org.jastadd.preprocessor; package org.jastadd.preprocessor;
import org.jastadd.relast.tests.RelAstProcessorTestBase; import org.jastadd.relast.tests.RelAstProcessorTestBase;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeAll;
import java.io.IOException;
import java.nio.file.Paths;
public class PreprocessorTest extends RelAstProcessorTestBase { public class PreprocessorTest extends RelAstProcessorTestBase {
@BeforeAll
@Test static void init() {
void testSimpleInheritance() throws IOException, InterruptedException { mainClass = Main.class;
directoryTest(Main.class, Paths.get("src/test/resources/SimpleInheritance"));
} }
} }
- name: "SimpleInheritance (default)" - name: "SimpleInheritance (default)"
compare: true
out: "default/out"
expected: "default/expected"
args: args:
- "--inputBaseDir=in" - "--inputBaseDir=in"
- "--outputBaseDir=out/default/" - "--outputBaseDir=default/out"
- "Example.relast" - "Example.relast"
- name: "SimpleInheritance (null)" - name: "SimpleInheritance (null)"
compare: true
out: "null/out"
expected: "null/expected"
args: args:
- "--inputBaseDir=in" - "--inputBaseDir=in"
- "--outputBaseDir=out/null/" - "--outputBaseDir=null/out"
- "--printYaml"
- "--errorHandling=null" - "--errorHandling=null"
- "Example.relast" - "Example.relast"
- name: "SimpleInheritance (java.lang.Optional)" - name: "SimpleInheritance (java.lang.Optional)"
compare: true
out: "optional/out"
expected: "optional/expected"
args: args:
- "--inputBaseDir=in" - "--inputBaseDir=in"
- "--outputBaseDir=out/optional/" - "--outputBaseDir=optional/out"
- "--printYaml"
- "--errorHandling=optional" - "--errorHandling=optional"
- "Example.relast" - "Example.relast"
- name: "SimpleInheritance (default exception)" - name: "SimpleInheritance (default exception)"
compare: true
out: "exception/out"
expected: "exception/expected"
args: args:
- "--inputBaseDir=in" - "--inputBaseDir=in"
- "--outputBaseDir=out/exception/" - "--outputBaseDir=exception/out"
- "--printYaml"
- "--errorHandling=exception" - "--errorHandling=exception"
- "Example.relast" - "Example.relast"
- name: "SimpleInheritance (custom exception)" - name: "SimpleInheritance (custom exception)"
compare: true
out: "customexception/out"
expected: "customexception/expected"
args: args:
- "--inputBaseDir=in" - "--inputBaseDir=in"
- "--outputBaseDir=out/customexception/" - "--outputBaseDir=customexception/out"
- "--printYaml"
- "--errorHandling=java.lang.ClassCastException" - "--errorHandling=java.lang.ClassCastException"
- "Example.relast" - "Example.relast"
- name: "SimpleInheritance (wrong exception)" - name: "SimpleInheritance (wrong exception)"
...@@ -35,6 +54,6 @@ ...@@ -35,6 +54,6 @@
- "Invalid argument 'not.a.Class' for parameter 'errorHandling': Class not found (name must be qualified)." - "Invalid argument 'not.a.Class' for parameter 'errorHandling': Class not found (name must be qualified)."
args: args:
- "--inputBaseDir=in" - "--inputBaseDir=in"
- "--outputBaseDir=out/castexception/" - "--outputBaseDir=out/does_not_matter_will_fail"
- "--errorHandling=not.a.Class" - "--errorHandling=not.a.Class"
- "Example.relast" - "Example.relast"
aspect Navigation {
/** Tests if A is a A1.
* @return 'true' if this is a A1, otherwise 'false'
*/
syn A A.isA1() = false;
eq A1.isA1() = true;
/** Tests if A is a A2.
* @return 'true' if this is a A2, otherwise 'false'
*/
syn A A.isA2() = false;
eq A2.isA2() = true;
/** casts a A into a A1 if possible.
* @return 'this' cast to a A1 or a
*/
syn A A.asA1();
eq A.asA1() {
throw new java.lang.ClassCastException();
}
eq A1.asA1() = this;
/** casts a A into a A2 if possible.
* @return 'this' cast to a A2 or a
*/
syn A A.asA2();
eq A.asA2() {
throw new java.lang.ClassCastException();
}
eq A2.asA2() = this;
}
useExceptions: true
useOptionals: false
exceptionName: java.lang.ClassCastException
types:
- typeName: A
subtypes:
- subtypeName: A1
- subtypeName: A2
aspect Navigation {
/** Tests if A is a A1.
* @return 'true' if this is a A1, otherwise 'false'
*/
syn A A.isA1() = false;
eq A1.isA1() = true;
/** Tests if A is a A2.
* @return 'true' if this is a A2, otherwise 'false'
*/
syn A A.isA2() = false;
eq A2.isA2() = true;
/** casts a A into a A1 if possible.
* @return 'this' cast to a A1 or 'null'
*/
syn A A.asA1();
eq A.asA1() = null;
eq A1.asA1() = this;
/** casts a A into a A2 if possible.
* @return 'this' cast to a A2 or 'null'
*/
syn A A.asA2();
eq A.asA2() = null;
eq A2.asA2() = this;
}
aspect Navigation {
/** Tests if A is a A1.
* @return 'true' if this is a A1, otherwise 'false'
*/
syn A A.isA1() = false;
eq A1.isA1() = true;
/** Tests if A is a A2.
* @return 'true' if this is a A2, otherwise 'false'
*/
syn A A.isA2() = false;
eq A2.isA2() = true;
/** casts a A into a A1 if possible.
* @return 'this' cast to a A1 or a
*/
syn A A.asA1();
eq A.asA1() {
throw new RuntimeException();
}
eq A1.asA1() = this;
/** casts a A into a A2 if possible.
* @return 'this' cast to a A2 or a
*/
syn A A.asA2();
eq A.asA2() {
throw new RuntimeException();
}
eq A2.asA2() = this;
}
useExceptions: true
useOptionals: false
exceptionName: RuntimeException
types:
- typeName: A
subtypes:
- subtypeName: A1
- subtypeName: A2
aspect Navigation {
/** Tests if A is a A1.
* @return 'true' if this is a A1, otherwise 'false'
*/
syn A A.isA1() = false;
eq A1.isA1() = true;
/** Tests if A is a A2.
* @return 'true' if this is a A2, otherwise 'false'
*/
syn A A.isA2() = false;
eq A2.isA2() = true;
/** casts a A into a A1 if possible.
* @return 'this' cast to a A1 or 'null'
*/
syn A A.asA1();
eq A.asA1() = null;
eq A1.asA1() = this;
/** casts a A into a A2 if possible.
* @return 'this' cast to a A2 or 'null'
*/
syn A A.asA2();
eq A.asA2() = null;
eq A2.asA2() = this;
}
useExceptions: false
useOptionals: false
exceptionName: java.lang.RuntimeException
types:
- typeName: A
subtypes:
- subtypeName: A1
- subtypeName: A2
aspect Navigation {
/** Tests if A is a A1.
* @return 'true' if this is a A1, otherwise 'false'
*/
syn A A.isA1() = false;
eq A1.isA1() = true;
/** Tests if A is a A2.
* @return 'true' if this is a A2, otherwise 'false'
*/
syn A A.isA2() = false;
eq A2.isA2() = true;
/** casts a A into a A1 if possible.
* @return an Optional of 'this' cast to a A1 or an empty Optional
*/
syn A A.asA1();
eq A.asA1() = java.util.Optional.empty();
eq .asA1() = java.util.Optional.of(this);
/** casts a A into a A2 if possible.
* @return an Optional of 'this' cast to a A2 or an empty Optional
*/
syn A A.asA2();
eq A.asA2() = java.util.Optional.empty();
eq .asA2() = java.util.Optional.of(this);
}
useExceptions: false
useOptionals: true
exceptionName: java.lang.RuntimeException
types:
- typeName: A
subtypes:
- subtypeName: A1
- subtypeName: A2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment