Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | Filename: special_characters.js |
michael@0 | 9 | Description: 'Tests regular expressions containing special characters' |
michael@0 | 10 | |
michael@0 | 11 | Author: Nick Lerissa |
michael@0 | 12 | Date: March 10, 1998 |
michael@0 | 13 | */ |
michael@0 | 14 | |
michael@0 | 15 | var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; |
michael@0 | 16 | var VERSION = 'no version'; |
michael@0 | 17 | startTest(); |
michael@0 | 18 | var TITLE = 'RegExp: special_charaters'; |
michael@0 | 19 | |
michael@0 | 20 | writeHeaderToLog('Executing script: special_characters.js'); |
michael@0 | 21 | writeHeaderToLog( SECTION + " "+ TITLE); |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | // testing backslash '\' |
michael@0 | 25 | new TestCase ( SECTION, "'^abcdefghi'.match(/\^abc/)", String(["^abc"]), String('^abcdefghi'.match(/\^abc/))); |
michael@0 | 26 | |
michael@0 | 27 | // testing beginning of line '^' |
michael@0 | 28 | new TestCase ( SECTION, "'abcdefghi'.match(/^abc/)", String(["abc"]), String('abcdefghi'.match(/^abc/))); |
michael@0 | 29 | |
michael@0 | 30 | // testing end of line '$' |
michael@0 | 31 | new TestCase ( SECTION, "'abcdefghi'.match(/fghi$/)", String(["ghi"]), String('abcdefghi'.match(/ghi$/))); |
michael@0 | 32 | |
michael@0 | 33 | // testing repeat '*' |
michael@0 | 34 | new TestCase ( SECTION, "'eeeefghi'.match(/e*/)", String(["eeee"]), String('eeeefghi'.match(/e*/))); |
michael@0 | 35 | |
michael@0 | 36 | // testing repeat 1 or more times '+' |
michael@0 | 37 | new TestCase ( SECTION, "'abcdeeeefghi'.match(/e+/)", String(["eeee"]), String('abcdeeeefghi'.match(/e+/))); |
michael@0 | 38 | |
michael@0 | 39 | // testing repeat 0 or 1 time '?' |
michael@0 | 40 | new TestCase ( SECTION, "'abcdefghi'.match(/abc?de/)", String(["abcde"]), String('abcdefghi'.match(/abc?de/))); |
michael@0 | 41 | |
michael@0 | 42 | // testing any character '.' |
michael@0 | 43 | new TestCase ( SECTION, "'abcdefghi'.match(/c.e/)", String(["cde"]), String('abcdefghi'.match(/c.e/))); |
michael@0 | 44 | |
michael@0 | 45 | // testing remembering () |
michael@0 | 46 | new TestCase ( SECTION, "'abcewirjskjdabciewjsdf'.match(/(abc).+\\1'/)", |
michael@0 | 47 | String(["abcewirjskjdabc","abc"]), String('abcewirjskjdabciewjsdf'.match(/(abc).+\1/))); |
michael@0 | 48 | |
michael@0 | 49 | // testing or match '|' |
michael@0 | 50 | new TestCase ( SECTION, "'abcdefghi'.match(/xyz|def/)", String(["def"]), String('abcdefghi'.match(/xyz|def/))); |
michael@0 | 51 | |
michael@0 | 52 | // testing repeat n {n} |
michael@0 | 53 | new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3}/)", String(["eee"]), String('abcdeeeefghi'.match(/e{3}/))); |
michael@0 | 54 | |
michael@0 | 55 | // testing min repeat n {n,} |
michael@0 | 56 | new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3,}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{3,}/))); |
michael@0 | 57 | |
michael@0 | 58 | // testing min/max repeat {min, max} |
michael@0 | 59 | new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{2,8}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{2,8}/))); |
michael@0 | 60 | |
michael@0 | 61 | // testing any in set [abc...] |
michael@0 | 62 | new TestCase ( SECTION, "'abcdefghi'.match(/cd[xey]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[xey]fgh/))); |
michael@0 | 63 | |
michael@0 | 64 | // testing any in set [a-z] |
michael@0 | 65 | new TestCase ( SECTION, "'netscape inc'.match(/t[r-v]ca/)", String(["tsca"]), String('netscape inc'.match(/t[r-v]ca/))); |
michael@0 | 66 | |
michael@0 | 67 | // testing any not in set [^abc...] |
michael@0 | 68 | new TestCase ( SECTION, "'abcdefghi'.match(/cd[^xy]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[^xy]fgh/))); |
michael@0 | 69 | |
michael@0 | 70 | // testing any not in set [^a-z] |
michael@0 | 71 | new TestCase ( SECTION, "'netscape inc'.match(/t[^a-c]ca/)", String(["tsca"]), String('netscape inc'.match(/t[^a-c]ca/))); |
michael@0 | 72 | |
michael@0 | 73 | // testing backspace [\b] |
michael@0 | 74 | new TestCase ( SECTION, "'this is b\ba test'.match(/is b[\b]a test/)", |
michael@0 | 75 | String(["is b\ba test"]), String('this is b\ba test'.match(/is b[\b]a test/))); |
michael@0 | 76 | |
michael@0 | 77 | // testing word boundary \b |
michael@0 | 78 | new TestCase ( SECTION, "'today is now - day is not now'.match(/\bday.*now/)", |
michael@0 | 79 | String(["day is not now"]), String('today is now - day is not now'.match(/\bday.*now/))); |
michael@0 | 80 | |
michael@0 | 81 | // control characters??? |
michael@0 | 82 | |
michael@0 | 83 | // testing any digit \d |
michael@0 | 84 | new TestCase ( SECTION, "'a dog - 1 dog'.match(/\d dog/)", String(["1 dog"]), String('a dog - 1 dog'.match(/\d dog/))); |
michael@0 | 85 | |
michael@0 | 86 | // testing any non digit \d |
michael@0 | 87 | new TestCase ( SECTION, "'a dog - 1 dog'.match(/\D dog/)", String(["a dog"]), String('a dog - 1 dog'.match(/\D dog/))); |
michael@0 | 88 | |
michael@0 | 89 | // testing form feed '\f' |
michael@0 | 90 | new TestCase ( SECTION, "'a b a\fb'.match(/a\fb/)", String(["a\fb"]), String('a b a\fb'.match(/a\fb/))); |
michael@0 | 91 | |
michael@0 | 92 | // testing line feed '\n' |
michael@0 | 93 | new TestCase ( SECTION, "'a b a\nb'.match(/a\nb/)", String(["a\nb"]), String('a b a\nb'.match(/a\nb/))); |
michael@0 | 94 | |
michael@0 | 95 | // testing carriage return '\r' |
michael@0 | 96 | new TestCase ( SECTION, "'a b a\rb'.match(/a\rb/)", String(["a\rb"]), String('a b a\rb'.match(/a\rb/))); |
michael@0 | 97 | |
michael@0 | 98 | // testing whitespace '\s' |
michael@0 | 99 | new TestCase ( SECTION, "'xa\f\n\r\t\vbz'.match(/a\s+b/)", String(["a\f\n\r\t\vb"]), String('xa\f\n\r\t\vbz'.match(/a\s+b/))); |
michael@0 | 100 | |
michael@0 | 101 | // testing non whitespace '\S' |
michael@0 | 102 | new TestCase ( SECTION, "'a\tb a b a-b'.match(/a\Sb/)", String(["a-b"]), String('a\tb a b a-b'.match(/a\Sb/))); |
michael@0 | 103 | |
michael@0 | 104 | // testing tab '\t' |
michael@0 | 105 | new TestCase ( SECTION, "'a\t\tb a b'.match(/a\t{2}/)", String(["a\t\t"]), String('a\t\tb a b'.match(/a\t{2}/))); |
michael@0 | 106 | |
michael@0 | 107 | // testing vertical tab '\v' |
michael@0 | 108 | new TestCase ( SECTION, "'a\v\vb a b'.match(/a\v{2}/)", String(["a\v\v"]), String('a\v\vb a b'.match(/a\v{2}/))); |
michael@0 | 109 | |
michael@0 | 110 | // testing alphnumeric characters '\w' |
michael@0 | 111 | new TestCase ( SECTION, "'%AZaz09_$'.match(/\w+/)", String(["AZaz09_"]), String('%AZaz09_$'.match(/\w+/))); |
michael@0 | 112 | |
michael@0 | 113 | // testing non alphnumeric characters '\W' |
michael@0 | 114 | new TestCase ( SECTION, "'azx$%#@*4534'.match(/\W+/)", String(["$%#@*"]), String('azx$%#@*4534'.match(/\W+/))); |
michael@0 | 115 | |
michael@0 | 116 | // testing back references '\<number>' |
michael@0 | 117 | new TestCase ( SECTION, "'test'.match(/(t)es\\1/)", String(["test","t"]), String('test'.match(/(t)es\1/))); |
michael@0 | 118 | |
michael@0 | 119 | // testing hex excaping with '\' |
michael@0 | 120 | new TestCase ( SECTION, "'abcdef'.match(/\x63\x64/)", String(["cd"]), String('abcdef'.match(/\x63\x64/))); |
michael@0 | 121 | |
michael@0 | 122 | // testing oct excaping with '\' |
michael@0 | 123 | new TestCase ( SECTION, "'abcdef'.match(/\\143\\144/)", String(["cd"]), String('abcdef'.match(/\143\144/))); |
michael@0 | 124 | |
michael@0 | 125 | test(); |
michael@0 | 126 |