1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_2/regexp/alphanumeric.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 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: alphanumeric.js 1.12 + Description: 'Tests regular expressions with \w and \W 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: \\w and \\W'; 1.22 + 1.23 +writeHeaderToLog('Executing script: alphanumeric.js'); 1.24 +writeHeaderToLog( SECTION + " " + TITLE); 1.25 + 1.26 +var non_alphanumeric = "~`!@#$%^&*()-+={[}]|\\:;'<,>./?\f\n\r\t\v " + '"'; 1.27 +var alphanumeric = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; 1.28 + 1.29 +// be sure all alphanumerics are matched by \w 1.30 +new TestCase ( SECTION, 1.31 + "'" + alphanumeric + "'.match(new RegExp('\\w+'))", 1.32 + String([alphanumeric]), String(alphanumeric.match(new RegExp('\\w+')))); 1.33 + 1.34 +// be sure all non-alphanumerics are matched by \W 1.35 +new TestCase ( SECTION, 1.36 + "'" + non_alphanumeric + "'.match(new RegExp('\\W+'))", 1.37 + String([non_alphanumeric]), String(non_alphanumeric.match(new RegExp('\\W+')))); 1.38 + 1.39 +// be sure all non-alphanumerics are not matched by \w 1.40 +new TestCase ( SECTION, 1.41 + "'" + non_alphanumeric + "'.match(new RegExp('\\w'))", 1.42 + null, non_alphanumeric.match(new RegExp('\\w'))); 1.43 + 1.44 +// be sure all alphanumerics are not matched by \W 1.45 +new TestCase ( SECTION, 1.46 + "'" + alphanumeric + "'.match(new RegExp('\\W'))", 1.47 + null, alphanumeric.match(new RegExp('\\W'))); 1.48 + 1.49 +var s = non_alphanumeric + alphanumeric; 1.50 + 1.51 +// be sure all alphanumerics are matched by \w 1.52 +new TestCase ( SECTION, 1.53 + "'" + s + "'.match(new RegExp('\\w+'))", 1.54 + String([alphanumeric]), String(s.match(new RegExp('\\w+')))); 1.55 + 1.56 +s = alphanumeric + non_alphanumeric; 1.57 + 1.58 +// be sure all non-alphanumerics are matched by \W 1.59 +new TestCase ( SECTION, 1.60 + "'" + s + "'.match(new RegExp('\\W+'))", 1.61 + String([non_alphanumeric]), String(s.match(new RegExp('\\W+')))); 1.62 + 1.63 +// be sure all alphanumerics are matched by \w (using literals) 1.64 +new TestCase ( SECTION, 1.65 + "'" + s + "'.match(/\w+/)", 1.66 + String([alphanumeric]), String(s.match(/\w+/))); 1.67 + 1.68 +s = alphanumeric + non_alphanumeric; 1.69 + 1.70 +// be sure all non-alphanumerics are matched by \W (using literals) 1.71 +new TestCase ( SECTION, 1.72 + "'" + s + "'.match(/\W+/)", 1.73 + String([non_alphanumeric]), String(s.match(/\W+/))); 1.74 + 1.75 +s = 'abcd*&^%$$'; 1.76 +// be sure the following test behaves consistently 1.77 +new TestCase ( SECTION, 1.78 + "'" + s + "'.match(/(\w+)...(\W+)/)", 1.79 + String([s , 'abcd' , '%$$']), String(s.match(/(\w+)...(\W+)/))); 1.80 + 1.81 +var i; 1.82 + 1.83 +// be sure all alphanumeric characters match individually 1.84 +for (i = 0; i < alphanumeric.length; ++i) 1.85 +{ 1.86 + s = '#$' + alphanumeric[i] + '%^'; 1.87 + new TestCase ( SECTION, 1.88 + "'" + s + "'.match(new RegExp('\\w'))", 1.89 + String([alphanumeric[i]]), String(s.match(new RegExp('\\w')))); 1.90 +} 1.91 +// be sure all non_alphanumeric characters match individually 1.92 +for (i = 0; i < non_alphanumeric.length; ++i) 1.93 +{ 1.94 + s = 'sd' + non_alphanumeric[i] + String((i+10) * (i+10) - 2 * (i+10)); 1.95 + new TestCase ( SECTION, 1.96 + "'" + s + "'.match(new RegExp('\\W'))", 1.97 + String([non_alphanumeric[i]]), String(s.match(new RegExp('\\W')))); 1.98 +} 1.99 + 1.100 +test();