From be69889e7f4450de7458ea45ac206f97ab3c9c79 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Wed, 21 Feb 2024 22:23:31 +0100 Subject: [PATCH] tests: fix stdlib test https://github.com/plantuml/plantuml/pull/1692#issuecomment-1952831187 --- .gitignore | 2 +- src/net/sourceforge/plantuml/preproc/Stdlib.java | 12 +++++++++--- test/net/sourceforge/plantuml/tim/EaterTest.java | 3 +-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 73ddb5bb800..da13ed28858 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ out #vscode files -/bin +**/bin/ # Ant result file plantuml.jar diff --git a/src/net/sourceforge/plantuml/preproc/Stdlib.java b/src/net/sourceforge/plantuml/preproc/Stdlib.java index 2c4863e153b..3072500d00b 100644 --- a/src/net/sourceforge/plantuml/preproc/Stdlib.java +++ b/src/net/sourceforge/plantuml/preproc/Stdlib.java @@ -3,10 +3,13 @@ import static java.nio.charset.StandardCharsets.UTF_8; import java.awt.image.BufferedImage; +import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -317,9 +320,12 @@ private InputStream getDataImagePngBase64() throws IOException { return new BrotliInputStream(raw); } - private static InputStream getInternalInputStream(String fullname, String extension) { - final String res = "/stdlib/" + fullname + extension; - return Stdlib.class.getResourceAsStream(res); + private static InputStream getInternalInputStream(String fullname, String extension) throws FileNotFoundException { + final String path = "stdlib/" + fullname + extension; + InputStream result = Stdlib.class.getResourceAsStream("/" + path); + if (result == null) + result = new BufferedInputStream(new FileInputStream(path)); + return result; } public static void extractStdLib() throws IOException { diff --git a/test/net/sourceforge/plantuml/tim/EaterTest.java b/test/net/sourceforge/plantuml/tim/EaterTest.java index fc370e459ed..1a458ceaa32 100644 --- a/test/net/sourceforge/plantuml/tim/EaterTest.java +++ b/test/net/sourceforge/plantuml/tim/EaterTest.java @@ -32,8 +32,7 @@ class EaterTest { "'@startuml\n!$a=[1, 2, 3]\ntitle xx $a[2] yy\na -> a\n' , xx 3 yy", "'@startuml\ntitle\n!foreach $i in [1, 2, 3]\nxx $i yy\n!endfor\nendtitle\na -> a\n' , xx 2 yy", "'@startuml\ntitle\n!foreach $i in [\"a\", \"b\", \"c\"]\nxx $i yy\n!endfor\nendtitle\na -> a\n' , xx b yy", -// TODO: fix code to allow test to access on stdlib, the corresponding (not working) test is here: -// "'@startuml\nstdlib\n@enduml', archimate", + "'@startuml\nstdlib\n@enduml', archimate", }) void Test_EaterTest(String input, String expected) throws Exception { assertRenderExpectedOutput(input, expected);