OCaml wire format DSL with EverParse 3D output for verified parsers
1(** Alcotest tests for the Wire_diff_gen library. *)
2
3let test_schema_create_fixed () =
4 let s =
5 Wire.struct_ "TestSchema"
6 [ Wire.field "a" Wire.uint8; Wire.field "b" Wire.uint16 ]
7 in
8 let m = Wire.module_ "TestSchema" [ Wire.typedef ~entrypoint:true s ] in
9 let result =
10 Wire_diff_gen.Diff_gen.schema ~name:"TestSchema" ~struct_:s ~module_:m
11 in
12 Alcotest.(check bool) "fixed-size schema is Some" true (Option.is_some result)
13
14let test_schema_create_variable () =
15 let s =
16 Wire.struct_ "VarSchema"
17 [ Wire.field "a" Wire.uint8; Wire.field "data" Wire.all_bytes ]
18 in
19 let m = Wire.module_ "VarSchema" [ Wire.typedef ~entrypoint:true s ] in
20 let result =
21 Wire_diff_gen.Diff_gen.schema ~name:"VarSchema" ~struct_:s ~module_:m
22 in
23 Alcotest.(check bool)
24 "variable-size schema is None" true (Option.is_none result)
25
26let suite =
27 ( "diff_gen",
28 [
29 Alcotest.test_case "schema create (fixed)" `Quick test_schema_create_fixed;
30 Alcotest.test_case "schema create (variable)" `Quick
31 test_schema_create_variable;
32 ] )