this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more

-108
-108
jmap/bin/simple_core_test.ml
··· 1 - (** Simple JMAP Core Types Test 2 - 3 - This is a minimal example that demonstrates the core JMAP library functionality 4 - without any network dependencies. It shows: 5 - 6 - 1. Basic JMAP type creation (Id, Date, UInt) 7 - 2. JSON serialization and deserialization 8 - 3. Basic JMAP protocol structures 9 - 4. Error handling with Result types 10 - *) 11 - 12 - open Printf 13 - 14 - let test_basic_types () = 15 - printf "Testing basic JMAP types...\n"; 16 - 17 - (* Test Id creation and JSON serialization *) 18 - let test_id_json () = 19 - match Jmap.Id.of_string "message-123" with 20 - | Ok id -> 21 - let json = Jmap.Id.to_json id in 22 - printf "✓ Id JSON: %s\n" (Yojson.Safe.to_string json); 23 - (match Jmap.Id.of_json json with 24 - | Ok parsed_id when Jmap.Id.to_string parsed_id = Jmap.Id.to_string id -> 25 - printf "✓ Id roundtrip successful\n"; true 26 - | Ok _ -> 27 - printf "✗ Id roundtrip failed: different values\n"; false 28 - | Error e -> 29 - printf "✗ Id parsing failed: %s\n" e; false) 30 - | Error e -> 31 - printf "✗ Id creation failed: %s\n" e; false 32 - in 33 - 34 - (* Test Date creation and JSON serialization *) 35 - let test_date_json () = 36 - let timestamp = Unix.time () in 37 - let date = Jmap.Date.of_timestamp timestamp in 38 - let json = Jmap.Date.to_json date in 39 - printf "✓ Date JSON: %s\n" (Yojson.Safe.to_string json); 40 - (match Jmap.Date.of_json json with 41 - | Ok parsed_date -> 42 - let diff = abs_float (Jmap.Date.to_timestamp parsed_date -. timestamp) in 43 - if diff < 86400.0 then ( (* Allow up to 24 hours difference for timezone issues *) 44 - printf "✓ Date roundtrip successful (diff: %.3fs)\n" diff; true 45 - ) else ( 46 - printf "✗ Date roundtrip failed: large difference %.3fs\n" diff; false 47 - ) 48 - | Error e -> 49 - printf "✗ Date parsing failed: %s\n" e; false) 50 - in 51 - 52 - (* Test UInt creation and JSON serialization *) 53 - let test_uint_json () = 54 - match Jmap.UInt.of_int 42 with 55 - | Ok uint -> 56 - let json = Jmap.UInt.to_json uint in 57 - printf "✓ UInt JSON: %s\n" (Yojson.Safe.to_string json); 58 - (match Jmap.UInt.of_json json with 59 - | Ok parsed_uint when Jmap.UInt.to_int parsed_uint = 42 -> 60 - printf "✓ UInt roundtrip successful\n"; true 61 - | Ok _ -> 62 - printf "✗ UInt roundtrip failed: different values\n"; false 63 - | Error e -> 64 - printf "✗ UInt parsing failed: %s\n" e; false) 65 - | Error e -> 66 - printf "✗ UInt creation failed: %s\n" e; false 67 - in 68 - 69 - let id_ok = test_id_json () in 70 - let date_ok = test_date_json () in 71 - let uint_ok = test_uint_json () in 72 - 73 - (id_ok && date_ok && uint_ok) 74 - 75 - let test_protocol_structures () = 76 - printf "\nTesting JMAP protocol structures...\n"; 77 - 78 - (* Test basic capability representation *) 79 - let test_capabilities () = 80 - (* For now, just test that we can reference the types *) 81 - printf "✓ Protocol types accessible\n"; 82 - true 83 - in 84 - 85 - test_capabilities () 86 - 87 - let main () = 88 - printf "JMAP Core Library Test\n"; 89 - printf "=====================\n\n"; 90 - 91 - let basic_ok = test_basic_types () in 92 - let protocol_ok = test_protocol_structures () in 93 - 94 - printf "\n=== Test Results ===\n"; 95 - printf "Basic types: %s\n" (if basic_ok then "PASS" else "FAIL"); 96 - printf "Protocol structures: %s\n" (if protocol_ok then "PASS" else "FAIL"); 97 - 98 - let all_ok = basic_ok && protocol_ok in 99 - printf "Overall: %s\n" (if all_ok then "ALL TESTS PASSED" else "SOME TESTS FAILED"); 100 - 101 - if all_ok then 102 - printf "\nThe core JMAP library is working correctly!\n" 103 - else 104 - printf "\nSome tests failed - library needs debugging.\n"; 105 - 106 - exit (if all_ok then 0 else 1) 107 - 108 - let () = main ()