Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: test/mjsunit/harmony/string-codepointat.js

Issue 406863003: Implement String.prototype.codePointAt and String.fromCodePoint. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/messages.js ('k') | test/mjsunit/harmony/string-fromcodepoint.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --harmony-strings
6
7 // Tests taken from:
8 // https://github.com/mathiasbynens/String.prototype.codePointAt
9
10 assertEquals(String.prototype.codePointAt.length, 1);
11 assertEquals(String.prototype.propertyIsEnumerable("codePointAt"), false);
12
13 // String that starts with a BMP symbol
14 assertEquals("abc\uD834\uDF06def".codePointAt(""), 0x61);
15 assertEquals("abc\uD834\uDF06def".codePointAt("_"), 0x61);
16 assertEquals("abc\uD834\uDF06def".codePointAt(), 0x61);
17 assertEquals("abc\uD834\uDF06def".codePointAt(-Infinity), undefined);
18 assertEquals("abc\uD834\uDF06def".codePointAt(-1), undefined);
19 assertEquals("abc\uD834\uDF06def".codePointAt(-0), 0x61);
20 assertEquals("abc\uD834\uDF06def".codePointAt(0), 0x61);
21 assertEquals("abc\uD834\uDF06def".codePointAt(3), 0x1D306);
22 assertEquals("abc\uD834\uDF06def".codePointAt(4), 0xDF06);
23 assertEquals("abc\uD834\uDF06def".codePointAt(5), 0x64);
24 assertEquals("abc\uD834\uDF06def".codePointAt(42), undefined);
25 assertEquals("abc\uD834\uDF06def".codePointAt(Infinity), undefined);
26 assertEquals("abc\uD834\uDF06def".codePointAt(Infinity), undefined);
27 assertEquals("abc\uD834\uDF06def".codePointAt(NaN), 0x61);
28 assertEquals("abc\uD834\uDF06def".codePointAt(false), 0x61);
29 assertEquals("abc\uD834\uDF06def".codePointAt(null), 0x61);
30 assertEquals("abc\uD834\uDF06def".codePointAt(undefined), 0x61);
31
32 // String that starts with an astral symbol
33 assertEquals("\uD834\uDF06def".codePointAt(""), 0x1D306);
34 assertEquals("\uD834\uDF06def".codePointAt("1"), 0xDF06);
35 assertEquals("\uD834\uDF06def".codePointAt("_"), 0x1D306);
36 assertEquals("\uD834\uDF06def".codePointAt(), 0x1D306);
37 assertEquals("\uD834\uDF06def".codePointAt(-1), undefined);
38 assertEquals("\uD834\uDF06def".codePointAt(-0), 0x1D306);
39 assertEquals("\uD834\uDF06def".codePointAt(0), 0x1D306);
40 assertEquals("\uD834\uDF06def".codePointAt(1), 0xDF06);
41 assertEquals("\uD834\uDF06def".codePointAt(42), undefined);
42 assertEquals("\uD834\uDF06def".codePointAt(false), 0x1D306);
43 assertEquals("\uD834\uDF06def".codePointAt(null), 0x1D306);
44 assertEquals("\uD834\uDF06def".codePointAt(undefined), 0x1D306);
45
46 // Lone high surrogates
47 assertEquals("\uD834abc".codePointAt(""), 0xD834);
48 assertEquals("\uD834abc".codePointAt("_"), 0xD834);
49 assertEquals("\uD834abc".codePointAt(), 0xD834);
50 assertEquals("\uD834abc".codePointAt(-1), undefined);
51 assertEquals("\uD834abc".codePointAt(-0), 0xD834);
52 assertEquals("\uD834abc".codePointAt(0), 0xD834);
53 assertEquals("\uD834abc".codePointAt(false), 0xD834);
54 assertEquals("\uD834abc".codePointAt(NaN), 0xD834);
55 assertEquals("\uD834abc".codePointAt(null), 0xD834);
56 assertEquals("\uD834abc".codePointAt(undefined), 0xD834);
57
58 // Lone low surrogates
59 assertEquals("\uDF06abc".codePointAt(""), 0xDF06);
60 assertEquals("\uDF06abc".codePointAt("_"), 0xDF06);
61 assertEquals("\uDF06abc".codePointAt(), 0xDF06);
62 assertEquals("\uDF06abc".codePointAt(-1), undefined);
63 assertEquals("\uDF06abc".codePointAt(-0), 0xDF06);
64 assertEquals("\uDF06abc".codePointAt(0), 0xDF06);
65 assertEquals("\uDF06abc".codePointAt(false), 0xDF06);
66 assertEquals("\uDF06abc".codePointAt(NaN), 0xDF06);
67 assertEquals("\uDF06abc".codePointAt(null), 0xDF06);
68 assertEquals("\uDF06abc".codePointAt(undefined), 0xDF06);
69
70 assertThrows(function() {
71 String.prototype.codePointAt.call(undefined);
72 }, TypeError);
73 assertThrows(function() {
74 String.prototype.codePointAt.call(undefined, 4);
75 }, TypeError);
76 assertThrows(function() {
77 String.prototype.codePointAt.call(null);
78 }, TypeError);
79 assertThrows(function() {
80 String.prototype.codePointAt.call(null, 4);
81 }, TypeError);
82 assertEquals(String.prototype.codePointAt.call(42, 0), 0x34);
83 assertEquals(String.prototype.codePointAt.call(42, 1), 0x32);
84 assertEquals(String.prototype.codePointAt.call({
85 toString: function() { return "abc"; }
86 }, 2), 0x63);
87 var tmp = 0;
88 assertEquals(String.prototype.codePointAt.call({
89 toString: function() { ++tmp; return String(tmp); }
90 }, 0), 0x31);
91 assertEquals(tmp, 1);
OLDNEW
« no previous file with comments | « src/messages.js ('k') | test/mjsunit/harmony/string-fromcodepoint.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698