json-test.js revision b40f5113b5f28daabc29b6ad49c905f290cf6cb7
'"url": "http://www.JSON.org/",' +
'"\\/\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?" : "A key can be any string"' +
function addTests() {
_should : {
error : {
test_failOnEmptyString : true,
test_failOnFunction : true,
test_failOnRegex : true,
test_failOnNew : true,
test_failOnUnquotedVal : true,
test_failOnUnquotedKey : true,
test_failOnUnclosedObject : true,
test_failOnUnclosedArray : true,
test_failOnExtraCommaInObject : true,
test_failOnExtraCommaInArray : true,
test_failOnMissingValue : true,
test_failOnCommaAfterClose : true,
test_failOnValueAfterClose : true,
test_failOnExtraClose : true,
test_failOnExpression : true,
test_failOnZeroPrefixedNumber : true,
test_failOnHex : true,
test_failOnMissingColon : true,
test_failOnDoubleColon : true,
test_failOnCommaInsteadOfColon : true,
test_failOnColonInsteadOfComma : true,
test_failOnSingleQuote : true,
test_failOnTabCharacter : true,
test_failOnLineBreakChar : true,
test_failOnMismatchedClose : true
test_emptyObject : function () {
test_emptyArray : function () {
test_JSONNatives : function () {
var data = Y.JSON.parse('{"obj":{},"arr":[],"f":false,"t":true,"n":null,"int":12345,"fl":1.2345,"str":"String\\nwith\\tescapes"}');
test_basics : function () {
Y.Assert.areSame("A key can be any string",data[8]["\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"]);
test_nonObjectWrapper : function () {
//Y.Assert.areSame('this is a string',Y.JSON.parse('"this is a string"'));
//Y.Assert.areSame(true,Y.JSON.parse('true'));
//Y.Assert.areSame(12345,Y.JSON.parse("12345"));
//Y.Assert.areSame(1.2345,Y.JSON.parse("1.2345"));
test_failOnEmptyString : function () {
test_failOnFunction : function () {
test_failOnRegex : function () {
test_failOnNew : function () {
test_failOnUnquotedVal : function () {
test_failOnUnquotedKey : function () {
test_failOnUnclosedObject : function () {
test_failOnUnclosedArray : function () {
test_failOnExtraCommaInObject : function () {
test_failOnDoubleExtraCommaInObject : function () {
test_failOnExtraCommaInArray : function () {
test_failOnDoubleExtraCommaInArray : function () {
test_failOnMissingValue : function () {
Y.log("Parsed array with missing value ("+data[0]+"), but should have failed.","warn","TestRunner");
test_failOnCommaAfterClose : function () {
test_failOnValueAfterClose : function () {
test_failOnExtraClose : function () {
test_failOnExpression : function () {
test_failOnZeroPrefixedNumber : function () {
test_failOnHex : function () {
test_failOnIllegalBackslashEscape : function () {
test_failOnMissingColon : function () {
test_failOnDoubleColon : function () {
test_failOnCommaInsteadOfColon : function () {
test_failOnColonInsteadOfComma : function () {
test_failOnSingleQuote : function () {
test_failOnLineBreakChar : function () {
test_failOnMismatchedClose : function () {
_should : {
error : {
test_failOnStringifyCyclicalRef1 : true,
test_failOnStringifyCyclicalRef2 : true,
setUp: function () {
'<button id="button_submit_with_value" type="submit" value="submit button value">content and value</button>' +
tearDown: function () {
test_stringifyNatives: function () {
Y.Assert.areSame('[true,false,null,-0.12345,"string",{"object with one member":["array with one element"]}]',
Y.JSON.stringify([true,false,null,-0.12345,"string",{"object with one member":["array with one element"]}]));
test_stringifyObject : function () {
Y.Assert.areSame('{"one":1,"two":true,"three":false,"four":null,"five":"String with\\nnewline","six":{"nested":-0.12345}}',
Y.JSON.stringify({one:1,two:true,three:false,four:null,five:"String with\nnewline",six : {nested:-0.12345}}));
test_failOnStringifyCyclicalRef1 : function () {
o.recurse = o;
test_failOnStringifyCyclicalRef2 : function () {
test_failOnStringifyCyclicalRef3 : function () {
test_stringifyFunction : function () {
arr : [ function () {} ]
test_stringifyRegex : function () {
test_stringifyUndefined : function () {
test_stringifyDate : function () {
test_stringifyFormValue : function () {
var data = {
test_emptyWhitelistArray : function () {
foo : false,
test_whitelistArray : function () {
foo : [
baz : true
baz : true
foo : [
baz : true
bar : [
baz : true
Y.JSON.stringify({
test_falseyIndents : function () {
Y.JSON.stringify({
test_indentNumber : function () {
test_indentString : function () {
test_reviver : function () {
test_toJSON_on_object: function () {
test_toJSON_on_proto: function () {
B.prototype = new A();
C.prototype = new B();
test_replacer : function () {
toUpper: true,
obj: {
return undefined;
delete this.toUpper;
return v.toUpperCase();
Y.Assert.areSame("{\n_\"num\": 2,\n_\"alpha\": \"ABC\",\n_\"obj\": {\n__\"nested_num\": 100,\n__\"alpha\": \"abc\"\n_},\n_\"arr\": [\n__2,\n__null,\n__4\n_]\n}",
toUpper: true,
obj: {
return undefined;
delete this.toUpper;
return v.toUpperCase();
test_replacer_after_toJSON : function () {
test_replacer_returning_Date : function () {
test_disableNative : function () {
addTests();
test_reenableNative : function () {
addTests();