js/src/tests/ecma_2/String/split-001.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.

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

mercurial