|
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/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 Filename: everything.js |
|
9 Description: 'Tests regular expressions' |
|
10 |
|
11 Author: Nick Lerissa |
|
12 Date: March 24, 1998 |
|
13 */ |
|
14 |
|
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'; |
|
19 |
|
20 writeHeaderToLog('Executing script: everything.js'); |
|
21 writeHeaderToLog( SECTION + " "+ TITLE); |
|
22 |
|
23 |
|
24 // 'Sally and Fred are sure to come.'.match(/^[a-z\s]*/i) |
|
25 new TestCase ( SECTION, "'Sally and Fred are sure to come'.match(/^[a-z\\s]*/i)", |
|
26 String(["Sally and Fred are sure to come"]), String('Sally and Fred are sure to come'.match(/^[a-z\s]*/i))); |
|
27 |
|
28 // 'test123W+xyz'.match(new RegExp('^[a-z]*[0-9]+[A-Z]?.(123|xyz)$')) |
|
29 new TestCase ( SECTION, "'test123W+xyz'.match(new RegExp('^[a-z]*[0-9]+[A-Z]?.(123|xyz)$'))", |
|
30 String(["test123W+xyz","xyz"]), String('test123W+xyz'.match(new RegExp('^[a-z]*[0-9]+[A-Z]?.(123|xyz)$')))); |
|
31 |
|
32 // 'number one 12365 number two 9898'.match(/(\d+)\D+(\d+)/) |
|
33 new TestCase ( SECTION, "'number one 12365 number two 9898'.match(/(\d+)\D+(\d+)/)", |
|
34 String(["12365 number two 9898","12365","9898"]), String('number one 12365 number two 9898'.match(/(\d+)\D+(\d+)/))); |
|
35 |
|
36 var simpleSentence = /(\s?[^\!\?\.]+[\!\?\.])+/; |
|
37 // 'See Spot run.'.match(simpleSentence) |
|
38 new TestCase ( SECTION, "'See Spot run.'.match(simpleSentence)", |
|
39 String(["See Spot run.","See Spot run."]), String('See Spot run.'.match(simpleSentence))); |
|
40 |
|
41 // 'I like it. What's up? I said NO!'.match(simpleSentence) |
|
42 new TestCase ( SECTION, "'I like it. What's up? I said NO!'.match(simpleSentence)", |
|
43 String(["I like it. What's up? I said NO!",' I said NO!']), String('I like it. What\'s up? I said NO!'.match(simpleSentence))); |
|
44 |
|
45 // 'the quick brown fox jumped over the lazy dogs'.match(/((\w+)\s*)+/) |
|
46 new TestCase ( SECTION, "'the quick brown fox jumped over the lazy dogs'.match(/((\\w+)\\s*)+/)", |
|
47 String(['the quick brown fox jumped over the lazy dogs','dogs','dogs']),String('the quick brown fox jumped over the lazy dogs'.match(/((\w+)\s*)+/))); |
|
48 |
|
49 test(); |