Replace runTestCase with assert helpers [test/built-ins/JSON]

This commit is contained in:
André Bargull 2015-08-06 18:25:42 +02:00
parent bec8782918
commit 8ea6a7e374
34 changed files with 64 additions and 195 deletions

View File

@ -8,13 +8,8 @@ info: >
4.2 calls out JSON as one of the built-in objects.
es5id: 15.12-0-1
description: JSON must be a built-in object
includes: [runTestCase.js]
---*/
function testcase() {
var o = JSON;
if (typeof(o) === "object") {
return true;
}
}
runTestCase(testcase);
assert.sameValue(typeof(o), "object", 'typeof(o)');

View File

@ -10,18 +10,13 @@ info: >
JSON, and we should not be able to enumerate them.
es5id: 15.12-0-4
description: JSON object's properties must be non enumerable
includes: [runTestCase.js]
---*/
function testcase() {
var o = JSON;
var i = 0;
for (var p in o) {
i++;
}
if (i === 0) {
return true;
}
}
runTestCase(testcase);
assert.sameValue(i, 0, 'i');

View File

@ -4,16 +4,10 @@
/*---
es5id: 15.12.1.1-0-9
description: Whitespace characters can appear before/after any JSONtoken
includes: [runTestCase.js]
---*/
function testcase() {
JSON.parse('\t\r \n{\t\r \n'+
'"property"\t\r \n:\t\r \n{\t\r \n}\t\r \n,\t\r \n' +
'"prop2"\t\r \n:\t\r \n'+
'[\t\r \ntrue\t\r \n,\t\r \nnull\t\r \n,123.456\t\r \n]'+
'\t\r \n}\t\r \n'); // should JOSN parse without error
return true;
}
runTestCase(testcase);

View File

@ -15,14 +15,8 @@ info: >
taking 2 parameters.
es5id: 15.12.2-0-1
description: JSON.parse must exist as a function
includes: [runTestCase.js]
---*/
function testcase() {
var f = JSON.parse;
if (typeof(f) === "function") {
return true;
}
}
runTestCase(testcase);
assert.sameValue(typeof(f), "function", 'typeof(f)');

View File

@ -15,14 +15,9 @@ info: >
taking 2 parameters.
es5id: 15.12.2-0-2
description: JSON.parse must exist as a function taking 2 parameters
includes: [runTestCase.js]
---*/
function testcase() {
var f = JSON.parse;
if (typeof(f) === "function" && f.length === 2) {
return true;
}
}
runTestCase(testcase);
assert.sameValue(typeof(f), "function", 'typeof(f)');
assert.sameValue(f.length, 2, 'f.length');

View File

@ -8,12 +8,9 @@ info: >
should be able to delete (8.6.2.5) the stringify and parse properties.
es5id: 15.12.2-0-3
description: JSON.parse must be deletable (configurable)
includes: [runTestCase.js]
---*/
function testcase() {
var o = JSON;
var desc = Object.getOwnPropertyDescriptor(o, "parse");
return desc.configurable === true;
}
runTestCase(testcase);
assert.sameValue(desc.configurable, true, 'desc.configurable');

View File

@ -15,14 +15,8 @@ info: >
taking 3 parameters.
es5id: 15.12.3-0-1
description: JSON.stringify must exist as be a function
includes: [runTestCase.js]
---*/
function testcase() {
var f = JSON.stringify;
if (typeof(f) === "function") {
return true;
}
}
runTestCase(testcase);
assert.sameValue(typeof(f), "function", 'typeof(f)');

View File

@ -15,14 +15,9 @@ info: >
taking 3 parameters.
es5id: 15.12.3-0-2
description: JSON.stringify must exist as be a function taking 3 parameters
includes: [runTestCase.js]
---*/
function testcase() {
var f = JSON.stringify;
if (typeof(f) === "function" && f.length === 3) {
return true;
}
}
runTestCase(testcase);
assert.sameValue(typeof(f), "function", 'typeof(f)');
assert.sameValue(f.length, 3, 'f.length');

View File

@ -8,14 +8,9 @@ info: >
should be able to delete (8.6.2.5) the stringify and parse properties.
es5id: 15.12.3-0-3
description: JSON.stringify must be deletable (configurable)
includes: [runTestCase.js]
---*/
function testcase() {
var o = JSON;
var desc = Object.getOwnPropertyDescriptor(o, "stringify");
if (desc.configurable === true) {
return true;
}
}
runTestCase(testcase);
assert.sameValue(desc.configurable, true, 'desc.configurable');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property name is the
union of all null character (The abstract operation Quote(value)
step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F": "John" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property name starts
with the union of all null character (The abstract operation
Quote(value) step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001Fname": "John" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property name ends
with the union of all null character (The abstract operation
Quote(value) step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "name\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F": "John" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property name starts
and ends with the union of all null character (The abstract
operation Quote(value) step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001Fname\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F": "John" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1 && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property name
middles with the union of all null character (The abstract
operation Quote(value) step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "na\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001Fme": "John" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property value is
the union of all null character (The abstract operation
Quote(value) step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "name": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property value
starts with the union of all null character (The abstract
operation Quote(value) step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "name": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001FJohn" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property value ends
with the union of all null character (The abstract operation
Quote(value) step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "name": "John\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property value
starts and ends with the union of all null character (The abstract
operation Quote(value) step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "name": "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001FJohn\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1 && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -7,11 +7,8 @@ description: >
JSON.stringify - stringifying an object where property value
middles with the union of all null character (The abstract
operation Quote(value) step 2.c)
includes: [runTestCase.js]
---*/
function testcase() {
var result = true;
var expectedNullChars = new Array();
@ -53,6 +50,5 @@ function testcase() {
var str = JSON.stringify({ "name": "Jo\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001Fhn" });
result = (result && str.indexOf(expectedNullChars[index]) !== -1 && str.indexOf(expectedNullChars[index]) !== -1);
}
return result;
}
runTestCase(testcase);
assert(result, 'result !== true');

View File

@ -6,16 +6,13 @@ es5id: 15.12.3-11-26
description: >
JSON.stringify - the last element of the concatenation is ']' (The
abstract operation JA(value) step 10.b.iii)
includes: [runTestCase.js]
---*/
function testcase() {
var arrObj = [];
arrObj[0] = "a";
arrObj[1] = "b";
arrObj[2] = "c";
var jsonText = JSON.stringify(arrObj, undefined, "").toString();
return jsonText.charAt(jsonText.length - 1) === "]";
}
runTestCase(testcase);
assert.sameValue(jsonText.charAt(jsonText.length - 1), "]", 'jsonText.charAt(jsonText.length - 1)');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-5-a-i-1
description: >
JSON.stringify converts Number wrapper object space aruguments to
Number values
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj,null, new Number(5))=== JSON.stringify(obj,null, 5);
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj,null, new Number(5)), JSON.stringify(obj,null, 5), 'JSON.stringify(obj,null, new Number(5))');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-5-b-i-1
description: >
JSON.stringify converts String wrapper object space aruguments to
String values
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj,null, new String('xxx'))=== JSON.stringify(obj,null, 'xxx');
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj,null, new String('xxx')), JSON.stringify(obj,null, 'xxx'), 'JSON.stringify(obj,null, new String("xxx"))');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-6-a-1
description: >
JSON.stringify treats numeric space arguments greater than 10 the
same as a space argument of 10.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj,null, 10)=== JSON.stringify(obj,null, 100);
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj,null, 10), JSON.stringify(obj,null, 100), 'JSON.stringify(obj,null, 10)');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-6-a-2
description: >
JSON.stringify truccates non-integer numeric space arguments to
their integer part.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj,null, 5.99999)=== JSON.stringify(obj,null, 5);
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj,null, 5.99999), JSON.stringify(obj,null, 5), 'JSON.stringify(obj,null, 5.99999)');

View File

@ -6,13 +6,10 @@ es5id: 15.12.3-6-b-4
description: >
JSON.stringify treats numeric space arguments (in the range 1..10)
is equivalent to a string of spaces of that length.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
var fiveSpaces = ' ';
// '12345'
return JSON.stringify(obj,null, 5)=== JSON.stringify(obj, null, fiveSpaces);
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj,null, 5), JSON.stringify(obj, null, fiveSpaces), 'JSON.stringify(obj,null, 5)');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-7-a-1
description: >
JSON.stringify only uses the first 10 characters of a string space
arguments.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj,null, '0123456789xxxxxxxxx')=== JSON.stringify(obj,null, '0123456789');
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj,null, '0123456789xxxxxxxxx'), JSON.stringify(obj,null, '0123456789'), 'JSON.stringify(obj,null, "0123456789xxxxxxxxx")');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-8-a-1
description: >
JSON.stringify treats an empty string space argument the same as a
missing space argument.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj)=== JSON.stringify(obj,null, '');
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj), JSON.stringify(obj,null, ''), 'JSON.stringify(obj)');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-8-a-2
description: >
JSON.stringify treats an Boolean space argument the same as a
missing space argument.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj)=== JSON.stringify(obj,null, true);
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj), JSON.stringify(obj,null, true), 'JSON.stringify(obj)');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-8-a-3
description: >
JSON.stringify treats an null space argument the same as a missing
space argument.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj)=== JSON.stringify(obj,null, null);
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj), JSON.stringify(obj,null, null), 'JSON.stringify(obj)');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-8-a-4
description: >
JSON.stringify treats an Boolean wrapper space argument the same
as a missing space argument.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj)=== JSON.stringify(obj,null, new Boolean(true));
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj), JSON.stringify(obj,null, new Boolean(true)), 'JSON.stringify(obj)');

View File

@ -6,11 +6,8 @@ es5id: 15.12.3-8-a-5
description: >
JSON.stringify treats non-Number or String object space arguments
the same as a missing space argument.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {a1: {b1: [1,2,3,4], b2: {c1: 1, c2: 2}},a2: 'a2'};
return JSON.stringify(obj)=== JSON.stringify(obj,null, obj);
}
runTestCase(testcase);
assert.sameValue(JSON.stringify(obj), JSON.stringify(obj,null, obj), 'JSON.stringify(obj)');

View File

@ -6,14 +6,11 @@ es5id: 15.12.3_2-2-b-i-1
description: >
JSON.stringify converts string wrapper objects returned from a
toJSON call to literal strings.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {
prop:42,
toJSON: function () {return 'fortytwo objects'}
};
return JSON.stringify([obj]) === '["fortytwo objects"]';
}
runTestCase(testcase);
assert.sameValue(JSON.stringify([obj]), '["fortytwo objects"]', 'JSON.stringify([obj])');

View File

@ -6,14 +6,11 @@ es5id: 15.12.3_2-2-b-i-2
description: >
JSON.stringify converts Number wrapper objects returned from a
toJSON call to literal Number.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {
prop:42,
toJSON: function () {return new Number(42)}
};
return JSON.stringify([obj]) === '[42]';
}
runTestCase(testcase);
assert.sameValue(JSON.stringify([obj]), '[42]', 'JSON.stringify([obj])');

View File

@ -6,14 +6,11 @@ es5id: 15.12.3_2-2-b-i-3
description: >
JSON.stringify converts Boolean wrapper objects returned from a
toJSON call to literal Boolean values.
includes: [runTestCase.js]
---*/
function testcase() {
var obj = {
prop:42,
toJSON: function () {return new Boolean(true)}
};
return JSON.stringify([obj]) === '[true]';
}
runTestCase(testcase);
assert.sameValue(JSON.stringify([obj]), '[true]', 'JSON.stringify([obj])');