File indexing completed on 2024-04-28 15:28:39
0001 /* Copyright (C) 2019 froglogic GmbH */ 0002 0003 // length property 0004 shouldBe("String.prototype.repeat.length", "1"); 0005 0006 // basic usage 0007 shouldBe("''.repeat(1)", "''"); 0008 shouldBe("'ab'.repeat(0)", "''"); 0009 shouldBe("'ab'.repeat(1)", "'ab'"); 0010 shouldBe("'ab'.repeat(1.2)", "'ab'"); 0011 shouldBe("'ab'.repeat(1.9)", "'ab'"); 0012 shouldBe("'ab'.repeat(2)", "'abab'"); 0013 shouldBe("'ab'.repeat()", "''"); 0014 shouldBe("'ab'.repeat(NaN)", "''"); 0015 0016 // generic applications 0017 shouldBe("String.prototype.repeat.call(true, 2)", "'truetrue'"); 0018 shouldBe("String.prototype.repeat.call(1, 2)", "'11'"); 0019 shouldBe("String.prototype.repeat.call({toString: function() { return 'XY' }}, 2)", "'XYXY'"); 0020 shouldBe("String.prototype.repeat.call(/a/, 2)", "'/a//a/'"); 0021 0022 // error cases 0023 shouldExcept(RangeError, function() { 'a'.repeat(Infinity); }, "Infinite repeat"); 0024 shouldExcept(RangeError, function() { 'a'.repeat(-1); }, "-1 repeat"); 0025 shouldExcept(RangeError, function() { 'a'.repeat(-Infinity); }, "-Infinite repeat"); 0026 shouldExcept(TypeError, function() { String.prototype.repeat.call(undefined, 1) }, "Repeat undefined"); 0027 shouldExcept(TypeError, function() { String.prototype.repeat.call(null, 1) }, "Repeat null"); 0028 shouldExcept(TypeError, function() { String.prototype.repeat.call({toString: undefined}, 2) }, "Failed toObject()");