js/src/tests/js1_2/regexp/word_boundary.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_2/regexp/word_boundary.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     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:     word_boundary.js
    1.12 +   Description:  'Tests regular expressions containing \b and \B'
    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: \\b and \\B';
    1.22 +
    1.23 +writeHeaderToLog('Executing script: word_boundary.js');
    1.24 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.25 +
    1.26 +
    1.27 +// 'cowboy boyish boy'.match(new RegExp('\bboy\b'))
    1.28 +new TestCase ( SECTION, "'cowboy boyish boy'.match(new RegExp('\\bboy\\b'))",
    1.29 +	       String(["boy"]), String('cowboy boyish boy'.match(new RegExp('\\bboy\\b'))));
    1.30 +
    1.31 +var boundary_characters = "\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"';
    1.32 +var non_boundary_characters = '1234567890_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    1.33 +var s     = '';
    1.34 +var i;
    1.35 +
    1.36 +// testing whether all boundary characters are matched when they should be
    1.37 +for (i = 0; i < boundary_characters.length; ++i)
    1.38 +{
    1.39 +  s = '123ab' + boundary_characters.charAt(i) + '123c' + boundary_characters.charAt(i);
    1.40 +
    1.41 +  new TestCase ( SECTION,
    1.42 +		 "'" + s + "'.match(new RegExp('\\b123[a-z]\\b'))",
    1.43 +		 String(["123c"]), String(s.match(new RegExp('\\b123[a-z]\\b'))));
    1.44 +}
    1.45 +
    1.46 +// testing whether all non-boundary characters are matched when they should be
    1.47 +for (i = 0; i < non_boundary_characters.length; ++i)
    1.48 +{
    1.49 +  s = '123ab' + non_boundary_characters.charAt(i) + '123c' + non_boundary_characters.charAt(i);
    1.50 +
    1.51 +  new TestCase ( SECTION,
    1.52 +		 "'" + s + "'.match(new RegExp('\\B123[a-z]\\B'))",
    1.53 +		 String(["123c"]), String(s.match(new RegExp('\\B123[a-z]\\B'))));
    1.54 +}
    1.55 +
    1.56 +s = '';
    1.57 +
    1.58 +// testing whether all boundary characters are not matched when they should not be
    1.59 +for (i = 0; i < boundary_characters.length; ++i)
    1.60 +{
    1.61 +  s += boundary_characters[i] + "a" + i + "b";
    1.62 +}
    1.63 +s += "xa1111bx";
    1.64 +
    1.65 +new TestCase ( SECTION,
    1.66 +	       "'" + s + "'.match(new RegExp('\\Ba\\d+b\\B'))",
    1.67 +	       String(["a1111b"]), String(s.match(new RegExp('\\Ba\\d+b\\B'))));
    1.68 +
    1.69 +new TestCase ( SECTION,
    1.70 +	       "'" + s + "'.match(/\\Ba\\d+b\\B/)",
    1.71 +	       String(["a1111b"]), String(s.match(/\Ba\d+b\B/)));
    1.72 +
    1.73 +s = '';
    1.74 +
    1.75 +// testing whether all non-boundary characters are not matched when they should not be
    1.76 +for (i = 0; i < non_boundary_characters.length; ++i)
    1.77 +{
    1.78 +  s += non_boundary_characters[i] + "a" + i + "b";
    1.79 +}
    1.80 +s += "(a1111b)";
    1.81 +
    1.82 +new TestCase ( SECTION,
    1.83 +	       "'" + s + "'.match(new RegExp('\\ba\\d+b\\b'))",
    1.84 +	       String(["a1111b"]), String(s.match(new RegExp('\\ba\\d+b\\b'))));
    1.85 +
    1.86 +new TestCase ( SECTION,
    1.87 +	       "'" + s + "'.match(/\\ba\\d+b\\b/)",
    1.88 +	       String(["a1111b"]), String(s.match(/\ba\d+b\b/)));
    1.89 +
    1.90 +test();

mercurial