1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_2/regexp/special_characters.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,126 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + Filename: special_characters.js 1.12 + Description: 'Tests regular expressions containing special characters' 1.13 + 1.14 + Author: Nick Lerissa 1.15 + Date: March 10, 1998 1.16 +*/ 1.17 + 1.18 +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; 1.19 +var VERSION = 'no version'; 1.20 +startTest(); 1.21 +var TITLE = 'RegExp: special_charaters'; 1.22 + 1.23 +writeHeaderToLog('Executing script: special_characters.js'); 1.24 +writeHeaderToLog( SECTION + " "+ TITLE); 1.25 + 1.26 + 1.27 +// testing backslash '\' 1.28 +new TestCase ( SECTION, "'^abcdefghi'.match(/\^abc/)", String(["^abc"]), String('^abcdefghi'.match(/\^abc/))); 1.29 + 1.30 +// testing beginning of line '^' 1.31 +new TestCase ( SECTION, "'abcdefghi'.match(/^abc/)", String(["abc"]), String('abcdefghi'.match(/^abc/))); 1.32 + 1.33 +// testing end of line '$' 1.34 +new TestCase ( SECTION, "'abcdefghi'.match(/fghi$/)", String(["ghi"]), String('abcdefghi'.match(/ghi$/))); 1.35 + 1.36 +// testing repeat '*' 1.37 +new TestCase ( SECTION, "'eeeefghi'.match(/e*/)", String(["eeee"]), String('eeeefghi'.match(/e*/))); 1.38 + 1.39 +// testing repeat 1 or more times '+' 1.40 +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e+/)", String(["eeee"]), String('abcdeeeefghi'.match(/e+/))); 1.41 + 1.42 +// testing repeat 0 or 1 time '?' 1.43 +new TestCase ( SECTION, "'abcdefghi'.match(/abc?de/)", String(["abcde"]), String('abcdefghi'.match(/abc?de/))); 1.44 + 1.45 +// testing any character '.' 1.46 +new TestCase ( SECTION, "'abcdefghi'.match(/c.e/)", String(["cde"]), String('abcdefghi'.match(/c.e/))); 1.47 + 1.48 +// testing remembering () 1.49 +new TestCase ( SECTION, "'abcewirjskjdabciewjsdf'.match(/(abc).+\\1'/)", 1.50 + String(["abcewirjskjdabc","abc"]), String('abcewirjskjdabciewjsdf'.match(/(abc).+\1/))); 1.51 + 1.52 +// testing or match '|' 1.53 +new TestCase ( SECTION, "'abcdefghi'.match(/xyz|def/)", String(["def"]), String('abcdefghi'.match(/xyz|def/))); 1.54 + 1.55 +// testing repeat n {n} 1.56 +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3}/)", String(["eee"]), String('abcdeeeefghi'.match(/e{3}/))); 1.57 + 1.58 +// testing min repeat n {n,} 1.59 +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{3,}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{3,}/))); 1.60 + 1.61 +// testing min/max repeat {min, max} 1.62 +new TestCase ( SECTION, "'abcdeeeefghi'.match(/e{2,8}/)", String(["eeee"]), String('abcdeeeefghi'.match(/e{2,8}/))); 1.63 + 1.64 +// testing any in set [abc...] 1.65 +new TestCase ( SECTION, "'abcdefghi'.match(/cd[xey]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[xey]fgh/))); 1.66 + 1.67 +// testing any in set [a-z] 1.68 +new TestCase ( SECTION, "'netscape inc'.match(/t[r-v]ca/)", String(["tsca"]), String('netscape inc'.match(/t[r-v]ca/))); 1.69 + 1.70 +// testing any not in set [^abc...] 1.71 +new TestCase ( SECTION, "'abcdefghi'.match(/cd[^xy]fgh/)", String(["cdefgh"]), String('abcdefghi'.match(/cd[^xy]fgh/))); 1.72 + 1.73 +// testing any not in set [^a-z] 1.74 +new TestCase ( SECTION, "'netscape inc'.match(/t[^a-c]ca/)", String(["tsca"]), String('netscape inc'.match(/t[^a-c]ca/))); 1.75 + 1.76 +// testing backspace [\b] 1.77 +new TestCase ( SECTION, "'this is b\ba test'.match(/is b[\b]a test/)", 1.78 + String(["is b\ba test"]), String('this is b\ba test'.match(/is b[\b]a test/))); 1.79 + 1.80 +// testing word boundary \b 1.81 +new TestCase ( SECTION, "'today is now - day is not now'.match(/\bday.*now/)", 1.82 + String(["day is not now"]), String('today is now - day is not now'.match(/\bday.*now/))); 1.83 + 1.84 +// control characters??? 1.85 + 1.86 +// testing any digit \d 1.87 +new TestCase ( SECTION, "'a dog - 1 dog'.match(/\d dog/)", String(["1 dog"]), String('a dog - 1 dog'.match(/\d dog/))); 1.88 + 1.89 +// testing any non digit \d 1.90 +new TestCase ( SECTION, "'a dog - 1 dog'.match(/\D dog/)", String(["a dog"]), String('a dog - 1 dog'.match(/\D dog/))); 1.91 + 1.92 +// testing form feed '\f' 1.93 +new TestCase ( SECTION, "'a b a\fb'.match(/a\fb/)", String(["a\fb"]), String('a b a\fb'.match(/a\fb/))); 1.94 + 1.95 +// testing line feed '\n' 1.96 +new TestCase ( SECTION, "'a b a\nb'.match(/a\nb/)", String(["a\nb"]), String('a b a\nb'.match(/a\nb/))); 1.97 + 1.98 +// testing carriage return '\r' 1.99 +new TestCase ( SECTION, "'a b a\rb'.match(/a\rb/)", String(["a\rb"]), String('a b a\rb'.match(/a\rb/))); 1.100 + 1.101 +// testing whitespace '\s' 1.102 +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/))); 1.103 + 1.104 +// testing non whitespace '\S' 1.105 +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/))); 1.106 + 1.107 +// testing tab '\t' 1.108 +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}/))); 1.109 + 1.110 +// testing vertical tab '\v' 1.111 +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}/))); 1.112 + 1.113 +// testing alphnumeric characters '\w' 1.114 +new TestCase ( SECTION, "'%AZaz09_$'.match(/\w+/)", String(["AZaz09_"]), String('%AZaz09_$'.match(/\w+/))); 1.115 + 1.116 +// testing non alphnumeric characters '\W' 1.117 +new TestCase ( SECTION, "'azx$%#@*4534'.match(/\W+/)", String(["$%#@*"]), String('azx$%#@*4534'.match(/\W+/))); 1.118 + 1.119 +// testing back references '\<number>' 1.120 +new TestCase ( SECTION, "'test'.match(/(t)es\\1/)", String(["test","t"]), String('test'.match(/(t)es\1/))); 1.121 + 1.122 +// testing hex excaping with '\' 1.123 +new TestCase ( SECTION, "'abcdef'.match(/\x63\x64/)", String(["cd"]), String('abcdef'.match(/\x63\x64/))); 1.124 + 1.125 +// testing oct excaping with '\' 1.126 +new TestCase ( SECTION, "'abcdef'.match(/\\143\\144/)", String(["cd"]), String('abcdef'.match(/\143\144/))); 1.127 + 1.128 +test(); 1.129 +