My agentic slop goes here. Not intended for anyone else!
at main 3.5 kB view raw
1(* Test the new Id, Date, UInt, and Patch modules *) 2open Printf 3 4let test_id () = 5 printf "Testing JMAP Id module:\n"; 6 7 (* Test valid ID creation *) 8 let valid_id = Jmap.Types.Id.of_string "abc123-_xyz" in 9 match valid_id with 10 | Ok id -> 11 printf "✓ Created valid ID: %s\n" (stringo_string id); 12 printf "✓ Debug representation: %s\n" (stringo_string_debug id) 13 | Error msg -> 14 printf "✗ Failed to create valid ID: %s\n" msg 15 16let test_date () = 17 printf "\nTesting JMAP Date module:\n"; 18 19 (* Test RFC 3339 parsing *) 20 let rfc_date = Jmap.Types.Date.of_rfc3339 "2023-12-01T10:30:00Z" in 21 match rfc_date with 22 | Ok date -> 23 printf "✓ Parsed RFC 3339 date: %s\n" (Jmap.Types.Date.to_rfc3339 date); 24 printf "✓ Debug representation: %s\n" (Jmap.Types.Date.to_string_debug date) 25 | Error msg -> 26 printf "✗ Failed to parse RFC 3339 date: %s\n" msg 27 28let test_uint () = 29 printf "\nTesting JMAP UInt module:\n"; 30 31 (* Test valid unsigned int *) 32 let valid_uint = Jmap.Types.UInt.of_int 42 in 33 match valid_uint with 34 | Ok uint -> 35 printf "✓ Created UInt: %d\n" (Jmap.Types.UInt.to_int uint); 36 printf "✓ Debug representation: %s\n" (Jmap.Types.UInt.to_string_debug uint) 37 | Error msg -> 38 printf "✗ Failed to create UInt: %s\n" msg; 39 40 (* Test invalid (negative) int *) 41 let invalid_uint = Jmap.Types.UInt.of_int (-1) in 42 match invalid_uint with 43 | Ok _ -> printf "✗ Should have failed for negative value\n" 44 | Error msg -> printf "✓ Correctly rejected negative value: %s\n" msg 45 46let test_patch () = 47 printf "\nTesting JMAP Patch module:\n"; 48 49 (* Test empty patch *) 50 let empty = Jmap.Types.Patch.empty in 51 printf "✓ Empty patch created, size: %d\n" (Jmap.Types.Patch.size empty); 52 53 (* Test setting a property *) 54 match Jmap.Types.Patch.set_property empty "name" (`String "John") with 55 | Ok patch -> 56 printf "✓ Set property 'name': %s\n" (Jmap.Types.Patch.to_string_debug patch); 57 printf "✓ Has property 'name': %b\n" (Jmap.Types.Patch.has_property patch "name") 58 | Error msg -> 59 printf "✗ Failed to set property: %s\n" msg 60 61let test_json_serialization () = 62 printf "\nTesting JSON serialization:\n"; 63 64 (* Test Id JSON roundtrip *) 65 (match Jmap.Types.Id.of_string "test123" with 66 | Ok id -> 67 let json = stringo_json id in 68 let parsed = Jmap.Types.Id.of_json json in 69 (match parsed with 70 | Ok parsed_id when Jmap.Types.Id.equal id parsed_id -> 71 printf "✓ Id JSON roundtrip successful\n" 72 | Ok _ -> printf "✗ Id JSON roundtrip failed - values differ\n" 73 | Error msg -> printf "✗ Id JSON parsing failed: %s\n" msg) 74 | Error msg -> printf "✗ Failed to create test Id: %s\n" msg); 75 76 (* Test UInt JSON roundtrip *) 77 (match Jmap.Types.UInt.of_int 100 with 78 | Ok uint -> 79 let json = Jmap.Types.UInt.to_json uint in 80 let parsed = Jmap.Types.UInt.of_json json in 81 (match parsed with 82 | Ok parsed_uint when Jmap.Types.UInt.equal uint parsed_uint -> 83 printf "✓ UInt JSON roundtrip successful\n" 84 | Ok _ -> printf "✗ UInt JSON roundtrip failed - values differ\n" 85 | Error msg -> printf "✗ UInt JSON parsing failed: %s\n" msg) 86 | Error msg -> printf "✗ Failed to create test UInt: %s\n" msg) 87 88let () = 89 printf "JMAP Module Restructuring Test\n"; 90 printf "==============================\n"; 91 test_id (); 92 test_date (); 93 test_uint (); 94 test_patch (); 95 test_json_serialization (); 96 printf "\nTest completed!\n"