| OLD | NEW |
| (Empty) |
| 1 description( | |
| 2 'This test checks for a regression against <a href="https://bugs.webkit.org/show
_bug.cgi?id=68348">String#split is buggy</a>.' | |
| 3 ); | |
| 4 | |
| 5 // The following JavaScript code (including "".split tests) is copyright by Stev
en Levithan, | |
| 6 // and released under the MIT License | |
| 7 var testCode = [ | |
| 8 ["''.split()", [""]], | |
| 9 ["''.split(/./)", [""]], | |
| 10 ["''.split(/.?/)", []], | |
| 11 ["''.split(/.??/)", []], | |
| 12 ["'ab'.split(/a*/)", ["", "b"]], | |
| 13 ["'ab'.split(/a*?/)", ["a", "b"]], | |
| 14 ["'ab'.split(/(?:ab)/)", ["", ""]], | |
| 15 ["'ab'.split(/(?:ab)*/)", ["", ""]], | |
| 16 ["'ab'.split(/(?:ab)*?/)", ["a", "b"]], | |
| 17 ["'test'.split('')", ["t", "e", "s", "t"]], | |
| 18 ["'test'.split()", ["test"]], | |
| 19 ["'111'.split(1)", ["", "", "", ""]], | |
| 20 ["'test'.split(/(?:)/, 2)", ["t", "e"]], | |
| 21 ["'test'.split(/(?:)/, -1)", ["t", "e", "s", "t"]], | |
| 22 ["'test'.split(/(?:)/, undefined)", ["t", "e", "s", "t"]], | |
| 23 ["'test'.split(/(?:)/, null)", []], | |
| 24 ["'test'.split(/(?:)/, NaN)", []], | |
| 25 ["'test'.split(/(?:)/, true)", ["t"]], | |
| 26 ["'test'.split(/(?:)/, '2')", ["t", "e"]], | |
| 27 ["'test'.split(/(?:)/, 'two')", []], | |
| 28 ["'a'.split(/-/)", ["a"]], | |
| 29 ["'a'.split(/-?/)", ["a"]], | |
| 30 ["'a'.split(/-??/)", ["a"]], | |
| 31 ["'a'.split(/a/)", ["", ""]], | |
| 32 ["'a'.split(/a?/)", ["", ""]], | |
| 33 ["'a'.split(/a??/)", ["a"]], | |
| 34 ["'ab'.split(/-/)", ["ab"]], | |
| 35 ["'ab'.split(/-?/)", ["a", "b"]], | |
| 36 ["'ab'.split(/-??/)", ["a", "b"]], | |
| 37 ["'a-b'.split(/-/)", ["a", "b"]], | |
| 38 ["'a-b'.split(/-?/)", ["a", "b"]], | |
| 39 ["'a-b'.split(/-??/)", ["a", "-", "b"]], | |
| 40 ["'a--b'.split(/-/)", ["a", "", "b"]], | |
| 41 ["'a--b'.split(/-?/)", ["a", "", "b"]], | |
| 42 ["'a--b'.split(/-??/)", ["a", "-", "-", "b"]], | |
| 43 ["''.split(/()()/)", []], | |
| 44 ["'.'.split(/()()/)", ["."]], | |
| 45 ["'.'.split(/(.?)(.?)/)", ["", ".", "", ""]], | |
| 46 ["'.'.split(/(.??)(.??)/)", ["."]], | |
| 47 ["'.'.split(/(.)?(.)?/)", ["", ".", undefined, ""]], | |
| 48 ["'A<B>bold</B>and<CODE>coded</CODE>'.split(ecmaSampleRe)", ["A", undefined,
"B", "bold", "/", "B", "and", undefined, "CODE", "coded", "/", "CODE", ""]], | |
| 49 ["'tesst'.split(/(s)*/)", ["t", undefined, "e", "s", "t"]], | |
| 50 ["'tesst'.split(/(s)*?/)", ["t", undefined, "e", undefined, "s", undefined,
"s", undefined, "t"]], | |
| 51 ["'tesst'.split(/(s*)/)", ["t", "", "e", "ss", "t"]], | |
| 52 ["'tesst'.split(/(s*?)/)", ["t", "", "e", "", "s", "", "s", "", "t"]], | |
| 53 ["'tesst'.split(/(?:s)*/)", ["t", "e", "t"]], | |
| 54 ["'tesst'.split(/(?=s+)/)", ["te", "s", "st"]], | |
| 55 ["'test'.split('t')", ["", "es", ""]], | |
| 56 ["'test'.split('es')", ["t", "t"]], | |
| 57 ["'test'.split(/t/)", ["", "es", ""]], | |
| 58 ["'test'.split(/es/)", ["t", "t"]], | |
| 59 ["'test'.split(/(t)/)", ["", "t", "es", "t", ""]], | |
| 60 ["'test'.split(/(es)/)", ["t", "es", "t"]], | |
| 61 ["'test'.split(/(t)(e)(s)(t)/)",["", "t", "e", "s", "t", ""]], | |
| 62 ["'.'.split(/(((.((.??)))))/)", ["", ".", ".", ".", "", "", ""]], | |
| 63 ["'.'.split(/(((((.??)))))/)", ["."]] | |
| 64 ]; | |
| 65 var ecmaSampleRe = /<(\/)?([^<>]+)>/; | |
| 66 | |
| 67 for (var i in testCode) | |
| 68 shouldBe(testCode[i][0], 'testCode[i][1]'); | |
| 69 | |
| 70 // Check that split works with object separators, and that steps 8 & 9 are perfo
rmed in the correct order. | |
| 71 var separatorToStringCalled = "ToString not called on the separator"; | |
| 72 shouldBe("'hello'.split({toString:function(){return 'e';}})", '["h", "llo"]'); | |
| 73 shouldBe("var a = 'hello'.split({toString:function(){separatorToStringCalled='OK
AY';return 'e';}},0); a.push(separatorToStringCalled); a", '["OKAY"]'); | |
| OLD | NEW |