OCaml library for JSONfeed parsing and creation
1Location tracking tests for JSON Feed parser
2===========================================
3
4This test suite verifies that jsont combinators correctly track location
5information for both valid and invalid JSON feeds.
6
7Valid Feeds
8-----------
9
10Test minimal valid feed:
11 $ ./test_location_errors.exe data/minimal_valid.json title
12 {"status":"ok","field":"title","value":"Minimal Feed"}
13
14 $ ./test_location_errors.exe data/minimal_valid.json version
15 {"status":"ok","field":"version","value":"https://jsonfeed.org/version/1.1"}
16
17 $ ./test_location_errors.exe data/minimal_valid.json item_count
18 {"status":"ok","field":"item_count","value":"0"}
19
20Test complete feed with all fields:
21 $ ./test_location_errors.exe data/complete_valid.json title
22 {"status":"ok","field":"title","value":"Complete Feed"}
23
24 $ ./test_location_errors.exe data/complete_valid.json item_count
25 {"status":"ok","field":"item_count","value":"1"}
26
27 $ ./test_location_errors.exe data/complete_valid.json first_item_id
28 {"status":"ok","field":"first_item_id","value":"https://example.com/item1"}
29
30Test mixed content types:
31 $ ./test_location_errors.exe data/mixed_content.json item_count
32 {"status":"ok","field":"item_count","value":"3"}
33
34Test feed with extensions:
35 $ ./test_location_errors.exe data/with_extensions.json title
36 {"status":"ok","field":"title","value":"Feed with Extensions"}
37
38
39Missing Required Fields
40------------------------
41
42Test missing title field:
43 $ ./test_location_errors.exe data/missing_title.json title
44 {"status":"error","message":"Missing member title in JSON Feed object","location":{"file":"data/missing_title.json","line":1,"column":1,"byte_start":0,"byte_end":65},"context":"$"}
45 [1]
46
47Test missing version field:
48 $ ./test_location_errors.exe data/missing_version.json title
49 {"status":"error","message":"Missing member version in JSON Feed object","location":{"file":"data/missing_version.json","line":1,"column":1,"byte_start":0,"byte_end":51},"context":"$"}
50 [1]
51
52Test missing items field:
53 $ ./test_location_errors.exe data/missing_items.json title
54 {"status":"error","message":"Missing member items in JSON Feed object","location":{"file":"data/missing_items.json","line":1,"column":1,"byte_start":0,"byte_end":83},"context":"$"}
55 [1]
56
57Test missing item id:
58 $ ./test_location_errors.exe data/missing_item_id.json first_item_id
59 {"status":"error","message":"Missing member id in Item object","location":{"file":"data/missing_item_id.json","line":5,"column":5,"byte_start":108,"byte_end":161},"context":"$.items[0]"}
60 [1]
61
62Test missing item content:
63 $ ./test_location_errors.exe data/missing_item_content.json first_item_id
64 {"status":"error","message":"Item must have at least one of content_html or content_text","location":{"file":"-","line":-1,"column":1,"byte_start":-1,"byte_end":-1},"context":"$.items[0]"}
65 [1]
66
67
68Type Errors
69-----------
70
71Test wrong type for version (number instead of string):
72 $ ./test_location_errors.exe data/wrong_type_version.json title
73 {"status":"error","message":"Expected string but found number","location":{"file":"data/wrong_type_version.json","line":2,"column":14,"byte_start":15,"byte_end":15},"context":"$.version"}
74 [1]
75
76Test wrong type for items (object instead of array):
77 $ ./test_location_errors.exe data/wrong_type_items.json item_count
78 {"status":"error","message":"Expected array<Item object> but found object","location":{"file":"data/wrong_type_items.json","line":4,"column":12,"byte_start":102,"byte_end":102},"context":"$.items"}
79 [1]
80
81Test wrong type for title (boolean instead of string):
82 $ ./test_location_errors.exe data/wrong_type_title.json title
83 {"status":"error","message":"Expected string but found bool","location":{"file":"data/wrong_type_title.json","line":3,"column":12,"byte_start":62,"byte_end":62},"context":"$.title"}
84 [1]
85
86Test wrong type for expired (string instead of boolean):
87 $ ./test_location_errors.exe data/wrong_type_expired.json title
88 {"status":"error","message":"Expected bool but found string","location":{"file":"data/wrong_type_expired.json","line":4,"column":14,"byte_start":111,"byte_end":111},"context":"$.expired"}
89 [1]
90
91
92Nested Errors
93-------------
94
95Test invalid date format in item:
96 $ ./test_location_errors.exe data/invalid_date_format.json first_item_id
97 {"status":"error","message":"RFC 3339 timestamp: invalid RFC 3339 timestamp: \"not-a-valid-date\"","location":{"file":"-","line":-1,"column":1,"byte_start":-1,"byte_end":-1},"context":"$.items[0].date_published"}
98 [1]
99
100Test invalid author type (string instead of object):
101 $ ./test_location_errors.exe data/invalid_author_type.json title
102 {"status":"error","message":"Expected Author object but found string","location":{"file":"data/invalid_author_type.json","line":5,"column":5,"byte_start":109,"byte_end":109},"context":"$.authors[0]"}
103 [1]
104
105Test invalid attachment field type (deeply nested):
106 $ ./test_location_errors.exe data/invalid_nested_attachment.json first_item_id
107 {"status":"error","message":"Expected string but found number","location":{"file":"data/invalid_nested_attachment.json","line":11,"column":24,"byte_start":296,"byte_end":296},"context":"$.items[0].attachments[0].mime_type"}
108 [1]
109
110Test missing required field in hub:
111 $ ./test_location_errors.exe data/invalid_hub_type.json title
112 {"status":"error","message":"Missing member url in Hub object","location":{"file":"data/invalid_hub_type.json","line":5,"column":5,"byte_start":103,"byte_end":132},"context":"$.hubs[0]"}
113 [1]
114
115
116JSON Syntax Errors
117------------------
118
119Test trailing comma:
120 $ ./test_location_errors.exe data/extra_comma.json title
121 {"status":"error","message":"Expected object member but found }","location":{"file":"data/extra_comma.json","line":5,"column":1,"byte_start":105,"byte_end":105},"context":"$"}
122 [1]
123
124Test malformed JSON (missing comma):
125 $ ./test_location_errors.exe data/malformed_json.json title
126 {"status":"error","message":"Expected , or } after object member but found: \"","location":{"file":"data/malformed_json.json","line":3,"column":3,"byte_start":52,"byte_end":52},"context":"$"}
127 [1]