| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'whitespace.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: \\f\\n\\r\\t\\v\\s\\S '; |
| 20 |
|
| 21 |
writeHeaderToLog('Executing script: whitespace.js'); |
| 22 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 23 |
|
| 24 |
|
| 25 |
var non_whitespace = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()-+={[}]|\\:;'<,>./?1234567890" + '"'; |
| 26 |
var whitespace = "\f\n\r\t\v "; |
| 27 |
|
| 28 |
|
| 29 |
new TestCase ( SECTION, |
| 30 |
"'" + whitespace + "'.match(new RegExp('\\s+'))", |
| 31 |
String([whitespace]), String(whitespace.match(new RegExp('\\s+')))); |
| 32 |
|
| 33 |
|
| 34 |
new TestCase ( SECTION, |
| 35 |
"'" + non_whitespace + "'.match(new RegExp('\\S+'))", |
| 36 |
String([non_whitespace]), String(non_whitespace.match(new RegExp('\\S+')))); |
| 37 |
|
| 38 |
|
| 39 |
new TestCase ( SECTION, |
| 40 |
"'" + non_whitespace + "'.match(new RegExp('\\s'))", |
| 41 |
null, non_whitespace.match(new RegExp('\\s'))); |
| 42 |
|
| 43 |
|
| 44 |
new TestCase ( SECTION, |
| 45 |
"'" + whitespace + "'.match(new RegExp('\\S'))", |
| 46 |
null, whitespace.match(new RegExp('\\S'))); |
| 47 |
|
| 48 |
var s = non_whitespace + whitespace; |
| 49 |
|
| 50 |
|
| 51 |
new TestCase ( SECTION, |
| 52 |
"'" + s + "'.match(new RegExp('\\s+'))", |
| 53 |
String([whitespace]), String(s.match(new RegExp('\\s+')))); |
| 54 |
|
| 55 |
s = whitespace + non_whitespace; |
| 56 |
|
| 57 |
|
| 58 |
new TestCase ( SECTION, |
| 59 |
"'" + s + "'.match(new RegExp('\\S+'))", |
| 60 |
String([non_whitespace]), String(s.match(new RegExp('\\S+')))); |
| 61 |
|
| 62 |
|
| 63 |
new TestCase ( SECTION, "'1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+'))", |
| 64 |
String(["find me"]), String('1233345find me345'.match(new RegExp('[a-z\\s][a-z\\s]+')))); |
| 65 |
|
| 66 |
var i; |
| 67 |
|
| 68 |
|
| 69 |
for (i = 0; i < whitespace.length; ++i) |
| 70 |
{ |
| 71 |
s = 'ab' + whitespace[i] + 'cd'; |
| 72 |
new TestCase ( SECTION, |
| 73 |
"'" + s + "'.match(new RegExp('\\\\s'))", |
| 74 |
String([whitespace[i]]), String(s.match(new RegExp('\\s')))); |
| 75 |
new TestCase ( SECTION, |
| 76 |
"'" + s + "'.match(/\s/)", |
| 77 |
String([whitespace[i]]), String(s.match(/\s/))); |
| 78 |
} |
| 79 |
|
| 80 |
for (i = 0; i < non_whitespace.length; ++i) |
| 81 |
{ |
| 82 |
s = ' ' + non_whitespace[i] + ' '; |
| 83 |
new TestCase ( SECTION, |
| 84 |
"'" + s + "'.match(new RegExp('\\\\S'))", |
| 85 |
String([non_whitespace[i]]), String(s.match(new RegExp('\\S')))); |
| 86 |
new TestCase ( SECTION, |
| 87 |
"'" + s + "'.match(/\S/)", |
| 88 |
String([non_whitespace[i]]), String(s.match(/\S/))); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
test(); |