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

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

Issue 1700003002: [esnext] implement String padding proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove ToObject Created 4 years, 9 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
« no previous file with comments | « src/js/harmony-string-padding.js ('k') | test/mjsunit/harmony/harmony-string-pad-start.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 2016 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-string-padding
6
7 (function TestMeta() {
8 assertEquals(1, String.prototype.padEnd.length);
9 assertEquals("function", typeof String.prototype.padEnd);
10 assertEquals(Object.getPrototypeOf(Function),
11 Object.getPrototypeOf(String.prototype.padEnd));
12 assertEquals("padEnd", String.prototype.padEnd.name);
13
14 var desc = Object.getOwnPropertyDescriptor(String.prototype, "padEnd");
15 assertFalse(desc.enumerable);
16 assertTrue(desc.configurable);
17 assertTrue(desc.writable);
18 assertEquals(undefined, desc.get);
19 assertEquals(undefined, desc.set);
20
21 assertThrows(() => new Function(`${String.prototype.padEnd}`), SyntaxError);
22 })();
23
24
25 (function TestRequireObjectCoercible() {
26 var padEnd = String.prototype.padEnd;
27 assertThrows(() => padEnd.call(null, 4, "test"), TypeError);
28 assertThrows(() => padEnd.call(undefined, 4, "test"), TypeError);
29 assertEquals("123 ", padEnd.call({
30 __proto__: null,
31 valueOf() { return 123; }
32 }, 6, " "));
33
34 var proxy = new Proxy({}, {
35 get(t, name) {
36 if (name === Symbol.toPrimitive || name === "toString") return;
37 if (name === "valueOf") return () => 6.7;
38 assertUnreachable();
39 }
40 });
41 assertEquals("6.7 ", padEnd.call(proxy, 6, " "));
42
43 proxy = new Proxy({}, {
44 get(t, name) {
45 if (name === Symbol.toPrimitive || name === "valueOf") return;
46 if (name === "toString") return () => 6.7;
47 assertUnreachable();
48 }
49 });
50 assertEquals("6.7 ", padEnd.call(proxy, 6, " "));
51 })();
52
53
54 (function TestToLength() {
55 assertThrows(() => "123".padEnd(Symbol("16")), TypeError);
56 assertEquals("123", "123".padEnd(-1));
57 assertEquals("123", "123".padEnd({ toString() { return -1; } }));
58 assertEquals("123", "123".padEnd(-0));
59 assertEquals("123", "123".padEnd({ toString() { return -0; } }));
60 assertEquals("123", "123".padEnd(+0));
61 assertEquals("123", "123".padEnd({ toString() { return +0; } }));
62 assertEquals("123", "123".padEnd(NaN));
63 assertEquals("123", "123".padEnd({ toString() { return NaN; } }));
64 })();
65
66
67 (function TestFillerToString() {
68 assertEquals(". ", ".".padEnd(10));
69 assertEquals(". ", ".".padEnd(10, undefined));
70 assertEquals(". ", ".".padEnd(10, { toString() { return ""; } }));
71 assertEquals(".nullnulln", ".".padEnd(10, null));
72 })();
73
74
75 (function TestFillerRepetition() {
76 for (var i = 2000; i > 0; --i) {
77 var expected = "123" + "xoxo".repeat(i / 4).slice(0, i - 3);
78 var actual = "123".padEnd(i, "xoxo");
79 assertEquals(expected, actual);
80 assertEquals(i > "123".length ? i : 3, actual.length);
81 }
82 })();
83
84
85 (function TestTruncation() {
86 assertEquals("ab", "a".padEnd(2, "bc"));
87 })();
OLDNEW
« no previous file with comments | « src/js/harmony-string-padding.js ('k') | test/mjsunit/harmony/harmony-string-pad-start.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698