| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
load("testsrc/assert.js"); |
| 29 |
|
| 30 |
assertEquals(1, String.prototype.repeat.length); |
| 31 |
|
| 32 |
assertEquals("000", String.prototype.repeat.call(0, 3)); |
| 33 |
assertEquals("-1-1-1", String.prototype.repeat.call(-1, 3)); |
| 34 |
assertEquals("2.12.12.1", String.prototype.repeat.call(2.1, 3)); |
| 35 |
assertEquals("", String.prototype.repeat.call([], 3)); |
| 36 |
assertEquals("1,2,3", String.prototype.repeat.call([1, 2, 3], 1)); |
| 37 |
assertEquals("true", String.prototype.repeat.call(true, 1)); |
| 38 |
assertEquals("false", String.prototype.repeat.call(false, 1)); |
| 39 |
assertEquals("[object Object]", String.prototype.repeat.call({}, 1)); |
| 40 |
|
| 41 |
assertEquals("000", String.prototype.repeat.apply(0, [3])); |
| 42 |
assertEquals("-1-1-1", String.prototype.repeat.apply(-1, [3])); |
| 43 |
assertEquals("2.12.12.1", String.prototype.repeat.apply(2.1, [3])); |
| 44 |
assertEquals("", String.prototype.repeat.apply([], [3])); |
| 45 |
assertEquals("1,2,3", String.prototype.repeat.apply([1, 2, 3], [1])); |
| 46 |
assertEquals("true", String.prototype.repeat.apply(true, [1])); |
| 47 |
assertEquals("false", String.prototype.repeat.apply(false, [1])); |
| 48 |
assertEquals("[object Object]", String.prototype.repeat.apply({}, [1])); |
| 49 |
|
| 50 |
assertEquals("\u10D8\u10D8\u10D8", "\u10D8".repeat(3)); |
| 51 |
|
| 52 |
assertThrows('String.prototype.repeat.call(null, 1)', TypeError); |
| 53 |
assertThrows('String.prototype.repeat.call(undefined, 1)', TypeError); |
| 54 |
assertThrows('String.prototype.repeat.apply(null, [1])', TypeError); |
| 55 |
assertThrows('String.prototype.repeat.apply(undefined, [1])', TypeError); |
| 56 |
|
| 57 |
|
| 58 |
assertEquals("abc", "abc".repeat(1)); |
| 59 |
assertEquals("abcabc", "abc".repeat(2)); |
| 60 |
assertEquals("abcabcabc", "abc".repeat(3)); |
| 61 |
assertEquals("aaaaaaaaaa", "a".repeat(10)); |
| 62 |
assertEquals("", "".repeat(5)); |
| 63 |
assertEquals("", "abc".repeat(0)); |
| 64 |
assertEquals("abcabc", "abc".repeat(2.0)); |
| 65 |
|
| 66 |
assertEquals("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a".repeat(37)); |
| 67 |
assertThrows('"a".repeat(-1)', RangeError); |
| 68 |
assertThrows('"a".repeat(Number.POSITIVE_INFINITY)', RangeError); |
| 69 |
assertThrows('"a".repeat(Infinity)', RangeError); |
| 70 |
assertThrows('"a".repeat(+Infinity)', RangeError); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
var myobj = { |
| 76 |
toString: function() { |
| 77 |
return "abc"; |
| 78 |
}, |
| 79 |
repeat : String.prototype.repeat |
| 80 |
}; |
| 81 |
assertEquals("abc", myobj.repeat(1)); |
| 82 |
assertEquals("abcabc", myobj.repeat(2)); |
| 83 |
|
| 84 |
"success"; |