Browse Source

testcase for an 'string repeat' idiom

pull/1/head
Sami Vaarala 11 years ago
parent
commit
f4ea9e2268
  1. 37
      ecmascript-testcases/test-dev-array-rep-trick.js

37
ecmascript-testcases/test-dev-array-rep-trick.js

@ -0,0 +1,37 @@
/*===
10 x
10 y
100000 x
100000 y
===*/
/* String repeat can be implemented with an array join. */
function dump(x) {
var ch = '?'
if (x.length > 0) {
ch = x.charAt(0);
for (var i = 0; i < x.length; i++) {
if (x.charAt(i) !== ch) {
throw new Error('error in string');
}
}
}
print(x.length, ch);
}
try {
dump(Array.prototype.join.call({ length: 10 + 1 }, 'x'));
var arr = []; arr.length = 10 + 1;
dump(arr.join('y'));
} catch (e) {
print(e);
}
try {
dump(Array.prototype.join.call({ length: 100000 + 1 }, 'x'));
var arr = []; arr.length = 100000 + 1;
dump(arr.join('y'));
} catch (e) {
print(e);
}
Loading…
Cancel
Save