File indexing completed on 2024-04-28 15:28:37
0001 // We can't use normal shouldBe here, since they'd eval in the wrong context... 0002 function shouldBeOfType(msg, val, type) { 0003 if (typeof(val) != type) 0004 testFailed(msg + ": value has type " + typeof(val) + " , not:" + type); 0005 else 0006 testPassed(msg); 0007 } 0008 0009 function shouldBeVal(msg, val, expected) { 0010 if (val != expected) 0011 testFailed(msg + ": value is " + val + " , not:" + expected); 0012 else 0013 testPassed(msg); 0014 } 0015 0016 f = "global"; 0017 0018 function test() { 0019 try { 0020 shouldBeOfType("Function declaration takes effect at entry", f, "function"); 0021 } 0022 catch (e) { 0023 testFailed("Scoping very broken!"); 0024 } 0025 0026 for (var i = 0; i < 3; ++i) { 0027 if (i == 0) 0028 shouldBeOfType("Decl not yet overwritten", f, 'function'); 0029 else 0030 shouldBeOfType("Decl already overwritten", f, 'number'); 0031 0032 f = 3; 0033 shouldBeVal("After assign ("+i+")", f, 3); 0034 0035 function f() {}; 0036 shouldBeVal("function decls have no execution content", f, 3); 0037 0038 f = 5; 0039 0040 shouldBeVal("After assign #2 ("+i+")", f, 5); 0041 } 0042 } 0043 0044 test();