js/src/tests/ecma_5/String/split-xregexp.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Tests from http://xregexp.com/tests/split.html
michael@0 3 *
michael@0 4 * Copyright (C) 2007 by Steven Levithan <stevenlevithan.com>
michael@0 5 *
michael@0 6 * Distributed under the terms of the MIT license.
michael@0 7 *
michael@0 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
michael@0 9 * of this software and associated documentation files (the "Software"), to deal
michael@0 10 * in the Software without restriction, including without limitation the rights
michael@0 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
michael@0 12 * copies of the Software, and to permit persons to whom the Software is
michael@0 13 * furnished to do so, subject to the following conditions:
michael@0 14
michael@0 15 * The above copyright notice and this permission notice shall be included in
michael@0 16 * all copies or substantial portions of the Software.
michael@0 17
michael@0 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
michael@0 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
michael@0 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
michael@0 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
michael@0 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
michael@0 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
michael@0 24 * THE SOFTWARE.
michael@0 25 */
michael@0 26 var BUGNUMBER = 614608;
michael@0 27 var summary = "String.prototype.split with regexp separator";
michael@0 28
michael@0 29 print(BUGNUMBER + ": " + summary);
michael@0 30
michael@0 31 /**************
michael@0 32 * BEGIN TEST *
michael@0 33 **************/
michael@0 34
michael@0 35 var ecmaSampleRe = /<(\/)?([^<>]+)>/;
michael@0 36
michael@0 37 var testCode = [
michael@0 38 ["''.split()", [""]],
michael@0 39 ["''.split(/./)", [""]],
michael@0 40 ["''.split(/.?/)", []],
michael@0 41 ["''.split(/.??/)", []],
michael@0 42 ["'ab'.split(/a*/)", ["", "b"]],
michael@0 43 ["'ab'.split(/a*?/)", ["a", "b"]],
michael@0 44 ["'ab'.split(/(?:ab)/)", ["", ""]],
michael@0 45 ["'ab'.split(/(?:ab)*/)", ["", ""]],
michael@0 46 ["'ab'.split(/(?:ab)*?/)", ["a", "b"]],
michael@0 47 ["'test'.split('')", ["t", "e", "s", "t"]],
michael@0 48 ["'test'.split()", ["test"]],
michael@0 49 ["'111'.split(1)", ["", "", "", ""]],
michael@0 50 ["'test'.split(/(?:)/, 2)", ["t", "e"]],
michael@0 51 ["'test'.split(/(?:)/, -1)", ["t", "e", "s", "t"]],
michael@0 52 ["'test'.split(/(?:)/, undefined)", ["t", "e", "s", "t"]],
michael@0 53 ["'test'.split(/(?:)/, null)", []],
michael@0 54 ["'test'.split(/(?:)/, NaN)", []],
michael@0 55 ["'test'.split(/(?:)/, true)", ["t"]],
michael@0 56 ["'test'.split(/(?:)/, '2')", ["t", "e"]],
michael@0 57 ["'test'.split(/(?:)/, 'two')", []],
michael@0 58 ["'a'.split(/-/)", ["a"]],
michael@0 59 ["'a'.split(/-?/)", ["a"]],
michael@0 60 ["'a'.split(/-??/)", ["a"]],
michael@0 61 ["'a'.split(/a/)", ["", ""]],
michael@0 62 ["'a'.split(/a?/)", ["", ""]],
michael@0 63 ["'a'.split(/a??/)", ["a"]],
michael@0 64 ["'ab'.split(/-/)", ["ab"]],
michael@0 65 ["'ab'.split(/-?/)", ["a", "b"]],
michael@0 66 ["'ab'.split(/-??/)", ["a", "b"]],
michael@0 67 ["'a-b'.split(/-/)", ["a", "b"]],
michael@0 68 ["'a-b'.split(/-?/)", ["a", "b"]],
michael@0 69 ["'a-b'.split(/-??/)", ["a", "-", "b"]],
michael@0 70 ["'a--b'.split(/-/)", ["a", "", "b"]],
michael@0 71 ["'a--b'.split(/-?/)", ["a", "", "b"]],
michael@0 72 ["'a--b'.split(/-??/)", ["a", "-", "-", "b"]],
michael@0 73 ["''.split(/()()/)", []],
michael@0 74 ["'.'.split(/()()/)", ["."]],
michael@0 75 ["'.'.split(/(.?)(.?)/)", ["", ".", "", ""]],
michael@0 76 ["'.'.split(/(.??)(.??)/)", ["."]],
michael@0 77 ["'.'.split(/(.)?(.)?/)", ["", ".", undefined, ""]],
michael@0 78 ["'A<B>bold</B>and<CODE>coded</CODE>'.split(ecmaSampleRe)",
michael@0 79 ["A", undefined, "B", "bold", "/", "B",
michael@0 80 "and", undefined, "CODE", "coded", "/",
michael@0 81 "CODE", ""]],
michael@0 82 ["'tesst'.split(/(s)*/)", ["t", undefined, "e", "s", "t"]],
michael@0 83 ["'tesst'.split(/(s)*?/)", ["t", undefined, "e", undefined, "s",
michael@0 84 undefined, "s", undefined, "t"]],
michael@0 85 ["'tesst'.split(/(s*)/)", ["t", "", "e", "ss", "t"]],
michael@0 86 ["'tesst'.split(/(s*?)/)", ["t", "", "e", "", "s", "", "s", "", "t"]],
michael@0 87 ["'tesst'.split(/(?:s)*/)", ["t", "e", "t"]],
michael@0 88 ["'tesst'.split(/(?=s+)/)", ["te", "s", "st"]],
michael@0 89 ["'test'.split('t')", ["", "es", ""]],
michael@0 90 ["'test'.split('es')", ["t", "t"]],
michael@0 91 ["'test'.split(/t/)", ["", "es", ""]],
michael@0 92 ["'test'.split(/es/)", ["t", "t"]],
michael@0 93 ["'test'.split(/(t)/)", ["", "t", "es", "t", ""]],
michael@0 94 ["'test'.split(/(es)/)", ["t", "es", "t"]],
michael@0 95 ["'test'.split(/(t)(e)(s)(t)/)", ["", "t", "e", "s", "t", ""]],
michael@0 96 ["'.'.split(/(((.((.??)))))/)", ["", ".", ".", ".", "", "", ""]],
michael@0 97 ["'.'.split(/(((((.??)))))/)", ["."]]
michael@0 98 ];
michael@0 99
michael@0 100 function testSplit() {
michael@0 101 for (var i = 0; i < testCode.length; i++) {
michael@0 102 var actual = eval(testCode[i][0]);
michael@0 103 var expected = testCode[i][1];
michael@0 104
michael@0 105 assertEq(actual.length, expected.length);
michael@0 106
michael@0 107 for(var j=0; j<actual.length; j++) {
michael@0 108 assertEq(actual[j], expected[j], testCode[i][0]);
michael@0 109 }
michael@0 110 }
michael@0 111 }
michael@0 112
michael@0 113 testSplit();
michael@0 114
michael@0 115 if (typeof reportCompare === "function")
michael@0 116 reportCompare(true, true);
michael@0 117
michael@0 118 print("All tests passed!");

mercurial