<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>S7.6_A2.3</p>
<div id='console'></div>
<script>
try {

/**
 * @name: S7.6_A2.3;
 * @section: 7.6;
 * @assertion: IdentifierPart :: UnicodeDigit (any character in the Unicode categories "Decimal Number (Nd)".
 * @description: Complex test with eval;
*/

//CHECK
Nd = [[0x0030, 0x0039], [0x0660, 0x0669], [0x06F0, 0x06F9], [0x07C0, 0x07C9], [0x0966, 0x096F], [0x09E6, 0x09EF], [0x0A66, 0x0A6F], [0x0AE6, 0x0AEF], [0x0B66, 0x0B6F], [0x0BE6, 0x0BEF], [0x0C66, 0x0C6F], [0x0CE6, 0x0CEF], [0x0D66, 0x0D6F], [0x0E50, 0x0E59], [0x0ED0, 0x0ED9], [0x0F20, 0x0F29], [0x1040, 0x1049], [0x1090, 0x1099], [0x17E0, 0x17E9], [0x1810, 0x1819], [0x1946, 0x194F], [0x19D0, 0x19D9], [0x1B50, 0x1B59], [0x1BB0, 0x1BB9], [0x1C40, 0x1C49], [0x1C50, 0x1C59], [0xA620, 0xA629], [0xA8D0, 0xA8D9], [0xA900, 0xA909], [0xAA50, 0xAA59], [0xFF10, 0xFF19]];

errorCount = 0;
count = 0;
for (indexI = 0; indexI < Nd.length; indexI++) {
  for (indexJ = Nd[indexI][0]; indexJ <= Nd[indexI][1]; indexJ++) {
    try {
      var identifier = "$" + String.fromCharCode(indexJ);
      var hex = decimalToHexString(indexJ);
      eval("var " + identifier + "=1");
      if (eval(identifier + "===1") !== true) {
        testFailed('#' + hex + ' ');
        errorCount++;
      }
    } catch (e) {
      testFailed('#' + hex + ' ');
      errorCount++;
    }
    count++;
  }
}

if (errorCount > 0) {    
  testFailed('Total error: ' + errorCount + ' bad Unicode character in ' + count);
}

function decimalToHexString(n) {
  n = Number(n);
  var h = "";
  for (var i = 3; i >= 0; i--) {
    if (n >= Math.pow(16, i)) {
      var t = Math.floor(n / Math.pow(16, i));
      n -= t * Math.pow(16, i);
      if ( t >= 10 ) {
        if ( t == 10 ) { h += "A"; }
        if ( t == 11 ) { h += "B"; }
        if ( t == 12 ) { h += "C"; }
        if ( t == 13 ) { h += "D"; }
        if ( t == 14 ) { h += "E"; }
        if ( t == 15 ) { h += "F"; }
      } else {
        h += String(t);
      }
    } else {
      h += "0";
    }
  }
  return h;
}

} 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>
