···
test_feed_parse_invalid_missing_content );
+
(* Unknown fields preservation tests *)
+
let test_author_unknown_roundtrip () =
+
"custom_field": "custom value",
+
"another_extension": 42
+
match Jsont_bytesrw.decode_string' Author.jsont json with
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
+
(* Check that unknown fields are preserved *)
+
let unknown = Author.unknown author in
+
"has unknown fields" false
+
(Jsonfeed.Unknown.is_empty unknown);
+
(* Encode and decode again *)
+
(match Jsont_bytesrw.encode_string' Author.jsont author with
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
+
match Jsont_bytesrw.decode_string' Author.jsont json2 with
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
+
(* Verify unknown fields survive roundtrip *)
+
let unknown2 = Author.unknown author2 in
+
"unknown fields preserved" false
+
(Jsonfeed.Unknown.is_empty unknown2)))
+
let test_item_unknown_roundtrip () =
+
"id": "https://example.com/1",
+
"content_html": "<p>Test</p>",
+
"custom_metadata": "some custom data",
+
"x_custom_number": 123.45
+
match Jsont_bytesrw.decode_string' Item.jsont json with
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
+
(* Check that unknown fields are preserved *)
+
let unknown = Item.unknown item in
+
"has unknown fields" false
+
(Jsonfeed.Unknown.is_empty unknown);
+
(* Encode and decode again *)
+
(match Jsont_bytesrw.encode_string' Item.jsont item with
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
+
match Jsont_bytesrw.decode_string' Item.jsont json2 with
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
+
let unknown2 = Item.unknown item2 in
+
"unknown fields preserved" false
+
(Jsonfeed.Unknown.is_empty unknown2)))
+
let test_feed_unknown_roundtrip () =
+
"version": "https://jsonfeed.org/version/1.1",
+
"custom_extension": "custom value",
+
"x_another_field": {"nested": "data"}
+
match Jsonfeed.of_string json with
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
+
(* Check that unknown fields are preserved *)
+
let unknown = Jsonfeed.unknown feed in
+
"has unknown fields" false
+
(Jsonfeed.Unknown.is_empty unknown);
+
(* Encode and decode again *)
+
(match Jsonfeed.to_string feed with
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
+
match Jsonfeed.of_string json2 with
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
+
let unknown2 = Jsonfeed.unknown feed2 in
+
"unknown fields preserved" false
+
(Jsonfeed.Unknown.is_empty unknown2)))
+
let test_hub_unknown_roundtrip () =
+
"url": "https://example.com/hub",
+
match Jsont_bytesrw.decode_string' Hub.jsont json with
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
+
let unknown = Hub.unknown hub in
+
"has unknown fields" false
+
(Jsonfeed.Unknown.is_empty unknown);
+
(match Jsont_bytesrw.encode_string' Hub.jsont hub with
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
+
match Jsont_bytesrw.decode_string' Hub.jsont json2 with
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
+
let unknown2 = Hub.unknown hub2 in
+
"unknown fields preserved" false
+
(Jsonfeed.Unknown.is_empty unknown2)))
+
let test_attachment_unknown_roundtrip () =
+
"url": "https://example.com/file.mp3",
+
"mime_type": "audio/mpeg",
+
match Jsont_bytesrw.decode_string' Attachment.jsont json with
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
+
let unknown = Attachment.unknown att in
+
"has unknown fields" false
+
(Jsonfeed.Unknown.is_empty unknown);
+
(match Jsont_bytesrw.encode_string' Attachment.jsont att with
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
+
match Jsont_bytesrw.decode_string' Attachment.jsont json2 with
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
+
let unknown2 = Attachment.unknown att2 in
+
"unknown fields preserved" false
+
(Jsonfeed.Unknown.is_empty unknown2)))
+
let unknown_fields_tests =
+
("author unknown roundtrip", `Quick, test_author_unknown_roundtrip);
+
("item unknown roundtrip", `Quick, test_item_unknown_roundtrip);
+
("feed unknown roundtrip", `Quick, test_feed_unknown_roundtrip);
+
("hub unknown roundtrip", `Quick, test_hub_unknown_roundtrip);
+
("attachment unknown roundtrip", `Quick, test_attachment_unknown_roundtrip);
···
("Jsonfeed", jsonfeed_tests);
+
("Unknown Fields", unknown_fields_tests);