js/src/tests/ecma_2/String/match-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/match-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 * 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
michael@0 38 var SECTION = "String/match-003.js";
michael@0 39 var VERSION = "ECMA_2";
michael@0 40 var TITLE = "String.prototype.match( regexp )";
michael@0 41
michael@0 42 startTest();
michael@0 43
michael@0 44 // the regexp argument is not a RegExp object
michael@0 45 // this is not a string object
michael@0 46
michael@0 47
michael@0 48 // [if regexp.global is true] set the regexp.lastIndex property to 0 and
michael@0 49 // invoke RegExp.prototype.exec repeatedly until there is no match. If
michael@0 50 // there is a match with an empty string (in other words, if the value of
michael@0 51 // regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1.
michael@0 52 // The value returned is an array with the properties 0 through n-1
michael@0 53 // corresponding to the first element of the result of each matching invocation
michael@0 54 // of RegExp.prototype.exec.
michael@0 55
michael@0 56
michael@0 57 // set the value of lastIndex
michael@0 58 re = /([\d]{5})([-\ ]?[\d]{4})?$/g;
michael@0 59
michael@0 60
michael@0 61 s = "Boston, MA 02134";
michael@0 62
michael@0 63 AddGlobalRegExpCases( re,
michael@0 64 "re = " + re,
michael@0 65 s,
michael@0 66 ["02134" ]);
michael@0 67
michael@0 68 re.lastIndex = 0;
michael@0 69
michael@0 70 AddGlobalRegExpCases(
michael@0 71 re,
michael@0 72 "re = " + re + "; re.lastIndex = 0 ",
michael@0 73 s,
michael@0 74 ["02134"]);
michael@0 75
michael@0 76
michael@0 77 re.lastIndex = s.length;
michael@0 78
michael@0 79 AddGlobalRegExpCases(
michael@0 80 re,
michael@0 81 "re = " + re + "; re.lastIndex = " + s.length,
michael@0 82 s,
michael@0 83 ["02134"] );
michael@0 84
michael@0 85 re.lastIndex = s.lastIndexOf("0");
michael@0 86
michael@0 87 AddGlobalRegExpCases(
michael@0 88 re,
michael@0 89 "re = "+ re +"; re.lastIndex = " + s.lastIndexOf("0"),
michael@0 90 s,
michael@0 91 ["02134"]);
michael@0 92
michael@0 93 re.lastIndex = s.lastIndexOf("0") + 1;
michael@0 94
michael@0 95 AddGlobalRegExpCases(
michael@0 96 re,
michael@0 97 "re = " +re+ "; re.lastIndex = " + (s.lastIndexOf("0") +1),
michael@0 98 s,
michael@0 99 ["02134"]);
michael@0 100
michael@0 101 test();
michael@0 102
michael@0 103 function AddGlobalRegExpCases(
michael@0 104 regexp, str_regexp, string, matches_array ) {
michael@0 105
michael@0 106 // prevent a runtime error
michael@0 107
michael@0 108 if ( string.match(regexp) == null || matches_array == null ) {
michael@0 109 AddTestCase(
michael@0 110 string + ".match(" + str_regexp +")",
michael@0 111 matches_array,
michael@0 112 string.match(regexp) );
michael@0 113
michael@0 114 return;
michael@0 115 }
michael@0 116
michael@0 117 AddTestCase(
michael@0 118 "( " + string + " ).match(" + str_regexp +").length",
michael@0 119 matches_array.length,
michael@0 120 string.match(regexp).length );
michael@0 121
michael@0 122 var limit = matches_array.length > string.match(regexp).length ?
michael@0 123 matches_array.length :
michael@0 124 string.match(regexp).length;
michael@0 125
michael@0 126 for ( var matches = 0; matches < limit; matches++ ) {
michael@0 127 AddTestCase(
michael@0 128 "( " + string + " ).match(" + str_regexp +")[" + matches +"]",
michael@0 129 matches_array[matches],
michael@0 130 string.match(regexp)[matches] );
michael@0 131 }
michael@0 132 }

mercurial