blob: d1989dfd731177e50c4bd3dcbdd585995901b16e [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2008 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28var s = "test";
29
30assertEquals("t", s.charAt());
31assertEquals("t", s.charAt("string"));
32assertEquals("t", s.charAt(null));
33assertEquals("t", s.charAt(void 0));
34assertEquals("t", s.charAt(false));
35assertEquals("e", s.charAt(true));
36assertEquals("", s.charAt(-1));
37assertEquals("", s.charAt(4));
38assertEquals("t", s.charAt(0));
39assertEquals("t", s.charAt(3));
40assertEquals("t", s.charAt(NaN));
41
42assertEquals(116, s.charCodeAt());
43assertEquals(116, s.charCodeAt("string"));
44assertEquals(116, s.charCodeAt(null));
45assertEquals(116, s.charCodeAt(void 0));
46assertEquals(116, s.charCodeAt(false));
47assertEquals(101, s.charCodeAt(true));
48assertEquals(116, s.charCodeAt(0));
49assertEquals(116, s.charCodeAt(3));
50assertEquals(116, s.charCodeAt(NaN));
51assertTrue(isNaN(s.charCodeAt(-1)));
52assertTrue(isNaN(s.charCodeAt(4)));
53
Steve Block6ded16b2010-05-10 14:33:55 +010054// Make sure enough of the one-char string cache is filled.
55var alpha = ['@'];
56for (var i = 1; i < 128; i++) {
57 var c = String.fromCharCode(i);
58 alpha[i] = c.charAt(0);
59}
60var alphaStr = alpha.join("");
61
62// Now test chars.
63for (var i = 1; i < 128; i++) {
64 assertEquals(alpha[i], alphaStr.charAt(i));
65 assertEquals(String.fromCharCode(i), alphaStr.charAt(i));
66}