1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.regexp.mozilla.js1_2;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22
23
24
25
26
27
28
29 @RunWith(BrowserRunner.class)
30 public class StringSplitTest extends WebDriverTestCase {
31
32
33
34
35
36 @Test
37 @Alerts("a,b,c,de,f")
38 public void test1() throws Exception {
39 test("'a b c de f'.split(/\\s/)");
40 }
41
42
43
44
45
46 @Test
47 @Alerts("a,b,c")
48 public void test2() throws Exception {
49 test("'a b c de f'.split(/\\s/,3)");
50 }
51
52
53
54
55
56 @Test
57 @Alerts("a b c de f")
58 public void test3() throws Exception {
59 test("'a b c de f'.split(/X/)");
60 }
61
62
63
64
65
66 @Test
67 @Alerts("dfe,iu , =+,--")
68 public void test4() throws Exception {
69 test("'dfe23iu 34 =+65--'.split(/\\d+/)");
70 }
71
72
73
74
75
76 @Test
77 @Alerts("dfe,iu , =+,--")
78 public void test5() throws Exception {
79 test("'dfe23iu 34 =+65--'.split(new RegExp('\\\\d+'))");
80 }
81
82
83
84
85
86 @Test
87 @Alerts(",,,")
88 public void test6() throws Exception {
89 test("'abc'.split(/[a-z]/)");
90 }
91
92
93
94
95
96 @Test
97 @Alerts(",,,")
98 public void test7() throws Exception {
99 test("'abc'.split(/[a-z]/)");
100 }
101
102
103
104
105
106 @Test
107 @Alerts(",,,")
108 public void test8() throws Exception {
109 test("'abc'.split(new RegExp('[a-z]'))");
110 }
111
112
113
114
115
116 @Test
117 @Alerts(",,,")
118 public void test9() throws Exception {
119 test("'abc'.split(new RegExp('[a-z]'))");
120 }
121
122 private void test(final String script) throws Exception {
123 final String html = "<html><head><script>\n"
124 + LOG_TITLE_FUNCTION
125 + " log(" + script + ");\n"
126 + "</script></head><body>\n"
127 + "</body></html>";
128 loadPageVerifyTitle2(html);
129 }
130 }