mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-19 09:32:52 +00:00
LibJS: Add JSON.parse
This commit is contained in:
parent
e8e728454c
commit
b155e64b67
Notes:
sideshowbarker
2024-07-19 05:40:42 +09:00
Author: https://github.com/mattco98
Commit: b155e64b67
Pull-request: https://github.com/SerenityOS/serenity/pull/2545
Reviewed-by: https://github.com/Dexesttp
Reviewed-by: https://github.com/awesomekling
6 changed files with 218 additions and 5 deletions
43
Libraries/LibJS/Tests/JSON.parse.js
Normal file
43
Libraries/LibJS/Tests/JSON.parse.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(JSON.parse.length === 2);
|
||||
|
||||
const properties = [
|
||||
["5", 5],
|
||||
["null", null],
|
||||
["true", true],
|
||||
["false", false],
|
||||
['"test"', "test"],
|
||||
['[1,2,"foo"]', [1, 2, "foo"]],
|
||||
['{"foo":1,"bar":"baz"}', { foo: 1, bar: "baz" }],
|
||||
];
|
||||
|
||||
properties.forEach(testCase => {
|
||||
assertDeepEquals(JSON.parse(testCase[0]), testCase[1]);
|
||||
});
|
||||
|
||||
let syntaxErrors = [
|
||||
undefined,
|
||||
NaN,
|
||||
-NaN,
|
||||
Infinity,
|
||||
-Infinity,
|
||||
'{ "foo" }',
|
||||
'{ foo: "bar" }',
|
||||
"[1,2,3,]",
|
||||
"[1,2,3, ]",
|
||||
'{ "foo": "bar",}',
|
||||
'{ "foo": "bar", }',
|
||||
];
|
||||
|
||||
syntaxErrors.forEach(error => assertThrowsError(() => {
|
||||
JSON.parse(error);
|
||||
}, {
|
||||
error: SyntaxError,
|
||||
}));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue