Home | History | Annotate | Download | only in webkit
      1 // Copyright 2013 the V8 project authors. All rights reserved.
      2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions
      6 // are met:
      7 // 1.  Redistributions of source code must retain the above copyright
      8 //     notice, this list of conditions and the following disclaimer.
      9 // 2.  Redistributions in binary form must reproduce the above copyright
     10 //     notice, this list of conditions and the following disclaimer in the
     11 //     documentation and/or other materials provided with the distribution.
     12 //
     13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
     14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23 
     24 description(
     25 'This is a test of the charAt and charCodeAt string functions.'
     26 );
     27 
     28 var undefined;
     29 
     30 var cases = [
     31     ["", "omitted"],
     32     ["", undefined],
     33     ["", 0],
     34     ["", null],
     35     ["", false],
     36     ["", true],
     37     ["", 0.0],
     38     ["", 0.1],
     39     ["", 999],
     40     ["", 1/0],
     41     ["", -1],
     42     ["", -1/0],
     43     ["", 0/0],
     44 
     45     ["x", "omitted"],
     46     ["x", undefined],
     47     ["x", 0],
     48     ["x", null],
     49     ["x", false],
     50     ["x", true],
     51     ["x", 0.0],
     52     ["x", 0.1],
     53     ["x", 999],
     54     ["x", 1/0],
     55     ["x", -1],
     56     ["x", -1/0],
     57     ["x", 0/0],
     58 
     59     ["xy", "omitted"],
     60     ["xy", undefined],
     61     ["xy", 0],
     62     ["xy", null],
     63     ["xy", false],
     64     ["xy", true],
     65     ["xy", 0.0],
     66     ["xy", 0.1],
     67     ["xy", 999],
     68     ["xy", 1/0],
     69     ["xy", -1],
     70     ["xy", -1/0],
     71     ["xy", 0/0],
     72 ];
     73 
     74 var answers = [['""', 'NaN'],
     75 ['""', 'NaN'],
     76 ['""', 'NaN'],
     77 ['""', 'NaN'],
     78 ['""', 'NaN'],
     79 ['""', 'NaN'],
     80 ['""', 'NaN'],
     81 ['""', 'NaN'],
     82 ['""', 'NaN'],
     83 ['""', 'NaN'],
     84 ['""', 'NaN'],
     85 ['""', 'NaN'],
     86 ['""', 'NaN'],
     87 ['"x"', '120'],
     88 ['"x"', '120'],
     89 ['"x"', '120'],
     90 ['"x"', '120'],
     91 ['"x"', '120'],
     92 ['""', 'NaN'],
     93 ['"x"', '120'],
     94 ['"x"', '120'],
     95 ['""', 'NaN'],
     96 ['""', 'NaN'],
     97 ['""', 'NaN'],
     98 ['""', 'NaN'],
     99 ['"x"', '120'],
    100 ['"x"', '120'],
    101 ['"x"', '120'],
    102 ['"x"', '120'],
    103 ['"x"', '120'],
    104 ['"x"', '120'],
    105 ['"y"', '121'],
    106 ['"x"', '120'],
    107 ['"x"', '120'],
    108 ['""', 'NaN'],
    109 ['""', 'NaN'],
    110 ['""', 'NaN'],
    111 ['""', 'NaN'],
    112 ['"x"', '120']];
    113 
    114 for (var i = 0; i < cases.length; ++i)
    115 {
    116     var item = cases[i];
    117     var result = answers[i];
    118     if (item[1] == "omitted") {
    119         shouldBe('"' + item[0] + '".charAt()', result[0]);
    120         if (result[1] == 'NaN')
    121             shouldBeNaN('"' + item[0] + '".charCodeAt()');
    122         else
    123             shouldBe('"' + item[0] + '".charCodeAt()', result[1]);
    124     } else {
    125         shouldBe('"' + item[0] + '".charAt(' + item[1] + ')', result[0]);
    126         if (result[1] == 'NaN')
    127             shouldBeNaN('"' + item[0] + '".charCodeAt(' + item[1] + ')');
    128         else
    129             shouldBe('"' + item[0] + '".charCodeAt(' + item[1] + ')', result[1]);
    130     }
    131 }
    132