test/script/basic/regex.js

Mon, 01 Jul 2013 19:52:07 +0530

author
sundar
date
Mon, 01 Jul 2013 19:52:07 +0530
changeset 390
ab3ea5b3e507
parent 7
5a1b0714df0e
child 952
6d5471a497fb
child 962
ac62e33a99b0
permissions
-rw-r--r--

8019488: switch on literals result in NoSuchMethodError or VerifyError
Reviewed-by: hannesw

     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  * 
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  * 
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  * 
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  * 
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /**
    25  * RegExp test.
    26  *
    27  * @test
    28  * @run 
    29  */
    31 var regexp;
    33 regexp = new RegExp("dog");
    34 print("is global? " + regexp.global);
    35 print(regexp.exec("One dog, two dogs in the yard."));
    36 regexp = new RegExp("dog", "g");
    37 print(regexp.exec("One dog, two dogs in the yard."));
    38 regexp = new RegExp("(d)(o)(g)");
    39 print(regexp.exec("One dog, two dogs in the yard."));
    40 regexp = new RegExp("cat");
    41 print(regexp.exec("One dog, two dogs in the yard."));
    43 regexp = new RegExp("dog");
    44 print(regexp.test("One dog, two dogs in the yard."));
    45 regexp = new RegExp("dog", "g");
    46 print(regexp.test("One dog, two dogs in the yard."));
    47 regexp = new RegExp("(d)(o)(g)");
    48 print(regexp.test("One dog, two dogs in the yard."));
    49 regexp = new RegExp("cat");
    50 print(regexp.test("One dog, two dogs in the yard."));
    52 regexp = new RegExp("dog");
    53 print("One dog, two dogs in the yard.".replace(regexp, "cat"));
    54 regexp = new RegExp("dog", "g");
    55 print("One dog, two dogs in the yard.".replace(regexp, "cat"));
    56 regexp = new RegExp("(d)(o)(g)");
    57 print("One dog, two dogs in the yard.".replace(regexp, "cat"));
    58 regexp = new RegExp("cat");
    59 print("One dog, two dogs in the yard.".replace(regexp, "cat"));
    60 print("One dog, two dogs in the yard.".replace("dog", "cat"));
    62 regexp = new RegExp("dog");
    63 print("One dog, two dogs in the yard.".search(regexp));
    64 regexp = new RegExp("dog", "g");
    65 print("One dog, two dogs in the yard.".search(regexp));
    66 regexp = new RegExp("(d)(o)(g)");
    67 print("One dog, two dogs in the yard.".search(regexp));
    68 regexp = new RegExp("cat");
    69 print("One dog, two dogs in the yard.".search(regexp));
    71 print(/dog/.exec("One dog, two dogs in the yard."));
    72 print(/dog/g.exec("One dog, two dogs in the yard."));
    73 print(/(d)(o)(g)/.exec("One dog, two dogs in the yard."));
    74 print(/cat/.exec("One dog, two dogs in the yard."));
    76 print(/dog/.test("One dog, two dogs in the yard."));
    77 print(/dog/g.test("One dog, two dogs in the yard."));
    78 print(/(d)(o)(g)/.test("One dog, two dogs in the yard."));
    79 print(/cat/.test("One dog, two dogs in the yard."));
    81 print("One dog, two dogs in the yard.".replace(/dog/, "cat"));
    82 print("One dog, two dogs in the yard.".replace(/dog/g, "cat"));
    83 print("One dog, two dogs in the yard.".replace(/(d)(o)(g)/, "cat"));
    84 print("One dog, two dogs in the yard.".replace(/cat/, "cat"));
    86 print("One dog, two dogs in the yard.".search(/dog/));
    87 print("One dog, two dogs in the yard.".search(/dog/g));
    88 print("One dog, two dogs in the yard.".search(/(d)(o)(g)/));
    89 print("One dog, two dogs in the yard.".search(/cat/));
    91 print("One dog, two dogs in the yard.".split(/dog/));
    92 print("One dog, two dogs in the yard.".split(/dog/g));
    93 print("One dog, two dogs in the yard.".split(/(d)(o)(g)/));
    94 print("One dog, two dogs in the yard.".split(/cat/));
    96 regexp = new RegExp("dog");
    97 print("One dog, two dogs in the yard.".split(regexp));
    98 regexp = new RegExp("dog", "g");
    99 print("One dog, two dogs in the yard.".split(regexp));
   100 regexp = new RegExp("(d)(o)(g)");
   101 print("One dog, two dogs in the yard.".split(regexp));
   102 regexp = new RegExp("cat");
   103 print("One dog, two dogs in the yard.".split(regexp));
   104 print("One dog, two dogs in the yard.".split("dog"));
   106 var str = 'shapgvba (){Cuk.Nccyvpngvba.Frghc.Pber();Cuk.Nccyvpngvba.Frghc.Nwnk();Cuk.Nccyvpngvba.Frghc.Synfu();Cuk.Nccyvpngvba.Frghc.Zbqhyrf()}';
   107 regex = /^[\s[]?shapgvba/;
   108 print(regex.exec('[bowrpg tybony]'));
   109 print(regex.exec(str));
   110 print(regex.exec('shapgvba sbphf() { [angvir pbqr] }'));
   111 regex = new RegExp("^[\\s[]?shapgvba");
   112 print(regex.exec('[bowrpg tybony]'));
   113 print(regex.exec(str));
   114 print(regex.exec('shapgvba sbphf() { [angvir pbqr] }'));

mercurial