-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathUnknownFObjectParserTest.js
More file actions
58 lines (50 loc) · 2.36 KB
/
UnknownFObjectParserTest.js
File metadata and controls
58 lines (50 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @license
* Copyright 2025 The FOAM Authors. All Rights Reserved.
* http://www.apache.org/licenses/LICENSE-2.0
*/
foam.CLASS({
package: 'foam.lib.json',
name: 'UnknownFObjectParserTest',
extends: 'foam.core.test.Test',
javaImports: [
'foam.lib.parse.*'
],
methods: [
{
name: 'runTest',
javaCode: `
// setup parser
var parser = UnknownFObjectParser.instance();
var psx = new ParserContextImpl();
// parse json
var input = "{\\"key\\":\\"value\\",\\"key2\\":true,\\"key3\\":null,\\"key4\\":{\\"foo\\":\\"bar\\"},\\"key5\\":[true,false,null,\\"text\\",1.23]}";
var ps = new StringPStream(input);
ps = (StringPStream) ps.apply(parser, psx);
test ( ps != null && ((UnknownFObject) ps.value()).getJson().equals(input), "Parsed json, input:" + input );
// parse empty json
var input2 = "{}";
ps = new StringPStream(input2);
ps = (StringPStream) ps.apply(parser, psx);
test ( ps != null && ((UnknownFObject) ps.value()).getJson().equals(input2), "Parsed empty json, input:" + input2 );
// parse json with un-quoted key
var input3 = "{key:\\"}\\"}";
ps = new StringPStream(input3);
ps = (StringPStream) ps.apply(parser, psx);
test ( ps != null && ((UnknownFObject) ps.value()).getJson().equals("{\\"key\\":\\"}\\"}"), "Parsed json with un-quoted key, input:" + input3 );
// parse json with comment line before key:value
var input4 = "{//comment1 \\n key:\\"1\\"," + "//comment2 \\n key2:\\"2\\"}";
var input4_print = "{//comment1 \\\\n key:\\"1\\"," + "//comment2 \\\\n key2:\\"2\\"}";
ps = new StringPStream(input4);
ps = (StringPStream) ps.apply(parser, psx);
test ( ps != null && ((UnknownFObject) ps.value()).getJson().equals("{\\"key\\":\\"1\\",\\"key2\\":\\"2\\"}"), "Parsed json with comment above properties, input:" + input4_print );
// parse empty json with just comments
var input5 = "{// comment1 \\n // comment2 \\n}";
var input5_print = "{// comment1 \\\\n // comment2 \\\\n}";
ps = new StringPStream(input5);
ps = (StringPStream) ps.apply(parser, psx);
test ( ps != null && ((UnknownFObject) ps.value()).getJson().equals("{}"), "Parsed empty json with just comment, input:" + input5_print );
`
}
]
});