tizen beta release
[profile/ivi/webkit-efl.git] / LayoutTests / fast / js / script-tests / regexp-in-and-foreach-handling.js
1 description("Test for bug 31689: RegExp#exec's returned Array-like object behaves differently from regular Arrays");
2
3 var tests = [
4     [ /(a)(_)?.+(c)(_)?.+(e)(_)?.+/, 'abcdef', '["abcdef", "a", undefined, "c", undefined, "e", undefined]' ],
5     [ /(a)(_)?/, 'abcdef', '["a", "a", undefined]' ],
6     [ /(_)?.+(a)/, 'xabcdef', '["xa", undefined, "a"]' ],
7     [ /(_)?.+(a)(_)?/, 'xabcdef', '["xa", undefined, "a", undefined]' ],
8 ];
9
10 function testRegExpMatchesArray(i)
11 {
12     return tests[i][0].exec(tests[i][1]);
13 }
14
15 function testInOperator(i)
16 {
17     var re = tests[i][0],
18         str = tests[i][1],
19         inArray = [],
20         matches = re.exec(str);
21
22     for (var j = 0; j < matches.length; j++) {
23         if (j in matches) {
24             inArray.push(matches[j]);
25         }
26     }
27     return inArray;
28 }
29
30 function testForEachFunction(i) 
31 {
32     var re = tests[i][0],
33         str = tests[i][1],
34         inArray = [],
35         matches = re.exec(str);
36
37     matches.forEach(function(m) {
38         inArray.push(m);
39     });
40     return inArray;
41
42 }
43
44 for (var i in tests) {
45     shouldBe('testRegExpMatchesArray(' + i + ')', tests[i][2]);
46     shouldBe('testInOperator(' + i + ')', tests[i][2]);
47     shouldBe('testForEachFunction(' + i + ')', tests[i][2]);
48 }
49