1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_5/String/split-xregexp.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* 1.5 + * Tests from http://xregexp.com/tests/split.html 1.6 + * 1.7 + * Copyright (C) 2007 by Steven Levithan <stevenlevithan.com> 1.8 + * 1.9 + * Distributed under the terms of the MIT license. 1.10 + * 1.11 + * Permission is hereby granted, free of charge, to any person obtaining a copy 1.12 + * of this software and associated documentation files (the "Software"), to deal 1.13 + * in the Software without restriction, including without limitation the rights 1.14 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1.15 + * copies of the Software, and to permit persons to whom the Software is 1.16 + * furnished to do so, subject to the following conditions: 1.17 + 1.18 + * The above copyright notice and this permission notice shall be included in 1.19 + * all copies or substantial portions of the Software. 1.20 + 1.21 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.22 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.23 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1.24 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1.25 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1.26 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1.27 + * THE SOFTWARE. 1.28 + */ 1.29 +var BUGNUMBER = 614608; 1.30 +var summary = "String.prototype.split with regexp separator"; 1.31 + 1.32 +print(BUGNUMBER + ": " + summary); 1.33 + 1.34 +/************** 1.35 + * BEGIN TEST * 1.36 + **************/ 1.37 + 1.38 +var ecmaSampleRe = /<(\/)?([^<>]+)>/; 1.39 + 1.40 +var testCode = [ 1.41 + ["''.split()", [""]], 1.42 + ["''.split(/./)", [""]], 1.43 + ["''.split(/.?/)", []], 1.44 + ["''.split(/.??/)", []], 1.45 + ["'ab'.split(/a*/)", ["", "b"]], 1.46 + ["'ab'.split(/a*?/)", ["a", "b"]], 1.47 + ["'ab'.split(/(?:ab)/)", ["", ""]], 1.48 + ["'ab'.split(/(?:ab)*/)", ["", ""]], 1.49 + ["'ab'.split(/(?:ab)*?/)", ["a", "b"]], 1.50 + ["'test'.split('')", ["t", "e", "s", "t"]], 1.51 + ["'test'.split()", ["test"]], 1.52 + ["'111'.split(1)", ["", "", "", ""]], 1.53 + ["'test'.split(/(?:)/, 2)", ["t", "e"]], 1.54 + ["'test'.split(/(?:)/, -1)", ["t", "e", "s", "t"]], 1.55 + ["'test'.split(/(?:)/, undefined)", ["t", "e", "s", "t"]], 1.56 + ["'test'.split(/(?:)/, null)", []], 1.57 + ["'test'.split(/(?:)/, NaN)", []], 1.58 + ["'test'.split(/(?:)/, true)", ["t"]], 1.59 + ["'test'.split(/(?:)/, '2')", ["t", "e"]], 1.60 + ["'test'.split(/(?:)/, 'two')", []], 1.61 + ["'a'.split(/-/)", ["a"]], 1.62 + ["'a'.split(/-?/)", ["a"]], 1.63 + ["'a'.split(/-??/)", ["a"]], 1.64 + ["'a'.split(/a/)", ["", ""]], 1.65 + ["'a'.split(/a?/)", ["", ""]], 1.66 + ["'a'.split(/a??/)", ["a"]], 1.67 + ["'ab'.split(/-/)", ["ab"]], 1.68 + ["'ab'.split(/-?/)", ["a", "b"]], 1.69 + ["'ab'.split(/-??/)", ["a", "b"]], 1.70 + ["'a-b'.split(/-/)", ["a", "b"]], 1.71 + ["'a-b'.split(/-?/)", ["a", "b"]], 1.72 + ["'a-b'.split(/-??/)", ["a", "-", "b"]], 1.73 + ["'a--b'.split(/-/)", ["a", "", "b"]], 1.74 + ["'a--b'.split(/-?/)", ["a", "", "b"]], 1.75 + ["'a--b'.split(/-??/)", ["a", "-", "-", "b"]], 1.76 + ["''.split(/()()/)", []], 1.77 + ["'.'.split(/()()/)", ["."]], 1.78 + ["'.'.split(/(.?)(.?)/)", ["", ".", "", ""]], 1.79 + ["'.'.split(/(.??)(.??)/)", ["."]], 1.80 + ["'.'.split(/(.)?(.)?/)", ["", ".", undefined, ""]], 1.81 + ["'A<B>bold</B>and<CODE>coded</CODE>'.split(ecmaSampleRe)", 1.82 + ["A", undefined, "B", "bold", "/", "B", 1.83 + "and", undefined, "CODE", "coded", "/", 1.84 + "CODE", ""]], 1.85 + ["'tesst'.split(/(s)*/)", ["t", undefined, "e", "s", "t"]], 1.86 + ["'tesst'.split(/(s)*?/)", ["t", undefined, "e", undefined, "s", 1.87 + undefined, "s", undefined, "t"]], 1.88 + ["'tesst'.split(/(s*)/)", ["t", "", "e", "ss", "t"]], 1.89 + ["'tesst'.split(/(s*?)/)", ["t", "", "e", "", "s", "", "s", "", "t"]], 1.90 + ["'tesst'.split(/(?:s)*/)", ["t", "e", "t"]], 1.91 + ["'tesst'.split(/(?=s+)/)", ["te", "s", "st"]], 1.92 + ["'test'.split('t')", ["", "es", ""]], 1.93 + ["'test'.split('es')", ["t", "t"]], 1.94 + ["'test'.split(/t/)", ["", "es", ""]], 1.95 + ["'test'.split(/es/)", ["t", "t"]], 1.96 + ["'test'.split(/(t)/)", ["", "t", "es", "t", ""]], 1.97 + ["'test'.split(/(es)/)", ["t", "es", "t"]], 1.98 + ["'test'.split(/(t)(e)(s)(t)/)", ["", "t", "e", "s", "t", ""]], 1.99 + ["'.'.split(/(((.((.??)))))/)", ["", ".", ".", ".", "", "", ""]], 1.100 + ["'.'.split(/(((((.??)))))/)", ["."]] 1.101 +]; 1.102 + 1.103 +function testSplit() { 1.104 + for (var i = 0; i < testCode.length; i++) { 1.105 + var actual = eval(testCode[i][0]); 1.106 + var expected = testCode[i][1]; 1.107 + 1.108 + assertEq(actual.length, expected.length); 1.109 + 1.110 + for(var j=0; j<actual.length; j++) { 1.111 + assertEq(actual[j], expected[j], testCode[i][0]); 1.112 + } 1.113 + } 1.114 +} 1.115 + 1.116 +testSplit(); 1.117 + 1.118 +if (typeof reportCompare === "function") 1.119 + reportCompare(true, true); 1.120 + 1.121 +print("All tests passed!");