UNPKG

tnetstrings.js

Version:
43 lines (39 loc) 1.33 kB
<!doctype html> <html> <head> <script src="tnetstrings.js"></script> </head> <body> <h1>You will see errors here if any</h1> <div id="errors"> </div> <script type="text/javascript"> errors = document.getElementById('errors'); function assert(source, result) { // easiest way to compare objects :( if (JSON.stringify(source) != JSON.stringify(result)) { var p = document.createElement('p'); p.innerHTML = ('Expected one result: ' + JSON.stringify(result) + ', but got another: ' + JSON.stringify(source)); // console.error('Expected one result, but got another ', result, source); errors.appendChild(p); } } TESTS = [ ['0:~', null], ['5:false!', false], ['4:test,', 'test'], ['3:123#', 123], ["16:5:hello,5:12345#}", {hello: 12345}], ["32:5:hello,5:12345#5:hello,5:56789#]", ["hello", 12345, "hello", 56789]], ["9:3.1415926^", 3.1415926], ["19:8:sentence,5:été,}", {sentence: "été"}] ]; for (var i = 0; i < TESTS.length; i++) { assert(tnetstrings.parse(TESTS[i][0]).value, TESTS[i][1]); assert(tnetstrings.dump(TESTS[i][1]), TESTS[i][0]); } console.log('All tests done'); </script> </body> </html>