js/src/tests/ecma_2/String/split-003.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 * File Name: String/split-003.js
michael@0 9 * ECMA Section: 15.6.4.9
michael@0 10 * Description: Based on ECMA 2 Draft 7 February 1999
michael@0 11 *
michael@0 12 * Author: christine@netscape.com
michael@0 13 * Date: 19 February 1999
michael@0 14 */
michael@0 15
michael@0 16 /*
michael@0 17 * Since regular expressions have been part of JavaScript since 1.2, there
michael@0 18 * are already tests for regular expressions in the js1_2/regexp folder.
michael@0 19 *
michael@0 20 * These new tests try to supplement the existing tests, and verify that
michael@0 21 * our implementation of RegExp conforms to the ECMA specification, but
michael@0 22 * does not try to be as exhaustive as in previous tests.
michael@0 23 *
michael@0 24 * The [,limit] argument to String.split is new, and not covered in any
michael@0 25 * existing tests.
michael@0 26 *
michael@0 27 * String.split cases are covered in ecma/String/15.5.4.8-*.js.
michael@0 28 * String.split where separator is a RegExp are in
michael@0 29 * js1_2/regexp/string_split.js
michael@0 30 *
michael@0 31 */
michael@0 32
michael@0 33 var SECTION = "ecma_2/String/split-003.js";
michael@0 34 var VERSION = "ECMA_2";
michael@0 35 var TITLE = "String.prototype.split( regexp, [,limit] )";
michael@0 36
michael@0 37 startTest();
michael@0 38
michael@0 39 // separator is a regexp
michael@0 40 // separator regexp value global setting is set
michael@0 41 // string is an empty string
michael@0 42 // if separator is an empty string, split each by character
michael@0 43
michael@0 44
michael@0 45 AddSplitCases( "hello", new RegExp, "new RegExp", ["h","e","l","l","o"] );
michael@0 46
michael@0 47 AddSplitCases( "hello", /l/, "/l/", ["he","","o"] );
michael@0 48 AddLimitedSplitCases( "hello", /l/, "/l/", 0, [] );
michael@0 49 AddLimitedSplitCases( "hello", /l/, "/l/", 1, ["he"] );
michael@0 50 AddLimitedSplitCases( "hello", /l/, "/l/", 2, ["he",""] );
michael@0 51 AddLimitedSplitCases( "hello", /l/, "/l/", 3, ["he","","o"] );
michael@0 52 AddLimitedSplitCases( "hello", /l/, "/l/", 4, ["he","","o"] );
michael@0 53 AddLimitedSplitCases( "hello", /l/, "/l/", void 0, ["he","","o"] );
michael@0 54 AddLimitedSplitCases( "hello", /l/, "/l/", "hi", [] );
michael@0 55 AddLimitedSplitCases( "hello", /l/, "/l/", undefined, ["he","","o"] );
michael@0 56
michael@0 57 AddSplitCases( "hello", new RegExp, "new RegExp", ["h","e","l","l","o"] );
michael@0 58 AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 0, [] );
michael@0 59 AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 1, ["h"] );
michael@0 60 AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 2, ["h","e"] );
michael@0 61 AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 3, ["h","e","l"] );
michael@0 62 AddLimitedSplitCases( "hello", new RegExp, "new RegExp", 4, ["h","e","l","l"] );
michael@0 63 AddLimitedSplitCases( "hello", new RegExp, "new RegExp", void 0, ["h","e","l","l","o"] );
michael@0 64 AddLimitedSplitCases( "hello", new RegExp, "new RegExp", "hi", [] );
michael@0 65 AddLimitedSplitCases( "hello", new RegExp, "new RegExp", undefined, ["h","e","l","l","o"] );
michael@0 66
michael@0 67 test();
michael@0 68
michael@0 69 function AddSplitCases( string, separator, str_sep, split_array ) {
michael@0 70 // verify that the result of split is an object of type Array
michael@0 71 AddTestCase(
michael@0 72 "( " + string + " ).split(" + str_sep +").constructor == Array",
michael@0 73 true,
michael@0 74 string.split(separator).constructor == Array );
michael@0 75
michael@0 76 // check the number of items in the array
michael@0 77 AddTestCase(
michael@0 78 "( " + string + " ).split(" + str_sep +").length",
michael@0 79 split_array.length,
michael@0 80 string.split(separator).length );
michael@0 81
michael@0 82 // check the value of each array item
michael@0 83 var limit = (split_array.length > string.split(separator).length )
michael@0 84 ? split_array.length : string.split(separator).length;
michael@0 85
michael@0 86 for ( var matches = 0; matches < split_array.length; matches++ ) {
michael@0 87 AddTestCase(
michael@0 88 "( " + string + " ).split(" + str_sep +")[" + matches +"]",
michael@0 89 split_array[matches],
michael@0 90 string.split( separator )[matches] );
michael@0 91 }
michael@0 92 }
michael@0 93
michael@0 94 function AddLimitedSplitCases(
michael@0 95 string, separator, str_sep, limit, split_array ) {
michael@0 96
michael@0 97 // verify that the result of split is an object of type Array
michael@0 98
michael@0 99 AddTestCase(
michael@0 100 "( " + string + " ).split(" + str_sep +", " + limit +
michael@0 101 " ).constructor == Array",
michael@0 102 true,
michael@0 103 string.split(separator, limit).constructor == Array );
michael@0 104
michael@0 105 // check the length of the array
michael@0 106
michael@0 107 AddTestCase(
michael@0 108 "( " + string + " ).split(" + str_sep +", " + limit + " ).length",
michael@0 109 split_array.length,
michael@0 110 string.split(separator, limit).length );
michael@0 111
michael@0 112 // check the value of each array item
michael@0 113
michael@0 114 var slimit = (split_array.length > string.split(separator).length )
michael@0 115 ? split_array.length : string.split(separator, limit).length;
michael@0 116
michael@0 117 for ( var matches = 0; matches < slimit; matches++ ) {
michael@0 118 AddTestCase(
michael@0 119 "( " + string + " ).split(" + str_sep +", " + limit + " )[" + matches +"]",
michael@0 120 split_array[matches],
michael@0 121 string.split( separator, limit )[matches] );
michael@0 122 }
michael@0 123 }

mercurial