Browse Source

JSON.parse() testcases

pull/1/head
Sami Vaarala 12 years ago
parent
commit
b8a09518b9
  1. 52
      testcases/test-builtin-json-dec-array.js
  2. 19
      testcases/test-builtin-json-dec-empty.js
  3. 26
      testcases/test-builtin-json-dec-whitespace.js

52
testcases/test-builtin-json-dec-array.js

@ -0,0 +1,52 @@
/*===
SyntaxError
===*/
/* Don't allow empty object with just comma */
try {
print(JSON.parse('[,]'));
} catch (e) {
print(e.name);
}
/*===
SyntaxError
===*/
/* Don't allow initial comma */
try {
print(JSON.parse('[,1]'));
} catch (e) {
print(e.name);
}
/*===
SyntaxError
===*/
/* Don't allow trailing comma.
*
* Rhino allows this.
*/
try {
print(JSON.parse('[1,]'));
} catch (e) {
print(e.name);
}
/*===
SyntaxError
===*/
/* Don't allow successive commas (elisions) */
try {
print(JSON.parse('[1,,2]'));
} catch (e) {
print(e.name);
}

19
testcases/test-builtin-json-dec-empty.js

@ -0,0 +1,19 @@
/*===
SyntaxError
SyntaxError
===*/
/* Empty or pure white space is a SyntaxError. */
try {
print(JSON.parse(''));
} catch (e) {
print(e.name);
}
try {
print(JSON.parse(' \n\r\t'));
} catch (e) {
print(e.name);
}

26
testcases/test-builtin-json-dec-whitespace.js

@ -0,0 +1,26 @@
/*===
1
1
SyntaxError
===*/
/* Allow leading and trailing whitespace, but no other garbage */
try {
print(JSON.parse('1'));
} catch (e) {
print(e.name);
}
try {
print(JSON.parse('\t\n 1 \t\n'));
} catch (e) {
print(e.name);
}
try {
print(JSON.parse('1 x'));
} catch (e) {
print(e.name);
}
Loading…
Cancel
Save