blob: 5b7aacbb953c906c86ccae1cbe1cb3eb7ee15614 [file] [log] [blame]
<html>
<head>
<meta charset='utf-8'>
<style>
.pass {
font-weight: bold;
color: green;
}
.fail {
font-weight: bold;
color: red;
}
</style>
<script>
if (window.testRunner)
testRunner.dumpAsText();
function SputnikError(message)
{
this.message = message;
}
SputnikError.prototype.toString = function ()
{
return 'SputnikError: ' + this.message;
};
var sputnikException;
function testPrint(msg)
{
var span = document.createElement("span");
document.getElementById("console").appendChild(span); // insert it first so XHTML knows the namespace
span.innerHTML = msg + '<br />';
}
function escapeHTML(text)
{
return text.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;");
}
function printTestPassed(msg)
{
testPrint('<span><span class="pass">PASS</span> ' + escapeHTML(msg) + '</span>');
}
function printTestFailed(msg)
{
testPrint('<span><span class="fail">FAIL</span> ' + escapeHTML(msg) + '</span>');
}
function testFailed(msg)
{
throw new SputnikError(msg);
}
var successfullyParsed = false;
</script>
</head>
<body>
<p>S12.2_A1</p>
<div id='console'></div>
<script>
try {
/**
* @name: S12.2_A1;
* @section: 12.2;
* @assertion: Variables are created when the program is entered. Variables are initialised to "undefined"
* when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the
* VariableStatement is executed, not when the variable is created;
* @description: Creating variables after entering the execution scope;
*/
//////////////////////////////////////////////////////////////////////////////
//CHECK#1
try {
__x = __x;
__y = __x ? "good fellow" : "liar"; // __y assigned to "liar" since __x undefined
__z = __z === __x ? 1 : 0; // __z assigned to 1 since both __x and __z are undefined
} catch (e) {
testFailed('#1: Using declarated variable before it declaration is admitted');
}
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//CHECK#2
try{
__something__undefined = __something__undefined;
testFailed('#2: "__something__undefined = __something__undefined" lead to throwing exception');
} catch(e){
testPrint(e.message);
}
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//CHECK#3
if ((__y !== "liar")&(__z !== 1)) {
testFailed('#3: (__y === "liar") and (__z === 1). Actual: __y ==='+__y+' and __z ==='+__z );
}
//
//////////////////////////////////////////////////////////////////////////////
var __x, __y = true, __z = __y ? "smeagol" : "golum";
//////////////////////////////////////////////////////////////////////////////
//CHECK#4
if (!__y&!(__z = "smeagol")) {
testFailed('#4: A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed');
}
//
//////////////////////////////////////////////////////////////////////////////
} catch (ex) {
sputnikException = ex;
}
var successfullyParsed = true;
</script>
<script>
if (!successfullyParsed)
printTestFailed('successfullyParsed is not set');
else if (sputnikException)
printTestFailed(sputnikException);
else
printTestPassed("");
testPrint('<br /><span class="pass">TEST COMPLETE</span>');
</script>
</body>
</html>