OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-string-padding | 5 // Flags: --harmony-string-padding |
6 | 6 |
7 (function TestMeta() { | 7 (function TestMeta() { |
8 assertEquals(1, String.prototype.padStart.length); | 8 assertEquals(1, String.prototype.padStart.length); |
9 assertEquals("function", typeof String.prototype.padStart); | 9 assertEquals("function", typeof String.prototype.padStart); |
10 assertEquals(Object.getPrototypeOf(Function), | 10 assertEquals(Object.getPrototypeOf(Function), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 assertEquals("123", "123".padStart(+0)); | 60 assertEquals("123", "123".padStart(+0)); |
61 assertEquals("123", "123".padStart({ toString() { return +0; } })); | 61 assertEquals("123", "123".padStart({ toString() { return +0; } })); |
62 assertEquals("123", "123".padStart(NaN)); | 62 assertEquals("123", "123".padStart(NaN)); |
63 assertEquals("123", "123".padStart({ toString() { return NaN; } })); | 63 assertEquals("123", "123".padStart({ toString() { return NaN; } })); |
64 })(); | 64 })(); |
65 | 65 |
66 | 66 |
67 (function TestFillerToString() { | 67 (function TestFillerToString() { |
68 assertEquals(" .", ".".padStart(10)); | 68 assertEquals(" .", ".".padStart(10)); |
69 assertEquals(" .", ".".padStart(10, undefined)); | 69 assertEquals(" .", ".".padStart(10, undefined)); |
70 assertEquals(" .", ".".padStart(10, { toString() { return ""; } })); | |
71 assertEquals("nullnulln.", ".".padStart(10, null)); | 70 assertEquals("nullnulln.", ".".padStart(10, null)); |
| 71 assertEquals("XXXXXXXXX.", ".".padStart(10, { toString() { return "X"; } })); |
| 72 assertEquals( |
| 73 "111111111.", |
| 74 ".".padStart(10, { toString: undefined, valueOf() { return 1; } })); |
72 })(); | 75 })(); |
73 | 76 |
74 | 77 |
| 78 (function TestFillerEmptyString() { |
| 79 assertEquals(".", ".".padStart(10, "")); |
| 80 assertEquals(".", ".".padStart(10, { toString() { return ""; } })); |
| 81 assertEquals( |
| 82 ".", ".".padStart(10, { toString: undefined, valueOf() { return ""; } })); |
| 83 })(); |
| 84 |
| 85 |
75 (function TestFillerRepetition() { | 86 (function TestFillerRepetition() { |
76 for (var i = 2000; i > 0; --i) { | 87 for (var i = 2000; i > 0; --i) { |
77 var expected = "xoxo".repeat(i / 4).slice(0, i - 3) + "123"; | 88 var expected = "xoxo".repeat(i / 4).slice(0, i - 3) + "123"; |
78 var actual = "123".padStart(i, "xoxo"); | 89 var actual = "123".padStart(i, "xoxo"); |
79 assertEquals(expected, actual); | 90 assertEquals(expected, actual); |
80 assertEquals(i > "123".length ? i : 3, actual.length); | 91 assertEquals(i > "123".length ? i : 3, actual.length); |
81 } | 92 } |
82 })(); | 93 })(); |
83 | 94 |
84 | 95 |
85 (function TestTruncation() { | 96 (function TestTruncation() { |
86 assertEquals("ba", "a".padStart(2, "bc")); | 97 assertEquals("ba", "a".padStart(2, "bc")); |
87 })(); | 98 })(); |
OLD | NEW |