<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.2_T2</p>
<div id='console'></div>
<script>
try {

/**
 * @name: S7.6_A2.2_T2;
 * @section: 7.6;
 * @assertion: IdentifierPart :: UnicodeCombiningMark (any character in the Unicode categories "Mn", "Mc");
 * @description: UnicodeCombiningMark :: Combining spacing mark (Mc).
 * Complex test with eval;
*/

//CHECK
Mc = [[0x0903, 0x0903], [0x093E, 0x0940], [0x0949, 0x094C], [0x0982, 0x0983], [0x09BE, 0x09C0], [0x09C7, 0x09C8], [0x09CB, 0x09CC], [0x09D7, 0x09D7], [0x0A3E, 0x0A40], [0x0A83, 0x0A83], [0x0ABE, 0x0AC0], [0x0AC9, 0x0AC9], [0x0ACB, 0x0ACC], [0x0B02, 0x0B03], [0x0B3E, 0x0B3E], [0x0B40, 0x0B40], [0x0B47, 0x0B48], [0x0B4B, 0x0B4C], [0x0B57, 0x0B57], [0x0B83, 0x0B83], [0x0BBE, 0x0BBF], [0x0BC1, 0x0BC2], [0x0BC6, 0x0BC8], [0x0BCA, 0x0BCC], [0x0BD7, 0x0BD7], [0x0C01, 0x0C03], [0x0C41, 0x0C44], [0x0C82, 0x0C83], [0x0CBE, 0x0CBE], [0x0CC0, 0x0CC4], [0x0CC7, 0x0CC8], [0x0CCA, 0x0CCB], [0x0CD5, 0x0CD6], [0x0D02, 0x0D03], [0x0D3E, 0x0D40], [0x0D46, 0x0D48], [0x0D4A, 0x0D4C], [0x0D57, 0x0D57], [0x0F3E, 0x0F3F], [0x0F7F, 0x0F7F]];

errorCount = 0;
count = 0;
for (indexI = 0; indexI < Mc.length; indexI++) {
  for (indexJ = Mc[indexI][0]; indexJ <= Mc[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>
