-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathTestIssue151RegEx.java
94 lines (82 loc) · 5.22 KB
/
TestIssue151RegEx.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package delight.nashornsandbox;
import javax.script.ScriptException;
import org.junit.Test;
import delight.nashornsandbox.exceptions.ScriptCPUAbuseException;
public class TestIssue151RegEx {
@Test
public void test_example_1() throws ScriptCPUAbuseException, ScriptException {
NashornSandbox sandbox = NashornSandboxes.create();
String script = "function test(data) {\n" +
" if (data.get(\"propertyA\") == \"a special value 1\" || data.get(\"propertyA\") == \"a special value 2\") {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 3\" && (data.get(\"propertyC\") == \"a special value 1\" || data.get(\"propertyJ\") == \"a special value 1\" || data.get(\"propertyV\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"4\" && (data.get(\"propertyD\") == \"a special value 1\" || data.get(\"propertyV\") == \"a special value 1\" || data.get(\"propertyW\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 2\" && (data.get(\"propertyE\") == \"a special value 1\" || data.get(\"propertyF\") == \"a special value 1\" || data.get(\"propertyL\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 3\" && (data.get(\"propertyE\") == \"a special value 1\" || data.get(\"propertyF\") == \"a special value 1\" || data.get(\"propertyL\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 3\" && (data.get(\"propertyM\") == \"a special value 1\" || data.get(\"propertyY\") == \"a special value 1\" || data.get(\"propertyH\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 3\" && (data.get(\"propertyM\") == \"a special value 1\" || data.get(\"propertyY\") == \"a special value 1\" || data.get(\"propertyH\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 3\" && (data.get(\"propertyM\") == \"a special value 1\" || data.get(\"propertyY\") == \"a special value 1\" || data.get(\"propertyH\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 3\" && (data.get(\"propertyM\") == \"a special value 1\" || data.get(\"propertyY\") == \"a special value 1\" || data.get(\"propertyH\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 3\" && (data.get(\"propertyM\") == \"a special value 1\" || data.get(\"propertyY\") == \"a special value 1\" || data.get(\"propertyH\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 3\" && (data.get(\"propertyM\") == \"a special value 1\" || data.get(\"propertyY\") == \"a special value 1\" || data.get(\"propertyH\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else if (data.get(\"propertyB\") == \"a special value 3\" && (data.get(\"propertyM\") == \"a special value 1\" || data.get(\"propertyY\") == \"a special value 1\" || data.get(\"propertyH\") == \"a special value 1\")) {\n"
+
" return \"a special value 1\";\n" +
" } else {\n" +
" return \"0\"\n" +
" };\n" +
"}\n";
sandbox.eval(script);
}
@Test
public void test_example_2() throws ScriptCPUAbuseException, ScriptException {
NashornSandbox sandbox = NashornSandboxes.create();
SandboxScriptContext context = sandbox.createScriptContext();
String jsonString = "var variable = {"
+ "0:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "1:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "2:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "3:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "4:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "5:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "6:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "7:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "8:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "9:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "10:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "11:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "12:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "13:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "14:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "15:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "16:{ status: 'ABCDEF12345', statusName: 'ABCDEF12345' },"
+ "17:{ status: 'ABCDEF', statusName: 'ABCDEF' },"
+ "18:{ status: 'ABCDEF', statusName: 'ABCDEF' },"
+ "19:{ status: 'ABCDEF', statusName: 'ABCDE' }"
+ "};"
+ "//This is a Comment"
+ "return msg;";
sandbox.eval(jsonString, context);
}
}