This project provides code that can be used to test Jamal extension macros that are written in Java.
A built-in macro most of the time converts the content to another string.
You need an instance of the macro class, a processor, an input object that contains the StringBuilder
, and a null
reference file name to test.
The test just invokes the macro Macro.evaluate(Input, javax0.jamal.api.Processor)
method and checks the returned string against the expected.
Xou can put this module on the test dependencies
<dependency> <groupId>com.javax0.jamal</groupId> <artifactId>jamal-testsupport</artifactId> <version>2.8.0</version> </dependency>
and have a test like
void testCamelLowerCase() throws Exception { var camelLowerCase = TestThat.theMacro(Camel.LowCamel.class); camelLowerCase.fromTheInput("INPUT").results("input"); camelLowerCase.fromTheInput("INpUT").results("input"); camelLowerCase.fromTheInput("INpuT").results("input"); camelLowerCase.fromTheInput("INput").results("input"); camelLowerCase.fromTheInput("Input").results("input"); camelLowerCase.fromTheInput("input").results("input"); camelLowerCase.fromTheInput("IN-PUT").results("inPut"); camelLowerCase.fromTheInput("I-N-P-U-T").results("iNPUT"); }
If the macro is expected to throw an exception, you write
TestThat .forMacro(For.class) .fromInput(" x in a,b,c,d= x is either a, b, c or d\n") .throwsBadSyntax();
If you expect some other exception type, you use throwsUp(exception.class)
instead of
throwsBadSyntax()
.
public class Test {
@TestFactory
Object testAll() {
return JamalYamlTest.factory(
String[]{ list all test files that are in the same resource directory and have .jyt extension}
);
}
}
Then have the files with .jyt
extension contain Jamal preprocessed Yaml files. Open and close are {% and `%}
.