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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// constant definition
const c = 11;
shouldBe("c", "11");
// attempt to redefine should have no effect
c = 22;
shouldBe("c", "11");
const dummy = 0;
for (var v = 0;;) {
++v;
shouldBe("v", "1");
break;
}
// local vars & consts
function h ()
{
function shouldBe(_a, _b)
{
if (typeof _a != "string" || typeof _b != "string")
debug("WARN: shouldBe() expects string arguments");
var _av, _bv;
try {
_av = eval(_a);
} catch (e) {
_av = evalError(_a, e);
}
try {
_bv = eval(_b);
} catch (e) {
_bv = evalError(_b, e);
}
if (_av === _bv)
testPassed(_a + " is " + _b);
else
testFailed(_a + " should be " + _bv + ". Was " + _av);
}
var hvar = 1;
const hconst = 1;
shouldBe("hvar", "1");
shouldBe("hconst", "1");
hvar = 2;
hconst = 2;
shouldBe("hvar", "2");
shouldBe("hconst", "1");
++hvar;
++hconst;
shouldBe("hvar", "3");
shouldBe("hconst", "1");
shouldBe("(hvar = 4)", "4");
shouldBe("(hconst = 4)", "4");
shouldBe("hvar", "4");
shouldBe("hconst", "1");
}
h();
h();
// ### check for forbidden redeclaration
|