| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'word_boundary.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; |
| 17 |
var VERSION = 'no version'; |
| 18 |
startTest(); |
| 19 |
var TITLE = 'RegExp: \\b and \\B'; |
| 20 |
|
| 21 |
writeHeaderToLog('Executing script: word_boundary.js'); |
| 22 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
new TestCase ( SECTION, "'cowboy boyish boy'.match(new RegExp('\\bboy\\b'))", |
| 27 |
String(["boy"]), String('cowboy boyish boy'.match(new RegExp('\\bboy\\b')))); |
| 28 |
|
| 29 |
var boundary_characters = "\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"'; |
| 30 |
var non_boundary_characters = '1234567890_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 31 |
var s = ''; |
| 32 |
var i; |
| 33 |
|
| 34 |
|
| 35 |
for (i = 0; i < boundary_characters.length; ++i) |
| 36 |
{ |
| 37 |
s = '123ab' + boundary_characters.charAt(i) + '123c' + boundary_characters.charAt(i); |
| 38 |
|
| 39 |
new TestCase ( SECTION, |
| 40 |
"'" + s + "'.match(new RegExp('\\b123[a-z]\\b'))", |
| 41 |
String(["123c"]), String(s.match(new RegExp('\\b123[a-z]\\b')))); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
for (i = 0; i < non_boundary_characters.length; ++i) |
| 46 |
{ |
| 47 |
s = '123ab' + non_boundary_characters.charAt(i) + '123c' + non_boundary_characters.charAt(i); |
| 48 |
|
| 49 |
new TestCase ( SECTION, |
| 50 |
"'" + s + "'.match(new RegExp('\\B123[a-z]\\B'))", |
| 51 |
String(["123c"]), String(s.match(new RegExp('\\B123[a-z]\\B')))); |
| 52 |
} |
| 53 |
|
| 54 |
s = ''; |
| 55 |
|
| 56 |
|
| 57 |
for (i = 0; i < boundary_characters.length; ++i) |
| 58 |
{ |
| 59 |
s += boundary_characters[i] + "a" + i + "b"; |
| 60 |
} |
| 61 |
s += "xa1111bx"; |
| 62 |
|
| 63 |
new TestCase ( SECTION, |
| 64 |
"'" + s + "'.match(new RegExp('\\Ba\\d+b\\B'))", |
| 65 |
String(["a1111b"]), String(s.match(new RegExp('\\Ba\\d+b\\B')))); |
| 66 |
|
| 67 |
new TestCase ( SECTION, |
| 68 |
"'" + s + "'.match(/\\Ba\\d+b\\B/)", |
| 69 |
String(["a1111b"]), String(s.match(/\Ba\d+b\B/))); |
| 70 |
|
| 71 |
s = ''; |
| 72 |
|
| 73 |
|
| 74 |
for (i = 0; i < non_boundary_characters.length; ++i) |
| 75 |
{ |
| 76 |
s += non_boundary_characters[i] + "a" + i + "b"; |
| 77 |
} |
| 78 |
s += "(a1111b)"; |
| 79 |
|
| 80 |
new TestCase ( SECTION, |
| 81 |
"'" + s + "'.match(new RegExp('\\ba\\d+b\\b'))", |
| 82 |
String(["a1111b"]), String(s.match(new RegExp('\\ba\\d+b\\b')))); |
| 83 |
|
| 84 |
new TestCase ( SECTION, |
| 85 |
"'" + s + "'.match(/\\ba\\d+b\\b/)", |
| 86 |
String(["a1111b"]), String(s.match(/\ba\d+b\b/))); |
| 87 |
|
| 88 |
test(); |