tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / js / kde / script-tests / RegExp.js
1 shouldBe("(new RegExp()).source", "''");
2 shouldBe("Boolean(new RegExp())", "true");
3 shouldBeTrue("isNaN(Number(new RegExp()))");
4
5 // RegExp constructor called as a function
6 shouldBe("RegExp(/x/).source", "'x'");
7 //shouldBe("RegExp(/x/, 'g').source", "'/x/'"); // can't supply flags when constructing one RegExp from another, says mozilla
8 shouldBe("RegExp('x', 'g').global", "true");
9 shouldBe("RegExp('x').source", "'x'");
10
11 // RegExp constructor
12 shouldBe("new RegExp('x').source", "'x'");
13
14 var ri = /a/i;
15 var rm = /a/m;
16 var rg = /a/g;
17
18 shouldBeFalse("(/a/).global");
19 shouldBe("typeof (/a/).global", "'boolean'");
20 shouldBeTrue("rg.global");
21 shouldBeFalse("(/a/).ignoreCase");
22 shouldBeTrue("ri.ignoreCase");
23 shouldBeFalse("(/a/).multiline");
24 shouldBeTrue("rm.multiline");
25 shouldBe("rg.toString()", "'/a/g'");
26 shouldBe("ri.toString()", "'/a/i'");
27 shouldBe("rm.toString()", "'/a/m'");
28
29 // check properety attributes
30 rg.global = false;
31 shouldBeTrue("rg.global");
32 ri.ignoreCase = false;
33 shouldBeTrue("ri.ignoreCase");
34 rm.multiline = false;
35 shouldBeTrue("rm.multiline");
36
37 shouldBe("Boolean(/a/.test)", "true");
38 shouldBe("/(b)c/.exec('abcd').toString()", "\"bc,b\"");
39 shouldBe("/(b)c/.exec('abcd').length", "2");
40 shouldBe("/(b)c/.exec('abcd').index", "1");
41 shouldBe("/(b)c/.exec('abcd').input", "'abcd'");
42
43 var rs = /foo/;
44 rs.source = "bar";
45 shouldBe("rs.source", "'foo'");
46
47 shouldBe("var r = new RegExp(/x/); r.global=true; r.lastIndex = -1; typeof r.test('a')", "'boolean'");
48
49 shouldBe("'abcdefghi'.match(/(abc)def(ghi)/).toString()","'abcdefghi,abc,ghi'");
50 shouldBe("/(abc)def(ghi)/.exec('abcdefghi').toString()","'abcdefghi,abc,ghi'");
51 shouldBe("RegExp.$1","'abc'");
52 shouldBe("RegExp.$2","'ghi'");
53 shouldBe("RegExp.$3","''");
54
55 shouldBe("'abcdefghi'.match(/(a(b(c(d(e)f)g)h)i)/).toString()", "'abcdefghi,abcdefghi,bcdefgh,cdefg,def,e'");
56 shouldBe("RegExp.$1","'abcdefghi'");
57 shouldBe("RegExp.$2","'bcdefgh'");
58 shouldBe("RegExp.$3","'cdefg'");
59 shouldBe("RegExp.$4","'def'");
60 shouldBe("RegExp.$5","'e'");
61 shouldBe("RegExp.$6","''");
62
63 shouldBe("'(100px 200px 150px 15px)'.match(/\\((\\d+)(px)* (\\d+)(px)* (\\d+)(px)* (\\d+)(px)*\\)/).toString()","'(100px 200px 150px 15px),100,px,200,px,150,px,15,px'");
64 shouldBe("RegExp.$1","'100'");
65 shouldBe("RegExp.$3","'200'");
66 shouldBe("RegExp.$5","'150'");
67 shouldBe("RegExp.$7","'15'");
68 shouldBe("''.match(/\((\\d+)(px)* (\\d+)(px)* (\\d+)(px)* (\\d+)(px)*\)/)","null");
69 // After a failed match, cached results on the RegExp object are unchanged.
70 shouldBe("RegExp.$1","'100'");
71 shouldBe("RegExp.$3","'200'");
72 shouldBe("RegExp.$5","'150'");
73 shouldBe("RegExp.$7","'15'");
74
75 var invalidChars = /[^@\.\w]/g; // #47092
76 shouldBe("'faure@kde.org'.match(invalidChars) == null", "true");
77 shouldBe("'faure-kde@kde.org'.match(invalidChars) == null", "false");
78
79 shouldBe("'test1test2'.replace('test','X')","'X1test2'");
80 shouldBe("'test1test2'.replace(/\\d/,'X')","'testXtest2'");
81 shouldBe("'1test2test3'.replace(/\\d/,'')","'test2test3'");
82 shouldBe("'test1test2'.replace(/test/g,'X')","'X1X2'");
83 shouldBe("'1test2test3'.replace(/\\d/g,'')","'testtest'");
84 shouldBe("'1test2test3'.replace(/x/g,'')","'1test2test3'");
85 shouldBe("'test1test2'.replace(/(te)(st)/g,'$2$1')","'stte1stte2'");
86 shouldBe("'foo+bar'.replace(/\\+/g,'%2B')", "'foo%2Bbar'");
87 var caught = false; try { new RegExp("+"); } catch (e) { caught = true; }
88 shouldBeTrue("caught"); // #40435
89 shouldBe("'foo'.replace(/z?/g,'x')", "'xfxoxox'");
90 shouldBe("'test test'.replace(/\\s*/g,'')","'testtest'"); // #50985
91 shouldBe("'abc$%@'.replace(/[^0-9a-z]*/gi,'')","'abc'"); // #50848
92 shouldBe("'ab'.replace(/[^\\d\\.]*/gi,'')","''"); // #75292
93 shouldBe("'1ab'.replace(/[^\\d\\.]*/gi,'')","'1'"); // #75292
94
95 shouldBe("'1test2test3blah'.split(/test/).toString()","'1,2,3blah'");
96 var reg = /(\d\d )/g;
97 var str = new String('98 76 blah');
98 shouldBe("reg.exec(str).toString()","'98 ,98 '");
99 shouldBe("reg.lastIndex","3");
100 shouldBe("RegExp.$1","'98 '");
101 shouldBe("RegExp.$2","''");
102
103 shouldBe("reg.exec(str).toString()","'76 ,76 '");
104 shouldBe("reg.lastIndex","6");
105 shouldBe("RegExp.$1","'76 '");
106 shouldBe("RegExp.$2","''");
107
108 shouldBe("reg.exec(str)","null");
109 shouldBe("reg.lastIndex","0");
110
111 // http://www.devguru.com/Technologies/ecmascript/quickref/regexp_lastindex.html
112 // Looks IE-only though
113 //shouldBe( "var re=/ships*\s/; re.exec('the hardships of traveling'); re.lastIndex", "14" );
114 //shouldBe( "var re=/ships*\s/; str='the hardships of traveling'; re.exec(str); re.exec(str); re.lastIndex", "0" );
115
116 // http://devedge.netscape.com/library/manuals/2000/javascript/1.5/guide/regexp.html
117 shouldBe( "myRe=/d(b+)d/g; myArray = myRe.exec('cdbbdbsbz'); myRe.lastIndex", "5" );
118
119 reg = /^u/i;
120 shouldBeTrue("reg.ignoreCase == true");
121 shouldBeTrue("reg.global === false");
122 shouldBeTrue("reg.multiline === false");
123 shouldBeTrue("reg.test('UGO')");
124
125 // regexp are writable ?
126 shouldBe("reg.x = 1; reg.x", "1");
127 // shared data ?
128 shouldBe("var r2 = reg; r2.x = 2; reg.x", "2");
129
130 var str = new String("For more information, see Chapter 3.4.5.1");
131 re = /(chapter \d+(\.\d)*)/i;
132 // This returns the array containing Chapter 3.4.5.1,Chapter 3.4.5.1,.1
133 // 'Chapter 3.4.5.1' is the first match and the first value remembered from (Chapter \d+(\.\d)*).
134 // '.1' is the second value remembered from (\.\d)
135 shouldBe("str.match(re).toString()","'Chapter 3.4.5.1,Chapter 3.4.5.1,.1'");
136
137 str = "abcDdcba";
138 // The returned array contains D, d.
139 shouldBe("str.match(/d/gi).toString()","'D,d'");
140
141 // unicode escape sequence
142 shouldBe("/\\u0061/.source", "'\\\\u0061'");
143 shouldBe("'abc'.match(/\\u0062/).toString()", "'b'");
144
145 shouldBe("Object.prototype.toString.apply(RegExp.prototype)",
146          "'[object RegExp]'");
147
148 // not sure what this should return. most importantly
149 // it doesn't throw an exception
150 shouldBe("typeof RegExp.prototype.toString()", "'string'");
151
152 // Empty regular expressions have string representation /(?:)/
153 shouldBe("new RegExp().toString()", "'/(?:)/'");
154 shouldBe("(new RegExp('(?:)')).source", "'(?:)'");
155 shouldBe("/(?:)/.toString()", "'/(?:)/'");
156 shouldBe("/(?:)/.source", "'(?:)'");
157
158 debug("Done.");