Commit 35057175 authored by Fred Eisele's avatar Fred Eisele
Browse files

cleaned up testing, added antlr4 parser to test suite

parent b77c0dc9
......@@ -24,5 +24,17 @@ public abstract class AqlParserFactory {
return new CombinatorParser();
}
}
public static IAqlParser getParser(final Mode mode) {
if(mode == Mode.COMBINATOR) {
return new CombinatorParser();
}
else if(mode == Mode.ANTLR4) {
return new Antlr4Parser();
}
else {
return new CombinatorParser();
}
}
}
package catdata.aql;
import catdata.ParseException;
import catdata.Program;
import catdata.aql.exp.AqlEnv;
import catdata.aql.exp.AqlMultiDriver;
......@@ -12,29 +13,51 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.fail;
public class AqlExampleTest {
public static Stream<Arguments> loadExamples(Language lang) {
return Examples
.getExamples(lang).stream()
.map(example ->
new Arguments[]{
Arguments.of(
example.getName(),
example.getText(),
AqlParserFactory.Mode.COMBINATOR,
new String[1]),
Arguments.of(
example.getName(),
example.getText(),
AqlParserFactory.Mode.ANTLR4,
new String[1])})
.flatMap(a -> Arrays.stream(a));
}
public void runSourceText(String description, String src, AqlParserFactory.Mode mode, String[] args)
throws ParseException
{
System.out.println("testing example: " + description + " parser: " + mode + " args: " + Arrays.toString(args));
final Program<Exp<?>> prog = AqlParserFactory.getParser(mode).parseProgram(src);
final AqlMultiDriver driver = new AqlMultiDriver(prog, args, null);
driver.start();
final AqlEnv lastEnv = driver.env;
if (lastEnv.exn != null) {
throw lastEnv.exn;
}
}
@ParameterizedTest
@MethodSource("loadExamples")
public void testSourceText(String description, String src) {
System.out.println("testing example: " + description);
@MethodSource("loadEffectiveExamples")
public void testSourceText(String description, String src, AqlParserFactory.Mode mode, String[] args) {
System.out.println("testing example: " + description + " parser: " + mode + " args: " + Arrays.toString(args));
try {
final Program<Exp<?>> prog = AqlParserFactory.getParser().parseProgram(src);
final AqlMultiDriver driver = new AqlMultiDriver(prog, new String[1], null);
driver.start();
final AqlEnv lastEnv = driver.env;
if (lastEnv.exn != null) {
throw lastEnv.exn;
}
final String msg = new StringBuilder()
.append("Test failed AS EXPECTED for test case '")
.append(description)
.append("' \n")
.toString();
runSourceText(description,src,mode,args);
} catch (Exception e) {
final String msg = new StringBuilder()
.append("Test failed for test case '")
......@@ -48,38 +71,29 @@ public class AqlExampleTest {
}
}
public static Stream<Arguments> loadExamples() {
return Examples
.getExamples(Language.AQL).stream()
.map(example -> Arguments.of(example.getName(), example.getText()));
}
public static Stream<Arguments> loadEffectiveExamples() {
return loadExamples(Language.AQL);
}
@ParameterizedTest
@MethodSource("loadDefectiveExamples")
public void testDefectiveSourceText(String description, String src) {
System.out.println("testing example: " + description);
try {
final Program<Exp<?>> prog = AqlParserFactory.getParser().parseProgram(src);
final AqlMultiDriver driver = new AqlMultiDriver(prog, new String[1], null);
driver.start();
final AqlEnv lastEnv = driver.env;
if (lastEnv.exn != null) {
throw lastEnv.exn;
}
final String msg = new StringBuilder()
.append("Test succeeded for test case '")
.append(description)
.append("' \n")
.toString();
fail(msg);
} catch (Exception e) {
}
}
@ParameterizedTest
@MethodSource("loadDefectiveExamples")
public void testDefectiveSourceText(String description, String src, AqlParserFactory.Mode mode, String[] args) {
System.out.println("testing example: " + description);
try {
runSourceText(description,src,mode,args);
final String msg = new StringBuilder()
.append("Test succeeded when expected to fail for test case '")
.append(description)
.append("' \n")
.toString();
fail(msg);
} catch (Exception e) {
}
}
public static Stream<Arguments> loadDefectiveExamples() {
return loadExamples(Language.AQL_ALT);
}
public static Stream<Arguments> loadDefectiveExamples() {
return Examples
.getExamples(Language.AQL_ALT).stream()
.map(example -> Arguments.of(example.getName(), example.getText()));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment