js/src/tests/ecma_2/String/match-002.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/match-002.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 * String.match( regexp )
michael@0 18 *
michael@0 19 * If regexp is not an object of type RegExp, it is replaced with result
michael@0 20 * of the expression new RegExp(regexp). Let string denote the result of
michael@0 21 * converting the this value to a string. If regexp.global is false,
michael@0 22 * return the result obtained by invoking RegExp.prototype.exec (see
michael@0 23 * section 15.7.5.3) on regexp with string as parameter.
michael@0 24 *
michael@0 25 * Otherwise, set the regexp.lastIndex property to 0 and invoke
michael@0 26 * RegExp.prototype.exec repeatedly until there is no match. If there is a
michael@0 27 * match with an empty string (in other words, if the value of
michael@0 28 * regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1.
michael@0 29 * The value returned is an array with the properties 0 through n-1
michael@0 30 * corresponding to the first element of the result of each matching
michael@0 31 * invocation of RegExp.prototype.exec.
michael@0 32 *
michael@0 33 * Note that the match function is intentionally generic; it does not
michael@0 34 * require that its this value be a string object. Therefore, it can be
michael@0 35 * transferred to other kinds of objects for use as a method.
michael@0 36 *
michael@0 37 * This file tests cases in which regexp.global is false. Therefore,
michael@0 38 * results should behave as regexp.exec with string passed as a parameter.
michael@0 39 *
michael@0 40 */
michael@0 41
michael@0 42 var SECTION = "String/match-002.js";
michael@0 43 var VERSION = "ECMA_2";
michael@0 44 var TITLE = "String.prototype.match( regexp )";
michael@0 45
michael@0 46 startTest();
michael@0 47
michael@0 48 // the regexp argument is not a RegExp object
michael@0 49 // this is not a string object
michael@0 50
michael@0 51 AddRegExpCases( /([\d]{5})([-\ ]?[\d]{4})?$/,
michael@0 52 "/([\d]{5})([-\ ]?[\d]{4})?$/",
michael@0 53 "Boston, Mass. 02134",
michael@0 54 14,
michael@0 55 ["02134", "02134", undefined]);
michael@0 56
michael@0 57 AddGlobalRegExpCases( /([\d]{5})([-\ ]?[\d]{4})?$/g,
michael@0 58 "/([\d]{5})([-\ ]?[\d]{4})?$/g",
michael@0 59 "Boston, Mass. 02134",
michael@0 60 ["02134"]);
michael@0 61
michael@0 62 // set the value of lastIndex
michael@0 63 re = /([\d]{5})([-\ ]?[\d]{4})?$/;
michael@0 64 re.lastIndex = 0;
michael@0 65
michael@0 66 s = "Boston, MA 02134";
michael@0 67
michael@0 68 AddRegExpCases( re,
michael@0 69 "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex =0",
michael@0 70 s,
michael@0 71 s.lastIndexOf("0"),
michael@0 72 ["02134", "02134", undefined]);
michael@0 73
michael@0 74
michael@0 75 re.lastIndex = s.length;
michael@0 76
michael@0 77 AddRegExpCases( re,
michael@0 78 "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
michael@0 79 s.length,
michael@0 80 s,
michael@0 81 s.lastIndexOf("0"),
michael@0 82 ["02134", "02134", undefined] );
michael@0 83
michael@0 84 re.lastIndex = s.lastIndexOf("0");
michael@0 85
michael@0 86 AddRegExpCases( re,
michael@0 87 "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
michael@0 88 s.lastIndexOf("0"),
michael@0 89 s,
michael@0 90 s.lastIndexOf("0"),
michael@0 91 ["02134", "02134", undefined]);
michael@0 92
michael@0 93 re.lastIndex = s.lastIndexOf("0") + 1;
michael@0 94
michael@0 95 AddRegExpCases( re,
michael@0 96 "re = /([\d]{5})([-\ ]?[\d]{4})?$/; re.lastIndex = " +
michael@0 97 s.lastIndexOf("0") +1,
michael@0 98 s,
michael@0 99 s.lastIndexOf("0"),
michael@0 100 ["02134", "02134", undefined]);
michael@0 101
michael@0 102 test();
michael@0 103
michael@0 104 function AddRegExpCases(
michael@0 105 regexp, str_regexp, string, index, matches_array ) {
michael@0 106
michael@0 107 // prevent a runtime error
michael@0 108
michael@0 109 if ( regexp.exec(string) == null || matches_array == null ) {
michael@0 110 AddTestCase(
michael@0 111 string + ".match(" + regexp +")",
michael@0 112 matches_array,
michael@0 113 string.match(regexp) );
michael@0 114
michael@0 115 return;
michael@0 116 }
michael@0 117
michael@0 118 AddTestCase(
michael@0 119 "( " + string + " ).match(" + str_regexp +").length",
michael@0 120 matches_array.length,
michael@0 121 string.match(regexp).length );
michael@0 122
michael@0 123 AddTestCase(
michael@0 124 "( " + string + " ).match(" + str_regexp +").index",
michael@0 125 index,
michael@0 126 string.match(regexp).index );
michael@0 127
michael@0 128 AddTestCase(
michael@0 129 "( " + string + " ).match(" + str_regexp +").input",
michael@0 130 string,
michael@0 131 string.match(regexp).input );
michael@0 132
michael@0 133 var limit = matches_array.length > string.match(regexp).length ?
michael@0 134 matches_array.length :
michael@0 135 string.match(regexp).length;
michael@0 136
michael@0 137 for ( var matches = 0; matches < limit; matches++ ) {
michael@0 138 AddTestCase(
michael@0 139 "( " + string + " ).match(" + str_regexp +")[" + matches +"]",
michael@0 140 matches_array[matches],
michael@0 141 string.match(regexp)[matches] );
michael@0 142 }
michael@0 143 }
michael@0 144
michael@0 145 function AddGlobalRegExpCases(
michael@0 146 regexp, str_regexp, string, matches_array ) {
michael@0 147
michael@0 148 // prevent a runtime error
michael@0 149
michael@0 150 if ( regexp.exec(string) == null || matches_array == null ) {
michael@0 151 AddTestCase(
michael@0 152 regexp + ".exec(" + string +")",
michael@0 153 matches_array,
michael@0 154 regexp.exec(string) );
michael@0 155
michael@0 156 return;
michael@0 157 }
michael@0 158
michael@0 159 AddTestCase(
michael@0 160 "( " + string + " ).match(" + str_regexp +").length",
michael@0 161 matches_array.length,
michael@0 162 string.match(regexp).length );
michael@0 163
michael@0 164 var limit = matches_array.length > string.match(regexp).length ?
michael@0 165 matches_array.length :
michael@0 166 string.match(regexp).length;
michael@0 167
michael@0 168 for ( var matches = 0; matches < limit; matches++ ) {
michael@0 169 AddTestCase(
michael@0 170 "( " + string + " ).match(" + str_regexp +")[" + matches +"]",
michael@0 171 matches_array[matches],
michael@0 172 string.match(regexp)[matches] );
michael@0 173 }
michael@0 174 }

mercurial