|
@@ -0,0 +1,75 @@
|
|
1
|
+package org.openzen.zenscript.scriptingexample.tests.actual_test.file_names;
|
|
2
|
+
|
|
3
|
+import org.junit.jupiter.api.*;
|
|
4
|
+import org.junit.jupiter.params.*;
|
|
5
|
+import org.junit.jupiter.params.provider.*;
|
|
6
|
+import org.openzen.zenscript.scriptingexample.tests.helpers.*;
|
|
7
|
+
|
|
8
|
+import java.io.*;
|
|
9
|
+
|
|
10
|
+public class FileNamesAndSpecialCharacters extends ZenCodeTest {
|
|
11
|
+
|
|
12
|
+ /**
|
|
13
|
+ * All the characters that we test.
|
|
14
|
+ */
|
|
15
|
+ public static char[] specialCharsToTest() {
|
|
16
|
+ return new char[]{'.', '1', '%', '$', '_', '!', '/', '\\', '\0', '\1', ' ', ';', ':', '-', '|', '[', ']'};
|
|
17
|
+ }
|
|
18
|
+
|
|
19
|
+ /**
|
|
20
|
+ * We disable the debug mode here because some of the filenames are invalid filenames in Windows/Unix.
|
|
21
|
+ * Since debug mode would try to write them out we disable it here.
|
|
22
|
+ */
|
|
23
|
+ @BeforeEach
|
|
24
|
+ public void disableDebug() {
|
|
25
|
+ engine.debug = false;
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ @ParameterizedTest(name = "[{index}] Checking special Character '{0}'")
|
|
29
|
+ @MethodSource("specialCharsToTest")
|
|
30
|
+ public void TestThatFilenameCanContainCharacter(char characterToTest) {
|
|
31
|
+
|
|
32
|
+ ScriptBuilder.create()
|
|
33
|
+ .startNewScript(String.format("t%1$se%1$ss%1$st.zs", characterToTest))
|
|
34
|
+ .add("println('Hello World');")
|
|
35
|
+ .execute(this);
|
|
36
|
+
|
|
37
|
+ logger.assertNoWarnings();
|
|
38
|
+ logger.assertNoErrors();
|
|
39
|
+ logger.assertPrintOutputSize(1);
|
|
40
|
+ logger.assertPrintOutput(0, "Hello World");
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ @ParameterizedTest
|
|
44
|
+ @MethodSource(value = "specialCharsToTest")
|
|
45
|
+ public void TestThatFilesWithSpecialCharacterFileNameAreAccessibleInsideOtherScripts(char characterToTest) {
|
|
46
|
+ ScriptBuilder.create()
|
|
47
|
+ .startNewScript(String.format("t%1$se%1$ss%1$st_1.zs", characterToTest))
|
|
48
|
+ .add("public function getTheString() as string => 'Hello World';")
|
|
49
|
+ .startNewScript(String.format("t%1$se%1$ss%1$st_2.zs", characterToTest))
|
|
50
|
+ .add("println(getTheString());")
|
|
51
|
+ .execute(this);
|
|
52
|
+
|
|
53
|
+ logger.assertNoWarnings();
|
|
54
|
+ logger.assertNoErrors();
|
|
55
|
+ logger.assertPrintOutputSize(1);
|
|
56
|
+ logger.assertPrintOutput(0, "Hello World");
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ @ParameterizedTest
|
|
60
|
+ @MethodSource(value = "specialCharsToTest")
|
|
61
|
+ public void TestThatFilesWithSpecialCharactersCanBePutInSubFolders(char characterToTest){
|
|
62
|
+ //noinspection SpellCheckingInspection
|
|
63
|
+ ScriptBuilder.create()
|
|
64
|
+ .startNewScript(String.format("some%2$sfolder%2$st%1$se%1$ss%1$st_1.zs", characterToTest, File.separatorChar))
|
|
65
|
+ .add("public function getTheString() as string => 'Hello World';")
|
|
66
|
+ .startNewScript(String.format("some%2$sfolder%2$st%1$se%1$ss%1$st_2.zs", characterToTest, File.separatorChar))
|
|
67
|
+ .add("println(getTheString());")
|
|
68
|
+ .execute(this);
|
|
69
|
+
|
|
70
|
+ logger.assertNoWarnings();
|
|
71
|
+ logger.assertNoErrors();
|
|
72
|
+ logger.assertPrintOutputSize(1);
|
|
73
|
+ logger.assertPrintOutput(0, "Hello World");
|
|
74
|
+ }
|
|
75
|
+}
|