Skip to content

Commit

Permalink
Keep root commands in model output.
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcsmith-net committed Aug 22, 2024
1 parent 767afcb commit bca8b03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,23 @@ private void doWrite(Appendable target) throws IOException {
var root = model.root();
if (root.isSynthetic()) {
// sub graph
writeCommands(target, root);
writeChildren(target, root, 0);
writeConnections(target, root, 0);
} else {
// full graph
writeCommands(target, root);
writeComponent(target, root.id(), root, 0);
}
}

private void writeCommands(Appendable sb, GraphElement.Root root)
throws IOException {
for (GraphElement.Command cmd : root.commands()) {
sb.append(cmd.command()).append('\n');
}
}

private void writeComponent(Appendable sb,
String id,
GraphElement.Component cmp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public void testParseGraphWithCommands() throws ParseException {
libraries {
pkg:maven/org.praxislive/praxiscore-api
}
# comment
""" + GRAPH_SCRIPT;
GraphModel model = GraphModel.parse(PARENT_CONTEXT, script);
if (VERBOSE) {
Expand All @@ -114,6 +113,8 @@ public void testParseGraphWithCommands() throws ParseException {
assertEquals(Token.Type.BRACED, command.get(1).getType());
assertEquals("pkg:maven/org.praxislive/praxiscore-api",
command.get(1).getText().strip());
String out = model.writeToString();
assertEquals(script, out);
}

@Test
Expand Down Expand Up @@ -187,6 +188,8 @@ public void testParseSubGraphWithCommands() throws ParseException {
assertEquals(Token.Type.PLAIN, command.get(0).getType());
assertEquals("shared-code", command.get(0).getText());
assertEquals(Token.Type.BRACED, command.get(1).getType());
String out = model.writeToString();
assertEquals(script, out);
}

@Test
Expand Down

0 comments on commit bca8b03

Please sign in to comment.