michael@0: /* michael@0: * Tests from http://xregexp.com/tests/split.html michael@0: * michael@0: * Copyright (C) 2007 by Steven Levithan michael@0: * michael@0: * Distributed under the terms of the MIT license. michael@0: * michael@0: * Permission is hereby granted, free of charge, to any person obtaining a copy michael@0: * of this software and associated documentation files (the "Software"), to deal michael@0: * in the Software without restriction, including without limitation the rights michael@0: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell michael@0: * copies of the Software, and to permit persons to whom the Software is michael@0: * furnished to do so, subject to the following conditions: michael@0: michael@0: * The above copyright notice and this permission notice shall be included in michael@0: * all copies or substantial portions of the Software. michael@0: michael@0: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR michael@0: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, michael@0: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE michael@0: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER michael@0: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, michael@0: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN michael@0: * THE SOFTWARE. michael@0: */ michael@0: var BUGNUMBER = 614608; michael@0: var summary = "String.prototype.split with regexp separator"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var ecmaSampleRe = /<(\/)?([^<>]+)>/; michael@0: michael@0: var testCode = [ michael@0: ["''.split()", [""]], michael@0: ["''.split(/./)", [""]], michael@0: ["''.split(/.?/)", []], michael@0: ["''.split(/.??/)", []], michael@0: ["'ab'.split(/a*/)", ["", "b"]], michael@0: ["'ab'.split(/a*?/)", ["a", "b"]], michael@0: ["'ab'.split(/(?:ab)/)", ["", ""]], michael@0: ["'ab'.split(/(?:ab)*/)", ["", ""]], michael@0: ["'ab'.split(/(?:ab)*?/)", ["a", "b"]], michael@0: ["'test'.split('')", ["t", "e", "s", "t"]], michael@0: ["'test'.split()", ["test"]], michael@0: ["'111'.split(1)", ["", "", "", ""]], michael@0: ["'test'.split(/(?:)/, 2)", ["t", "e"]], michael@0: ["'test'.split(/(?:)/, -1)", ["t", "e", "s", "t"]], michael@0: ["'test'.split(/(?:)/, undefined)", ["t", "e", "s", "t"]], michael@0: ["'test'.split(/(?:)/, null)", []], michael@0: ["'test'.split(/(?:)/, NaN)", []], michael@0: ["'test'.split(/(?:)/, true)", ["t"]], michael@0: ["'test'.split(/(?:)/, '2')", ["t", "e"]], michael@0: ["'test'.split(/(?:)/, 'two')", []], michael@0: ["'a'.split(/-/)", ["a"]], michael@0: ["'a'.split(/-?/)", ["a"]], michael@0: ["'a'.split(/-??/)", ["a"]], michael@0: ["'a'.split(/a/)", ["", ""]], michael@0: ["'a'.split(/a?/)", ["", ""]], michael@0: ["'a'.split(/a??/)", ["a"]], michael@0: ["'ab'.split(/-/)", ["ab"]], michael@0: ["'ab'.split(/-?/)", ["a", "b"]], michael@0: ["'ab'.split(/-??/)", ["a", "b"]], michael@0: ["'a-b'.split(/-/)", ["a", "b"]], michael@0: ["'a-b'.split(/-?/)", ["a", "b"]], michael@0: ["'a-b'.split(/-??/)", ["a", "-", "b"]], michael@0: ["'a--b'.split(/-/)", ["a", "", "b"]], michael@0: ["'a--b'.split(/-?/)", ["a", "", "b"]], michael@0: ["'a--b'.split(/-??/)", ["a", "-", "-", "b"]], michael@0: ["''.split(/()()/)", []], michael@0: ["'.'.split(/()()/)", ["."]], michael@0: ["'.'.split(/(.?)(.?)/)", ["", ".", "", ""]], michael@0: ["'.'.split(/(.??)(.??)/)", ["."]], michael@0: ["'.'.split(/(.)?(.)?/)", ["", ".", undefined, ""]], michael@0: ["'Aboldandcoded'.split(ecmaSampleRe)", michael@0: ["A", undefined, "B", "bold", "/", "B", michael@0: "and", undefined, "CODE", "coded", "/", michael@0: "CODE", ""]], michael@0: ["'tesst'.split(/(s)*/)", ["t", undefined, "e", "s", "t"]], michael@0: ["'tesst'.split(/(s)*?/)", ["t", undefined, "e", undefined, "s", michael@0: undefined, "s", undefined, "t"]], michael@0: ["'tesst'.split(/(s*)/)", ["t", "", "e", "ss", "t"]], michael@0: ["'tesst'.split(/(s*?)/)", ["t", "", "e", "", "s", "", "s", "", "t"]], michael@0: ["'tesst'.split(/(?:s)*/)", ["t", "e", "t"]], michael@0: ["'tesst'.split(/(?=s+)/)", ["te", "s", "st"]], michael@0: ["'test'.split('t')", ["", "es", ""]], michael@0: ["'test'.split('es')", ["t", "t"]], michael@0: ["'test'.split(/t/)", ["", "es", ""]], michael@0: ["'test'.split(/es/)", ["t", "t"]], michael@0: ["'test'.split(/(t)/)", ["", "t", "es", "t", ""]], michael@0: ["'test'.split(/(es)/)", ["t", "es", "t"]], michael@0: ["'test'.split(/(t)(e)(s)(t)/)", ["", "t", "e", "s", "t", ""]], michael@0: ["'.'.split(/(((.((.??)))))/)", ["", ".", ".", ".", "", "", ""]], michael@0: ["'.'.split(/(((((.??)))))/)", ["."]] michael@0: ]; michael@0: michael@0: function testSplit() { michael@0: for (var i = 0; i < testCode.length; i++) { michael@0: var actual = eval(testCode[i][0]); michael@0: var expected = testCode[i][1]; michael@0: michael@0: assertEq(actual.length, expected.length); michael@0: michael@0: for(var j=0; j