js/src/tests/ecma_3/RegExp/regress-209919.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 * Date: 19 June 2003
michael@0 9 * SUMMARY: Testing regexp submatches with quantifiers
michael@0 10 *
michael@0 11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=209919
michael@0 12 *
michael@0 13 */
michael@0 14 //-----------------------------------------------------------------------------
michael@0 15 var i = 0;
michael@0 16 var BUGNUMBER = 209919;
michael@0 17 var summary = 'Testing regexp submatches with quantifiers';
michael@0 18 var status = '';
michael@0 19 var statusmessages = new Array();
michael@0 20 var pattern = '';
michael@0 21 var patterns = new Array();
michael@0 22 var string = '';
michael@0 23 var strings = new Array();
michael@0 24 var actualmatch = '';
michael@0 25 var actualmatches = new Array();
michael@0 26 var expectedmatch = '';
michael@0 27 var expectedmatches = new Array();
michael@0 28
michael@0 29
michael@0 30 /*
michael@0 31 * Waldemar: "ECMA-262 15.10.2.5, third algorithm, step 2.1 states that
michael@0 32 * once the minimum repeat count (which is 0 for *, 1 for +, etc.) has
michael@0 33 * been satisfied, an atom being repeated must not match the empty string."
michael@0 34 *
michael@0 35 * In this example, the minimum repeat count is 0, so the last thing the
michael@0 36 * capturing parens is permitted to contain is the 'a'. It may NOT go on
michael@0 37 * to capture the '' at the $ position of 'a', even though '' satifies
michael@0 38 * the condition b*
michael@0 39 *
michael@0 40 */
michael@0 41 status = inSection(1);
michael@0 42 string = 'a';
michael@0 43 pattern = /(a|b*)*/;
michael@0 44 actualmatch = string.match(pattern);
michael@0 45 expectedmatch = Array(string, 'a');
michael@0 46 addThis();
michael@0 47
michael@0 48
michael@0 49 /*
michael@0 50 * In this example, the minimum repeat count is 5, so the capturing parens
michael@0 51 * captures the 'a', then goes on to capture the '' at the $ position of 'a'
michael@0 52 * 4 times before it has to stop. Therefore the last thing it contains is ''.
michael@0 53 */
michael@0 54 status = inSection(2);
michael@0 55 string = 'a';
michael@0 56 pattern = /(a|b*){5,}/;
michael@0 57 actualmatch = string.match(pattern);
michael@0 58 expectedmatch = Array(string, '');
michael@0 59 addThis();
michael@0 60
michael@0 61
michael@0 62 /*
michael@0 63 * Reduction of the above examples to contain only the condition b*
michael@0 64 * inside the capturing parens. This can be even harder to grasp!
michael@0 65 *
michael@0 66 * The global match is the '' at the ^ position of 'a', but the parens
michael@0 67 * is NOT permitted to capture it since the minimum repeat count is 0!
michael@0 68 */
michael@0 69 status = inSection(3);
michael@0 70 string = 'a';
michael@0 71 pattern = /(b*)*/;
michael@0 72 actualmatch = string.match(pattern);
michael@0 73 expectedmatch = Array('', undefined);
michael@0 74 addThis();
michael@0 75
michael@0 76
michael@0 77 /*
michael@0 78 * Here we have used the + quantifier (repeat count 1) outside the parens.
michael@0 79 * Therefore the parens must capture at least once before stopping, so it
michael@0 80 * does capture the '' this time -
michael@0 81 */
michael@0 82 status = inSection(4);
michael@0 83 string = 'a';
michael@0 84 pattern = /(b*)+/;
michael@0 85 actualmatch = string.match(pattern);
michael@0 86 expectedmatch = Array('', '');
michael@0 87 addThis();
michael@0 88
michael@0 89
michael@0 90 /*
michael@0 91 * More complex examples -
michael@0 92 */
michael@0 93 pattern = /^\-?(\d{1,}|\.{0,})*(\,\d{1,})?$/;
michael@0 94
michael@0 95 status = inSection(5);
michael@0 96 string = '100.00';
michael@0 97 actualmatch = string.match(pattern);
michael@0 98 expectedmatch = Array(string, '00', undefined);
michael@0 99 addThis();
michael@0 100
michael@0 101 status = inSection(6);
michael@0 102 string = '100,00';
michael@0 103 actualmatch = string.match(pattern);
michael@0 104 expectedmatch = Array(string, '100', ',00');
michael@0 105 addThis();
michael@0 106
michael@0 107 status = inSection(7);
michael@0 108 string = '1.000,00';
michael@0 109 actualmatch = string.match(pattern);
michael@0 110 expectedmatch = Array(string, '000', ',00');
michael@0 111 addThis();
michael@0 112
michael@0 113
michael@0 114
michael@0 115
michael@0 116 //-----------------------------------------------------------------------------
michael@0 117 test();
michael@0 118 //-----------------------------------------------------------------------------
michael@0 119
michael@0 120
michael@0 121
michael@0 122 function addThis()
michael@0 123 {
michael@0 124 statusmessages[i] = status;
michael@0 125 patterns[i] = pattern;
michael@0 126 strings[i] = string;
michael@0 127 actualmatches[i] = actualmatch;
michael@0 128 expectedmatches[i] = expectedmatch;
michael@0 129 i++;
michael@0 130 }
michael@0 131
michael@0 132
michael@0 133 function test()
michael@0 134 {
michael@0 135 enterFunc ('test');
michael@0 136 printBugNumber(BUGNUMBER);
michael@0 137 printStatus (summary);
michael@0 138 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
michael@0 139 exitFunc ('test');
michael@0 140 }

mercurial