Skip to content

Commit 80e51b4

Browse files
committed
fix tests
Signed-off-by: Stefan Niederhauser <[email protected]>
1 parent 6dd3020 commit 80e51b4

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

graphviz-java/src/main/java/guru/nidi/graphviz/engine/AbstractJsGraphvizEngine.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ public String execute(String src, Options options) {
3535
protected abstract String jsExecute(String jsCall);
3636

3737
protected String jsVizExec(String src, Options options) {
38-
final Entry<String, Options> srcAndOptions = preprocessCode(src, options);
38+
if (src.startsWith("totalMemory") || src.startsWith("render")) {
39+
return src;
40+
}
3941
final String memory = options.totalMemory == null ? "" : "totalMemory=" + options.totalMemory + ";";
40-
final String render = "render('" + srcAndOptions.getKey() + "'," + srcAndOptions.getValue().toJson(false) + ");";
41-
return src.startsWith("render") ? src : (memory + render);
42+
final Entry<String, Options> srcAndOpts = preprocessCode(src, options);
43+
final String render = "render('" + srcAndOpts.getKey() + "'," + srcAndOpts.getValue().toJson(false) + ");";
44+
return memory + render;
4245
}
4346

4447
protected Entry<String, Options> preprocessCode(String src, Options options) {
@@ -71,7 +74,10 @@ protected String jsInitEnv() {
7174
return "var viz; var totalMemory = 16777216;"
7275
+ "function initViz(force){"
7376
+ " if (force || !viz || viz.totalMemory !== totalMemory){"
74-
+ " viz = new Viz({Module: function(){ return Viz.Module({TOTAL_MEMORY: totalMemory}); }, render: Viz.render});"
77+
+ " viz = new Viz({"
78+
+ " Module: function(){ return Viz.Module({TOTAL_MEMORY: totalMemory}); },"
79+
+ " render: Viz.render"
80+
+ " });"
7581
+ " viz.totalMemory = totalMemory;"
7682
+ " }"
7783
+ " return viz;"

graphviz-java/src/main/java/guru/nidi/graphviz/engine/GraphvizV8Engine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ private static class Env implements AutoCloseable {
8585
v8.registerJavaMethod((receiver, parameters) -> {
8686
final String rawMsg = parameters.getString(0);
8787
final String msg = rawMsg.matches("TypeError: Module\\..*? is not a function")
88-
? "Got Error: '" + rawMsg + "'. This is probably an out of memory error. Try using the totalMemory method."
88+
? "Got Error: '" + rawMsg + "'. This is probably an out of memory error."
89+
+ " Try using the totalMemory method."
8990
: rawMsg;
9091
resultHandler.setError(msg);
9192
}, "error");

graphviz-java/src/test/java/guru/nidi/graphviz/engine/AbstractGraphvizEngineTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void vizExecWithOptions() {
4747

4848
final String vizResult = engineUnderTest.jsVizExec("digraph{ a -> b}", options);
4949

50-
assertThat(vizResult, is("render('digraph{ a -> b}',{format:'svg',engine:'dot',totalMemory:'320000',"
50+
assertThat(vizResult, is("totalMemory=320000;render('digraph{ a -> b}',{format:'svg',engine:'dot',totalMemory:'320000',"
5151
+ "yInvert:true,basedir:'" + new File(".").getAbsolutePath() + "',images:[]});"));
5252
}
5353

graphviz-java/src/test/java/guru/nidi/graphviz/engine/GraphvizTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void executeWithTotalMemory() {
6565
final Graph graph = graph().with(node("a").link("b"));
6666
final String result = Graphviz.fromGraph(graph).totalMemory(32000).render(Format.SVG).toString();
6767

68-
assertThat(result, is("render('graph { graph [\"dpi\"=\"96\"] \"a\" -- \"b\" }',"
68+
assertThat(result, is("totalMemory=32000;render('graph { graph [\"dpi\"=\"96\"] \"a\" -- \"b\" }',"
6969
+ "{format:'svg',engine:'dot',totalMemory:'32000',basedir:'" + new File(".").getAbsolutePath() + "',images:[]});"));
7070
}
7171

0 commit comments

Comments
 (0)