js/src/tests/js1_2/regexp/digit.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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:     digit.js
     9    Description:  'Tests regular expressions containing \d'
    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: \\d';
    20 writeHeaderToLog('Executing script: digit.js');
    21 writeHeaderToLog( SECTION + " "+ TITLE);
    23 var non_digits = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"';
    25 var digits = "1234567890";
    27 // be sure all digits are matched by \d
    28 new TestCase ( SECTION,
    29 	       "'" + digits + "'.match(new RegExp('\\d+'))",
    30 	       String([digits]), String(digits.match(new RegExp('\\d+'))));
    32 // be sure all non-digits are matched by \D
    33 new TestCase ( SECTION,
    34 	       "'" + non_digits + "'.match(new RegExp('\\D+'))",
    35 	       String([non_digits]), String(non_digits.match(new RegExp('\\D+'))));
    37 // be sure all non-digits are not matched by \d
    38 new TestCase ( SECTION,
    39 	       "'" + non_digits + "'.match(new RegExp('\\d'))",
    40 	       null, non_digits.match(new RegExp('\\d')));
    42 // be sure all digits are not matched by \D
    43 new TestCase ( SECTION,
    44 	       "'" + digits + "'.match(new RegExp('\\D'))",
    45 	       null, digits.match(new RegExp('\\D')));
    47 var s = non_digits + digits;
    49 // be sure all digits are matched by \d
    50 new TestCase ( SECTION,
    51 	       "'" + s + "'.match(new RegExp('\\d+'))",
    52 	       String([digits]), String(s.match(new RegExp('\\d+'))));
    54 var s = digits + non_digits;
    56 // be sure all non-digits are matched by \D
    57 new TestCase ( SECTION,
    58 	       "'" + s + "'.match(new RegExp('\\D+'))",
    59 	       String([non_digits]), String(s.match(new RegExp('\\D+'))));
    61 var i;
    63 // be sure all digits match individually
    64 for (i = 0; i < digits.length; ++i)
    65 {
    66   s = 'ab' + digits[i] + 'cd';
    67   new TestCase ( SECTION,
    68 		 "'" + s + "'.match(new RegExp('\\d'))",
    69 		 String([digits[i]]), String(s.match(new RegExp('\\d'))));
    70   new TestCase ( SECTION,
    71 		 "'" + s + "'.match(/\\d/)",
    72 		 String([digits[i]]), String(s.match(/\d/)));
    73 }
    74 // be sure all non_digits match individually
    75 for (i = 0; i < non_digits.length; ++i)
    76 {
    77   s = '12' + non_digits[i] + '34';
    78   new TestCase ( SECTION,
    79 		 "'" + s + "'.match(new RegExp('\\D'))",
    80 		 String([non_digits[i]]), String(s.match(new RegExp('\\D'))));
    81   new TestCase ( SECTION,
    82 		 "'" + s + "'.match(/\\D/)",
    83 		 String([non_digits[i]]), String(s.match(/\D/)));
    84 }
    86 test();

mercurial