var template = { html : "<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">\n<html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" >\n  <head>\n    <meta http-equiv=\"Content-Type\" content=\"text\/html; charset=iso-8859-1\" \/>\n    <title>Run All JS\/\/RUnit Tests<\/title>\n  <\/head>\n\n  <body onload='displayTests()'>\n \n    <div>\n      <h3>js_runit 0.1 (Test Results)<\/h3>\n \n      <div id=\"testDisplayOutput\">Some Error Occurred!<\/div>\n \n      <div><p><\/p><\/div>\n \n      <div>Refresh browser to run test again.<\/div>\n \n      <div id=\"parent\"><\/div>\n \n    <\/div>\n \n  <\/body>\n<\/html>\n ", javascript : "function newTestRegistry() {\n    var TestRegistry = new Object;\n    TestRegistry.registryArray = new Array();\n \n    TestRegistry.AddTest = function(theTest) {\n        this.registryArray[this.registryArray.length] = theTest;\n    }\n    return TestRegistry;\n}\n \nvar registry = newTestRegistry();\n \nfunction displayTests() {\n    document.getElementById('testDisplayOutput').innerHTML = DisplayAndRunAllTests();\n}\n \nfunction newTestDisplay() {\n    var TestDisplay = new Object;\n    TestDisplay.TestCount = 0;\n    TestDisplay.CheckCount = 0;\n    TestDisplay.TestsPass = true;\n    TestDisplay.OutputBuffer = \"\";\n \n    TestDisplay.SetUp = function() {\n        this.TestCount = 0;\n        this.CheckCount = 0;\n        this.TestsPass = true;\n        this.OutputBuffer = \"\";\n    }\n \n    TestDisplay.LogFatalError = function(TestCaseName) {\n        this.TestsPass = false;\n        this.OutputBuffer += \"<LI style=\\\"color: red; font-weight: bold\\\">\";\n        this.OutputBuffer += \"Fatal Error in \" + TestCaseName;\n        this.OutputBuffer += \"<\/LI>\\n\";\n    }\n \n    TestDisplay.IncrementTestCounter = function() {\n        this.TestCount++;\n    }\n \n    TestDisplay.LogPassingAssertion = function(CaseName, TestTitle) {\n        \/\/this.OutputBuffer += \"<LI style=\\\"color: green\\\">\";\n        \/\/this.OutputBuffer += TestTitle + \": Passed. \" + \"(\" + CaseName + \")\";\n        \/\/this.OutputBuffer += \"<\/LI>\\n\";\n        this.CheckCount++;\n    }\n \n    TestDisplay.LogFailingAssertion = function(CaseName, TestTitle) {\n        this.TestsPass = false;\n        this.OutputBuffer += \"<div>\";\n        if(TestTitle) {\n            this.OutputBuffer += TestTitle + \" --> \";\n        }\n        this.OutputBuffer += \"Failed: \" + \"<b style=\\\"color: red\\\">\" + CaseName + \"<\/b>\";\n        this.OutputBuffer += \"<\/div>\\n\";\n    }\n \n    TestDisplay.LogFailingEqualsAssertion = function(CaseName, Expected, Actual, TestTitle) {\n        this.TestsPass = false;\n        this.OutputBuffer += \"<div>\";\n        if(TestTitle) {\n            this.OutputBuffer += TestTitle + \" --> \";\n        }\n        this.OutputBuffer += \"Failed: \" + \"<b style=\\\"color: red\\\">\" + CaseName + \"<\/b>\";\n        this.OutputBuffer += \"<ul>\\n\";\n        this.OutputBuffer += \"<li>\";\n        this.OutputBuffer += \"Expected: &nbsp;\" + Expected;\n        this.OutputBuffer += \"<\/li>\\n\";\n        this.OutputBuffer += \"<li>\";\n        this.OutputBuffer += \"Actual :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\" + Actual;\n        this.OutputBuffer += \"<\/li>\\n\";\n        this.OutputBuffer += \"<\/ul>\\n\";\n        this.OutputBuffer += \"<\/div>\\n\";\n    }\n \n    TestDisplay.LogErrorException = function(caseName, exception) {\n        this.TestsPass = false;\n        this.OutputBuffer += '<span>Error: ' + \"<b style=\\\"color: red\\\">\" + caseName + \"<\/b><\/span>\";\n        this.OutputBuffer += \"<ul>\\n\";\n        this.OutputBuffer += \"<li>\";\n        this.OutputBuffer += exception.message;\n        this.OutputBuffer += \"<\/li>\\n\";\n        this.OutputBuffer += \"<li>\";\n        this.OutputBuffer += 'File: ' + exception.fileName;\n        this.OutputBuffer += \"<\/li>\\n\";\n        this.OutputBuffer += \"<li>\";\n        this.OutputBuffer += '@ Line: ' + exception.lineNumber;\n        this.OutputBuffer += \"<\/li>\\n\";\n        this.OutputBuffer += \"<\/ul>\\n\";\n    }\n \n    TestDisplay.logTraceMessage = function(caseName, message) {\n        this.OutputBuffer += '<span>Trace: ' + \"<b>\" + caseName + \"<\/b><\/span>\\n\";\n        this.OutputBuffer += \"<ul>\\n\";\n        this.OutputBuffer += \"<li>\\n\";\n        this.OutputBuffer += \"<b>\" + message + \"<\/b>\\n\";\n \n        this.OutputBuffer += \"<\/li>\\n\";\n        this.OutputBuffer += \"<\/ul>\\n\";\n \n    }\n \n    TestDisplay.Output = function() {\n        if(this.TestsPass){\n            this.OutputBuffer += \"<h2 style=\\\"color: green\\\">Pass<\/h2>\\n\";\n            this.OutputBuffer += \"<span style=\\\"color: green\\\">Test count: \" + this.TestCount +\n                \", Check count: \" + this.CheckCount + \"<\/span>\\n\";\n        } else {\n            this.OutputBuffer += \"<h2 style=\\\"color: red\\\">Fail<\/h2>\\n\";\n        }\n        return this.OutputBuffer;\n    }\n    return TestDisplay;\n}\n \nfunction should(testName) {\n\/\/need to figure out how to change to remove duplicatiion\n \n    var Test = new Object;\n    Test.name = testName;\n    registry.AddTest(Test);\n \n    Test.setUpDisplay = function(TestDisplay) {\n        this.TestDisplay = TestDisplay;\n    }\n \n    Test.executeWithCatch = function() {\n        try {\n            this.test();\n        }\n        catch(e) {\n            this.TestDisplay.LogErrorException(this.name, e);\n        }\n    }\n \n    Test.test = function() {}\n \n    Test.tearDown = function() {\n        this.TestDisplay.IncrementTestCounter();\n    }\n \n    Test.TestCount = function() {return 1;}\n \n    Test.assert = function(Test, Title) {\n        if (Test) {\n            this.TestDisplay.LogPassingAssertion(this.name, Title);\n        } else {\n            this.TestDisplay.LogFailingAssertion(this.name, Title);\n        }\n    }\n \n    Test.fail = function(Message) {\n        this.assert((false), Message);\n    }\n    \n    \/\/ Need to change from using the fail to regular output with test banner\n    Test.debugTrace = function(message) {\n        this.TestDisplay.logTraceMessage(this.name, message);\n    }\n \n    Test.is = function(test, title) {\n        this.assert(test, title);\n    }\n \n    Test.isNot = function(test, title) {\n        this.is((test != null), title);\n    }\n \n    Test.isFalse = function(bool, title) {\n        this.isEqual(false, bool, title);\n    }\n \n     Test.isTrue = function(bool, title) {\n        this.isEqual(true, bool, title);\n    }\n \n   Test.isEqual = function(expected, actual, message) {\n        if (expected == actual) {\n            this.TestDisplay.LogPassingAssertion(this.name, message);\n        } else {\n            this.TestDisplay.LogFailingEqualsAssertion(this.name, expected, actual, message);\n        }\n    }\n \n    Test.isNotEqual = function(expected, actual, message) {\n        if (expected != actual) {\n            this.TestDisplay.LogPassingAssertion(this.name, message);\n        } else {\n            this.TestDisplay.LogFailingEqualsAssertion(this.name, expected, actual, message);\n        }\n    }\n \n    return Test;\n \n}\n \nfunction TestRunner(Test, TestDisplay)\n{\n    Test.setUpDisplay(TestDisplay);\n    Test.executeWithCatch();\n    Test.tearDown();\n}\n \nfunction DisplayAndRunAllTests()\n{\n    var thisTestDisplay = newTestDisplay();\n    thisTestDisplay.SetUp();\n    RunAllTests(thisTestDisplay);\n    return thisTestDisplay.Output();\n}\n \nfunction RunAllTests(aTestDisplay)\n{\n    for (var i=0; i < registry.registryArray.length; i++)\n    {\n        TestRunner(registry.registryArray[i], aTestDisplay);\n    }\n}\n \nfunction errorMessage(exception) {\n    return '<p>Error: ' + exception.message + '<\/p>'\n            + '<p>@ Line: ' + exception.lineNumber + '<\/p>';\n}\n\nshould('pass').test = function() {\n    this.is(true, \"A Passing Test\");\n}\n \nshould('isEqual').test = function() {\n    this.isEqual(1, 1, \"A Passing Test\");\n}\n \nshould('isTrue').test = function() {\n    this.isTrue(true, \"A Passing Test\");\n}\n \n \n\/\/failing tests\n\/\/should('is').test = function() {\n\/\/    this.is(null, \"failed is\");\n\/\/}\n \n\/\/should('isEqual').test = function() {\n\/\/    this.isEqual(1, 2, \"failed isEqual\");\n\/\/}\n \n\/\/should('isTrue').test = function() {\n\/\/    this.isTrue(false, \"failed isTrue\");\n\/\/}\n \n\/\/should('exception').test = function() {\n\/\/    this.is(noFunction(), \"error\");\n\/\/}\n " };