···
test_feed_parse_invalid_missing_content );
373
+
(* Unknown fields preservation tests *)
375
+
let test_author_unknown_roundtrip () =
378
+
"name": "Test Author",
379
+
"custom_field": "custom value",
380
+
"another_extension": 42
383
+
match Jsont_bytesrw.decode_string' Author.jsont json with
386
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
388
+
(* Check that unknown fields are preserved *)
389
+
let unknown = Author.unknown author in
390
+
Alcotest.(check bool)
391
+
"has unknown fields" false
392
+
(Jsonfeed.Unknown.is_empty unknown);
393
+
(* Encode and decode again *)
394
+
(match Jsont_bytesrw.encode_string' Author.jsont author with
397
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
399
+
match Jsont_bytesrw.decode_string' Author.jsont json2 with
402
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
404
+
(* Verify unknown fields survive roundtrip *)
405
+
let unknown2 = Author.unknown author2 in
406
+
Alcotest.(check bool)
407
+
"unknown fields preserved" false
408
+
(Jsonfeed.Unknown.is_empty unknown2)))
410
+
let test_item_unknown_roundtrip () =
413
+
"id": "https://example.com/1",
414
+
"content_html": "<p>Test</p>",
415
+
"custom_metadata": "some custom data",
416
+
"x_custom_number": 123.45
419
+
match Jsont_bytesrw.decode_string' Item.jsont json with
422
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
424
+
(* Check that unknown fields are preserved *)
425
+
let unknown = Item.unknown item in
426
+
Alcotest.(check bool)
427
+
"has unknown fields" false
428
+
(Jsonfeed.Unknown.is_empty unknown);
429
+
(* Encode and decode again *)
430
+
(match Jsont_bytesrw.encode_string' Item.jsont item with
433
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
435
+
match Jsont_bytesrw.decode_string' Item.jsont json2 with
438
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
440
+
let unknown2 = Item.unknown item2 in
441
+
Alcotest.(check bool)
442
+
"unknown fields preserved" false
443
+
(Jsonfeed.Unknown.is_empty unknown2)))
445
+
let test_feed_unknown_roundtrip () =
448
+
"version": "https://jsonfeed.org/version/1.1",
449
+
"title": "Test Feed",
451
+
"custom_extension": "custom value",
452
+
"x_another_field": {"nested": "data"}
455
+
match Jsonfeed.of_string json with
458
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
460
+
(* Check that unknown fields are preserved *)
461
+
let unknown = Jsonfeed.unknown feed in
462
+
Alcotest.(check bool)
463
+
"has unknown fields" false
464
+
(Jsonfeed.Unknown.is_empty unknown);
465
+
(* Encode and decode again *)
466
+
(match Jsonfeed.to_string feed with
469
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
471
+
match Jsonfeed.of_string json2 with
474
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
476
+
let unknown2 = Jsonfeed.unknown feed2 in
477
+
Alcotest.(check bool)
478
+
"unknown fields preserved" false
479
+
(Jsonfeed.Unknown.is_empty unknown2)))
481
+
let test_hub_unknown_roundtrip () =
484
+
"url": "https://example.com/hub",
485
+
"custom_field": "test"
487
+
match Jsont_bytesrw.decode_string' Hub.jsont json with
490
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
492
+
let unknown = Hub.unknown hub in
493
+
Alcotest.(check bool)
494
+
"has unknown fields" false
495
+
(Jsonfeed.Unknown.is_empty unknown);
496
+
(match Jsont_bytesrw.encode_string' Hub.jsont hub with
499
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
501
+
match Jsont_bytesrw.decode_string' Hub.jsont json2 with
504
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
506
+
let unknown2 = Hub.unknown hub2 in
507
+
Alcotest.(check bool)
508
+
"unknown fields preserved" false
509
+
(Jsonfeed.Unknown.is_empty unknown2)))
511
+
let test_attachment_unknown_roundtrip () =
514
+
"url": "https://example.com/file.mp3",
515
+
"mime_type": "audio/mpeg",
516
+
"x_custom": "value"
519
+
match Jsont_bytesrw.decode_string' Attachment.jsont json with
522
+
(Printf.sprintf "Parse failed: %s" (Jsont.Error.to_string e))
524
+
let unknown = Attachment.unknown att in
525
+
Alcotest.(check bool)
526
+
"has unknown fields" false
527
+
(Jsonfeed.Unknown.is_empty unknown);
528
+
(match Jsont_bytesrw.encode_string' Attachment.jsont att with
531
+
(Printf.sprintf "Encode failed: %s" (Jsont.Error.to_string e))
533
+
match Jsont_bytesrw.decode_string' Attachment.jsont json2 with
536
+
(Printf.sprintf "Re-parse failed: %s" (Jsont.Error.to_string e))
538
+
let unknown2 = Attachment.unknown att2 in
539
+
Alcotest.(check bool)
540
+
"unknown fields preserved" false
541
+
(Jsonfeed.Unknown.is_empty unknown2)))
543
+
let unknown_fields_tests =
545
+
("author unknown roundtrip", `Quick, test_author_unknown_roundtrip);
546
+
("item unknown roundtrip", `Quick, test_item_unknown_roundtrip);
547
+
("feed unknown roundtrip", `Quick, test_feed_unknown_roundtrip);
548
+
("hub unknown roundtrip", `Quick, test_hub_unknown_roundtrip);
549
+
("attachment unknown roundtrip", `Quick, test_attachment_unknown_roundtrip);
···
("Jsonfeed", jsonfeed_tests);
562
+
("Unknown Fields", unknown_fields_tests);