js/src/tests/js1_2/regexp/RegExp_object.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/RegExp_object.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     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:     RegExp_object.js
    1.12 +   Description:  'Tests regular expressions creating RexExp Objects'
    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: object';
    1.22 +
    1.23 +writeHeaderToLog('Executing script: RegExp_object.js');
    1.24 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.25 +
    1.26 +var SSN_pattern = new RegExp("\\d{3}-\\d{2}-\\d{4}");
    1.27 +
    1.28 +// testing SSN pattern
    1.29 +new TestCase ( SECTION, "'Test SSN is 123-34-4567'.match(SSN_pattern))",
    1.30 +	       String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern)));
    1.31 +
    1.32 +// testing SSN pattern
    1.33 +new TestCase ( SECTION, "'Test SSN is 123-34-4567'.match(SSN_pattern))",
    1.34 +	       String(["123-34-4567"]), String('Test SSN is 123-34-4567'.match(SSN_pattern)));
    1.35 +
    1.36 +var PHONE_pattern = new RegExp("\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})");
    1.37 +// testing PHONE pattern
    1.38 +new TestCase ( SECTION, "'Our phone number is (408)345-2345.'.match(PHONE_pattern))",
    1.39 +	       String(["(408)345-2345","408","345","2345"]), String('Our phone number is (408)345-2345.'.match(PHONE_pattern)));
    1.40 +
    1.41 +// testing PHONE pattern
    1.42 +new TestCase ( SECTION, "'The phone number is 408-345-2345!'.match(PHONE_pattern))",
    1.43 +	       String(["408-345-2345","408","345","2345"]), String('The phone number is 408-345-2345!'.match(PHONE_pattern)));
    1.44 +
    1.45 +// testing PHONE pattern
    1.46 +new TestCase ( SECTION, "String(PHONE_pattern.toString())",
    1.47 +	       "/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/", String(PHONE_pattern.toString()));
    1.48 +
    1.49 +// testing conversion to String
    1.50 +new TestCase ( SECTION, "PHONE_pattern + ' is the string'",
    1.51 +	       "/\\(?(\\d{3})\\)?-?(\\d{3})-(\\d{4})/ is the string",PHONE_pattern + ' is the string');
    1.52 +
    1.53 +// testing conversion to int
    1.54 +new TestCase ( SECTION, "SSN_pattern - 8",
    1.55 +	       NaN,SSN_pattern - 8);
    1.56 +
    1.57 +var testPattern = new RegExp("(\\d+)45(\\d+)90");
    1.58 +
    1.59 +test();

mercurial