js/src/tests/js1_2/regexp/alphanumeric.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    Filename:     alphanumeric.js
     9    Description:  'Tests regular expressions with \w and \W special characters'
    11    Author:       Nick Lerissa
    12    Date:         March 10, 1998
    13 */
    15 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
    16 var VERSION = 'no version';
    17 startTest();
    18 var TITLE   = 'RegExp: \\w and \\W';
    20 writeHeaderToLog('Executing script: alphanumeric.js');
    21 writeHeaderToLog( SECTION + " " + TITLE);
    23 var non_alphanumeric = "~`!@#$%^&*()-+={[}]|\\:;'<,>./?\f\n\r\t\v " + '"';
    24 var alphanumeric     = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    26 // be sure all alphanumerics are matched by \w
    27 new TestCase ( SECTION,
    28 	       "'" + alphanumeric + "'.match(new RegExp('\\w+'))",
    29 	       String([alphanumeric]), String(alphanumeric.match(new RegExp('\\w+'))));
    31 // be sure all non-alphanumerics are matched by \W
    32 new TestCase ( SECTION,
    33 	       "'" + non_alphanumeric + "'.match(new RegExp('\\W+'))",
    34 	       String([non_alphanumeric]), String(non_alphanumeric.match(new RegExp('\\W+'))));
    36 // be sure all non-alphanumerics are not matched by \w
    37 new TestCase ( SECTION,
    38 	       "'" + non_alphanumeric + "'.match(new RegExp('\\w'))",
    39 	       null, non_alphanumeric.match(new RegExp('\\w')));
    41 // be sure all alphanumerics are not matched by \W
    42 new TestCase ( SECTION,
    43 	       "'" + alphanumeric + "'.match(new RegExp('\\W'))",
    44 	       null, alphanumeric.match(new RegExp('\\W')));
    46 var s = non_alphanumeric + alphanumeric;
    48 // be sure all alphanumerics are matched by \w
    49 new TestCase ( SECTION,
    50 	       "'" + s + "'.match(new RegExp('\\w+'))",
    51 	       String([alphanumeric]), String(s.match(new RegExp('\\w+'))));
    53 s = alphanumeric + non_alphanumeric;
    55 // be sure all non-alphanumerics are matched by \W
    56 new TestCase ( SECTION,
    57 	       "'" + s + "'.match(new RegExp('\\W+'))",
    58 	       String([non_alphanumeric]), String(s.match(new RegExp('\\W+'))));
    60 // be sure all alphanumerics are matched by \w (using literals)
    61 new TestCase ( SECTION,
    62 	       "'" + s + "'.match(/\w+/)",
    63 	       String([alphanumeric]), String(s.match(/\w+/)));
    65 s = alphanumeric + non_alphanumeric;
    67 // be sure all non-alphanumerics are matched by \W (using literals)
    68 new TestCase ( SECTION,
    69 	       "'" + s + "'.match(/\W+/)",
    70 	       String([non_alphanumeric]), String(s.match(/\W+/)));
    72 s = 'abcd*&^%$$';
    73 // be sure the following test behaves consistently
    74 new TestCase ( SECTION,
    75 	       "'" + s + "'.match(/(\w+)...(\W+)/)",
    76 	       String([s , 'abcd' , '%$$']), String(s.match(/(\w+)...(\W+)/)));
    78 var i;
    80 // be sure all alphanumeric characters match individually
    81 for (i = 0; i < alphanumeric.length; ++i)
    82 {
    83   s = '#$' + alphanumeric[i] + '%^';
    84   new TestCase ( SECTION,
    85 		 "'" + s + "'.match(new RegExp('\\w'))",
    86 		 String([alphanumeric[i]]), String(s.match(new RegExp('\\w'))));
    87 }
    88 // be sure all non_alphanumeric characters match individually
    89 for (i = 0; i < non_alphanumeric.length; ++i)
    90 {
    91   s = 'sd' + non_alphanumeric[i] + String((i+10) * (i+10) - 2 * (i+10));
    92   new TestCase ( SECTION,
    93 		 "'" + s + "'.match(new RegExp('\\W'))",
    94 		 String([non_alphanumeric[i]]), String(s.match(new RegExp('\\W'))));
    95 }
    97 test();

mercurial