mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-31 21:30:58 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
	
		
			721 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
	
		
			721 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| test("basic functionality", () => {
 | |
|   expect(JSON.parse).toHaveLength(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 => {
 | |
|     expect(JSON.parse(testCase[0])).toEqual(testCase[1]);
 | |
|   });
 | |
| });
 | |
| 
 | |
| test("syntax errors", () => {
 | |
|   [
 | |
|     undefined,
 | |
|     NaN,
 | |
|     -NaN,
 | |
|     Infinity,
 | |
|     -Infinity,
 | |
|     '{ "foo" }',
 | |
|     '{ foo: "bar" }',
 | |
|     "[1,2,3,]",
 | |
|     "[1,2,3, ]",
 | |
|     '{ "foo": "bar",}',
 | |
|     '{ "foo": "bar", }',
 | |
|   ].forEach(test => {
 | |
|     expect(() => {
 | |
|       JSON.parse(test);
 | |
|     }).toThrow(SyntaxError);
 | |
|   });
 | |
| });
 | 
