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

improve tests and path handling

parent 5dbfe76b
No related branches found
No related tags found
No related merge requests found
Pipeline #12786 passed
......@@ -24,6 +24,8 @@ test:
stage: test
needs:
- build
before_script:
- apt-get update && apt-get -y install graphviz
script:
- "./gradlew test"
artifacts:
......
site_name: Motion Grammar
site_name: Motion Grammar JastAdd Implementation Example
repo_url: https://git-st.inf.tu-dresden.de/jastadd/motion-grammar-example
site_dir: ../public
......
......@@ -19,6 +19,7 @@ public class Main {
World world = World.initialWorld(new Random(1));
WorldParser parser = new WorldParser(world);
parser.setDebugDiagramDir(AST_DIAGRAM_DIR);
try {
Files.walk(AST_DIAGRAM_DIR)
......
......@@ -7,18 +7,22 @@ import de.tudresden.inf.st.mg.jastadd.model.Token;
import de.tudresden.inf.st.mg.jastadd.model.TokenType;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import static de.tudresden.inf.st.mg.Main.AST_DIAGRAM_DIR;
public abstract class MotionGrammarParser {
protected final Map<String, ASTNode<?>> context_ = new HashMap<>();
protected ASTNode<T> rootContainer_;
private int timeStep;
private int timeStep_;
protected Path astDiagramDir_;
public void setDebugDiagramDir(Path p) {
astDiagramDir_ = p;
}
/**
* Prints the AST and all context models into PlantUML diagrams. Each time this method is called, a counter incremented.
......@@ -27,6 +31,11 @@ public abstract class MotionGrammarParser {
* @param highlightNode a node that is highlighted, to illustrate what happens in the current step; may be null
*/
protected void printAST(String step, ASTNode<?> highlightNode) {
if (astDiagramDir_ == null) {
return;
}
final String N_N = "4C78A6";
final String H_N = "DCE9F7";
final String N_T = "A78344";
......@@ -37,16 +46,16 @@ public abstract class MotionGrammarParser {
for (var contextEntry : context_.entrySet()) {
Dumper.read(contextEntry.getValue())
.setNameMethod(o -> o == null ? "null" : o.getClass().getSimpleName())
.dumpAsPNG(AST_DIAGRAM_DIR.resolve("Context-" + contextEntry.getKey() + "-" + String.format("%03d", timeStep) + "-" + step + ".png"));
.dumpAsPNG(astDiagramDir_.resolve("Context-" + contextEntry.getKey() + "-" + String.format("%03d", timeStep_) + "-" + step + ".png"));
}
// TODO remove this once the issue in relast2uml has been resolved
if (rootContainer_.getChild(0) != null) {
Dumper.read(rootContainer_.getChild(0)).setBackgroundColorMethod(n -> n == null ? "white" : (n == highlightNode ? (n instanceof Token ? H_T : H_N) : (n instanceof Token ? N_T : N_N)))
.setNameMethod(o -> o == null ? "null" : o.getClass().getSimpleName())
.customPreamble("\nskinparam object {\nBackgroundColor<<null>> white\nBorderColor<<null>> white\nStereotypeFontColor<<null>> white\n}\n")
.dumpAsPNG(AST_DIAGRAM_DIR.resolve("AST-" + String.format("%03d", timeStep) + "-" + step + ".png"));
.dumpAsPNG(astDiagramDir_.resolve("AST-" + String.format("%03d", timeStep_) + "-" + step + ".png"));
}
timeStep++;
timeStep_++;
} catch (IOException e) {
e.printStackTrace();
}
......
......@@ -21,12 +21,15 @@ public class ParserTest {
@BeforeAll
static void prepareOutputPath() throws IOException {
try {
Files.walk(AST_DIAGRAM_DIR)
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
} catch (IOException e) {
// do nothing
}
Files.createDirectories(AST_DIAGRAM_DIR);
}
@Test
......@@ -36,6 +39,7 @@ public class ParserTest {
World world = World.initialWorld(new Random(1));
WorldParser parser = new WorldParser(world);
parser.setDebugDiagramDir(AST_DIAGRAM_DIR);
var result = parser.parseT();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment