Debian Codegraph @

test/non_integers_repr.ml

raw symbols SCIP
1 (* WARNING: never accept the corrected output for this file, it must never change! *)
2
3 open Core
4 open Poly
5 open Bigarray
6 open Import
7
8 (* Generate reference serialized output for various functions of
9 [Bin_prot.Write] for the purpose of ensuring [Bin_prot.Size.Maximum] and
10 [Bin_prot.Size.Minimum] bound correctness.
11
12 We can't generate reference output for every possible values as it would be huge,
13 instead we choose a few interesting points and generate tests around and including
14 those points.
15 *)
16
17 module Read = Bin_prot.Read
18 module Write = Bin_prot.Write
19
20 type 'a to_test =
21 { writer : 'a Write.writer
22 ; writer_local : 'a Write.writer_local option
23 ; reader : 'a Read.reader
24 ; values : 'a list
25 ; equal : 'a -> 'a -> bool
26 ; sexp_of : 'a -> Sexp.t (* Bounds on the bin_protted size *)
27 ; hi_bound : int option
28 ; lo_bound : int
29 }
30
31 module Vec = struct
32 let mk_gen_float tp n =
33 let vec = Array1.create tp fortran_layout n in
34 for i = 1 to n do
35 vec.{i} <- float i
36 done;
37 vec
38 ;;
39
40 let mk_float32 = mk_gen_float float32
41 let mk_float64 = mk_gen_float float64
42 let to_array t = Array.init (Array1.dim t) ~f:(fun i -> t.{i + 1})
43 let sexp_of_t t = [%sexp_of: float array] (to_array t)
44 let equal t1 t2 = Array.equal Float.equal (to_array t1) (to_array t2)
45 end
46
47 module Mat = struct
48 let mk_gen_float tp m n =
49 let mat = Array2.create tp fortran_layout m n in
50 let fn = float m in
51 for c = 1 to n do
52 let ofs = float (c - 1) *. fn in
53 for r = 1 to m do
54 mat.{r, c} <- ofs +. float r
55 done
56 done;
57 mat
58 ;;
59
60 let mk_float32 = mk_gen_float float32
61 let mk_float64 = mk_gen_float float64
62
63 let to_array t =
64 Array.init (Array2.dim1 t) ~f:(fun i ->
65 Array.init (Array2.dim2 t) ~f:(fun j -> t.{i + 1, j + 1}))
66 ;;
67
68 let sexp_of_t t = [%sexp_of: float array array] (to_array t)
69 let equal t1 t2 = Array.equal (Array.equal Float.equal) (to_array t1) (to_array t2)
70 end
71
72 module Tests = struct
73 (* max and min *)
74 let unit =
75 { writer = Write.bin_write_unit
76 ; writer_local = Some Write.bin_write_unit__local
77 ; reader = Read.bin_read_unit
78 ; values = [ () ]
79 ; equal = Unit.equal
80 ; sexp_of = [%sexp_of: unit]
81 ; hi_bound = Some Maximum.bin_size_unit
82 ; lo_bound = Minimum.bin_size_unit
83 }
84 ;;
85
86 let bool =
87 { writer = Write.bin_write_bool
88 ; writer_local = Some Write.bin_write_bool__local
89 ; reader = Read.bin_read_bool
90 ; values = [ true; false ]
91 ; equal = Bool.equal
92 ; sexp_of = [%sexp_of: bool]
93 ; hi_bound = Some Maximum.bin_size_bool
94 ; lo_bound = Minimum.bin_size_bool
95 }
96 ;;
97
98 let char =
99 { writer = Write.bin_write_char
100 ; writer_local = Some Write.bin_write_char__local
101 ; reader = Read.bin_read_char
102 ; values = [ '\x00'; 'A'; 'z'; ';'; '\xFF' ]
103 ; equal = Char.equal
104 ; sexp_of = [%sexp_of: char]
105 ; hi_bound = Some Maximum.bin_size_char
106 ; lo_bound = Minimum.bin_size_char
107 }
108 ;;
109
110 let digest =
111 { writer = Write.bin_write_md5
112 ; writer_local = Some Write.bin_write_md5__local
113 ; reader = Read.bin_read_md5
114 ; values = [ Md5_lib.of_hex_exn "0123456789abcdef0123456789ABCDEF" ]
115 ; equal = (fun d1 d2 -> Md5_lib.compare d1 d2 = 0)
116 ; sexp_of = (fun md5 -> Atom (Md5_lib.to_hex md5))
117 ; hi_bound = Some Maximum.bin_size_md5
118 ; lo_bound = Minimum.bin_size_md5
119 }
120 ;;
121
122 let float =
123 { writer = Write.bin_write_float
124 ; writer_local = Some Write.bin_write_float__local
125 ; reader = Read.bin_read_float
126 ; values =
127 [ Float.epsilon_float
128 ; Float.infinity
129 ; Float.max_finite_value
130 ; Float.max_value
131 ; Float.min_positive_normal_value
132 ; Float.min_positive_subnormal_value
133 ; Float.min_value
134 ; Float.minus_one
135 ; Float.neg_infinity
136 ; Float.one
137 ; Float.robust_comparison_tolerance
138 ; Float.zero
139 ]
140 ; equal = (fun a b -> (Float.is_nan a && Float.is_nan b) || Float.equal a b)
141 ; sexp_of = [%sexp_of: float]
142 ; hi_bound = Some Maximum.bin_size_float
143 ; lo_bound = Minimum.bin_size_float
144 }
145 ;;
146
147 let float_nan = { float with values = [ Float.nan ] }
148
149 (* min only *)
150 let vec =
151 { writer = Write.bin_write_vec
152 ; writer_local = Some Write.bin_write_vec__local
153 ; reader = Read.bin_read_vec
154 ; values = [ Vec.mk_float64 0; Vec.mk_float64 1 ]
155 ; equal = Vec.equal
156 ; sexp_of = [%sexp_of: Vec.t]
157 ; hi_bound = None
158 ; lo_bound = Minimum.bin_size_vec
159 }
160 ;;
161
162 let float32_vec =
163 { writer = Write.bin_write_float32_vec
164 ; writer_local = Some Write.bin_write_float32_vec__local
165 ; reader = Read.bin_read_float32_vec
166 ; values = [ Vec.mk_float32 0; Vec.mk_float32 1 ]
167 ; equal = Vec.equal
168 ; sexp_of = [%sexp_of: Vec.t]
169 ; hi_bound = None
170 ; lo_bound = Minimum.bin_size_float32_vec
171 }
172 ;;
173
174 let float64_vec =
175 { writer = Write.bin_write_float64_vec
176 ; writer_local = Some Write.bin_write_float64_vec__local
177 ; reader = Read.bin_read_float64_vec
178 ; values = [ Vec.mk_float64 0; Vec.mk_float64 1 ]
179 ; equal = Vec.equal
180 ; sexp_of = [%sexp_of: Vec.t]
181 ; hi_bound = None
182 ; lo_bound = Minimum.bin_size_float64_vec
183 }
184 ;;
185
186 let mat =
187 { writer = Write.bin_write_mat
188 ; writer_local = Some Write.bin_write_mat__local
189 ; reader = Read.bin_read_mat
190 ; values = [ Mat.mk_float64 0 0; Mat.mk_float64 1 1 ]
191 ; equal = Mat.equal
192 ; sexp_of = [%sexp_of: Mat.t]
193 ; hi_bound = None
194 ; lo_bound = Minimum.bin_size_mat
195 }
196 ;;
197
198 let float32_mat =
199 { writer = Write.bin_write_float32_mat
200 ; writer_local = Some Write.bin_write_float32_mat__local
201 ; reader = Read.bin_read_float32_mat
202 ; values = [ Mat.mk_float32 0 0; Mat.mk_float32 1 1 ]
203 ; equal = Mat.equal
204 ; sexp_of = [%sexp_of: Mat.t]
205 ; hi_bound = None
206 ; lo_bound = Minimum.bin_size_float32_mat
207 }
208 ;;
209
210 let float64_mat =
211 { writer = Write.bin_write_float64_mat
212 ; writer_local = Some Write.bin_write_float64_mat__local
213 ; reader = Read.bin_read_float64_mat
214 ; values = [ Mat.mk_float64 0 0; Mat.mk_float64 1 1 ]
215 ; equal = Mat.equal
216 ; sexp_of = [%sexp_of: Mat.t]
217 ; hi_bound = None
218 ; lo_bound = Minimum.bin_size_float64_mat
219 }
220 ;;
221
222 let bigstring =
223 { writer = Write.bin_write_bigstring
224 ; writer_local = Some Write.bin_write_bigstring__local
225 ; reader = Read.bin_read_bigstring
226 ; values = [ Bigstring.of_string ""; Bigstring.of_string "hello" ]
227 ; equal =
228 (fun s1 s2 -> String.equal (Bigstring.to_string s1) (Bigstring.to_string s2))
229 ; sexp_of = [%sexp_of: Bigstring.t]
230 ; hi_bound = None
231 ; lo_bound = Minimum.bin_size_bigstring
232 }
233 ;;
234
235 let floatarray =
236 { writer = Write.bin_write_floatarray
237 ; writer_local = Some Write.bin_write_floatarray__local
238 ; reader = Read.bin_read_floatarray
239 ; values = [ Float_array.empty; Float_array.create ~len:1 0.0 ]
240 ; equal = Float_array.equal Float.equal
241 ; sexp_of = [%sexp_of: Float_array.t]
242 ; hi_bound = None
243 ; lo_bound = Minimum.bin_size_floatarray
244 }
245 ;;
246
247 let ref =
248 { writer = Write.bin_write_ref Write.bin_write_int32
249 ; writer_local = Some (Write.bin_write_ref__local Write.bin_write_int32__local)
250 ; reader = Read.bin_read_ref Read.bin_read_int32
251 ; values = [ ref 0l; ref 1l; ref (-1l); ref Int32.max_value; ref Int32.min_value ]
252 ; equal = (fun v1 v2 -> !v1 = !v2)
253 ; sexp_of = [%sexp_of: int32 ref]
254 ; hi_bound = None
255 ; lo_bound = Minimum.bin_size_ref
256 }
257 ;;
258
259 let lazy_t =
260 { writer = Write.bin_write_lazy Write.bin_write_int32
261 ; writer_local = Some (Write.bin_write_lazy__local Write.bin_write_int32__local)
262 ; reader = Read.bin_read_lazy Read.bin_read_int32
263 ; values =
264 [ lazy 0l; lazy 1l; lazy (-1l); lazy Int32.max_value; lazy Int32.min_value ]
265 ; equal = (fun v1 v2 -> force v1 = force v2)
266 ; sexp_of = [%sexp_of: int32 Lazy.t]
267 ; hi_bound = None
268 ; lo_bound = Minimum.bin_size_lazy_t
269 }
270 ;;
271
272 let option =
273 { writer = Write.bin_write_option Write.bin_write_int32
274 ; writer_local = Some (Write.bin_write_option__local Write.bin_write_int32__local)
275 ; reader = Read.bin_read_option Read.bin_read_int32
276 ; values =
277 [ None; Some 0l; Some 1l; Some (-1l); Some Int32.max_value; Some Int32.min_value ]
278 ; equal = Option.equal Int32.equal
279 ; sexp_of = [%sexp_of: int32 option]
280 ; hi_bound = None
281 ; lo_bound = Minimum.bin_size_option
282 }
283 ;;
284
285 let pair =
286 { writer = Write.bin_write_pair Write.bin_write_int32 Write.bin_write_int32
287 ; writer_local =
288 Some
289 (Write.bin_write_pair__local
290 Write.bin_write_int32__local
291 Write.bin_write_int32__local)
292 ; reader = Read.bin_read_pair Read.bin_read_int32 Read.bin_read_int32
293 ; values =
294 [ 0l, 0l
295 ; 1l, 1l
296 ; -1l, -1l
297 ; Int32.max_value, Int32.max_value
298 ; Int32.min_value, Int32.min_value
299 ]
300 ; equal = Tuple2.equal ~eq1:Int32.equal ~eq2:Int32.equal
301 ; sexp_of = [%sexp_of: int32 * int32]
302 ; hi_bound = None
303 ; lo_bound = Minimum.bin_size_pair
304 }
305 ;;
306
307 let triple =
308 { writer =
309 Write.bin_write_triple
310 Write.bin_write_int32
311 Write.bin_write_int32
312 Write.bin_write_int32
313 ; writer_local =
314 Some
315 (Write.bin_write_triple__local
316 Write.bin_write_int32__local
317 Write.bin_write_int32__local
318 Write.bin_write_int32__local)
319 ; reader =
320 Read.bin_read_triple Read.bin_read_int32 Read.bin_read_int32 Read.bin_read_int32
321 ; values =
322 [ 0l, 0l, 0l
323 ; 1l, 1l, 1l
324 ; -1l, -1l, -1l
325 ; Int32.max_value, Int32.max_value, Int32.max_value
326 ; Int32.min_value, Int32.min_value, Int32.min_value
327 ]
328 ; equal = Tuple3.equal ~eq1:Int32.equal ~eq2:Int32.equal ~eq3:Int32.equal
329 ; sexp_of = [%sexp_of: int32 * int32 * int32]
330 ; hi_bound = None
331 ; lo_bound = Minimum.bin_size_triple
332 }
333 ;;
334
335 let list =
336 { writer = Write.bin_write_list Write.bin_write_int32
337 ; writer_local = Some (Write.bin_write_list__local Write.bin_write_int32__local)
338 ; reader = Read.bin_read_list Read.bin_read_int32
339 ; values =
340 [ []
341 ; [ 0l ]
342 ; [ 0l; 1l ]
343 ; [ 1l; -1l ]
344 ; [ 0l; Int32.max_value ]
345 ; [ Int32.max_value; Int32.min_value ]
346 ]
347 ; equal = List.equal Int32.equal
348 ; sexp_of = [%sexp_of: int32 list]
349 ; hi_bound = None
350 ; lo_bound = Minimum.bin_size_list
351 }
352 ;;
353
354 let array =
355 { writer = Write.bin_write_array Write.bin_write_int32
356 ; writer_local = Some (Write.bin_write_array__local Write.bin_write_int32__local)
357 ; reader = Read.bin_read_array Read.bin_read_int32
358 ; values =
359 [ [||]
360 ; [| 0l |]
361 ; [| 0l; 1l |]
362 ; [| 1l; -1l |]
363 ; [| 0l; Int32.max_value |]
364 ; [| Int32.max_value; Int32.min_value |]
365 ]
366 ; equal = Array.equal Int32.equal
367 ; sexp_of = [%sexp_of: int32 array]
368 ; hi_bound = None
369 ; lo_bound = Minimum.bin_size_array
370 }
371 ;;
372
373 let hashtbl =
374 { writer = Write.bin_write_hashtbl Write.bin_write_int32 Write.bin_write_int32
375 ; writer_local = None
376 ; reader = Read.bin_read_hashtbl Read.bin_read_int32 Read.bin_read_int32
377 ; values =
378 List.map
379 [ []
380 ; [ 0l, 0l ]
381 ; [ 0l, 0l; 1l, 1l ]
382 ; [ 0l, 0l; Int32.max_value, Int32.max_value ]
383 ; [ -1l, -1l; Int32.min_value, Int32.min_value ]
384 ]
385 ~f:(fun l ->
386 let hashtbl = Stdlib.Hashtbl.create (List.length l) in
387 List.iter l ~f:(fun (key, data) -> Stdlib.Hashtbl.add hashtbl key data);
388 hashtbl)
389 ; equal =
390 (fun t1 t2 ->
391 let to_list tbl =
392 Stdlib.Hashtbl.fold (fun k v acc -> (k, v) :: acc) tbl []
393 |> List.sort ~compare
394 in
395 to_list t1 = to_list t2)
396 ; sexp_of = [%sexp_of: (int32, int32) Sexplib.Std.Hashtbl.t]
397 ; hi_bound = None
398 ; lo_bound = Minimum.bin_size_hashtbl
399 }
400 ;;
401
402 module R1 = struct
403 type t =
404 { x : Int32.t
405 ; y : float
406 }
407 [@@deriving bin_io ~localize, fields ~iterators:fold, sexp_of]
408
409 let maximum_bin_size =
410 Fields.fold
411 ~init:0
412 ~x:(fun acc _ -> acc + Maximum.bin_size_int32)
413 ~y:(fun acc _ -> acc + Maximum.bin_size_float)
414 ;;
415
416 let minimum_bin_size =
417 Fields.fold
418 ~init:0
419 ~x:(fun acc _ -> acc + Minimum.bin_size_int32)
420 ~y:(fun acc _ -> acc + Minimum.bin_size_float)
421 ;;
422 end
423
424 let record1 =
425 let open R1 in
426 { writer = bin_write_t
427 ; writer_local = Some bin_write_t__local
428 ; reader = bin_read_t
429 ; values = [ { x = 0l; y = 0.0 }; { x = Int32.max_value; y = Float.max_value } ]
430 ; equal = ( = )
431 ; sexp_of = [%sexp_of: t]
432 ; hi_bound = Some maximum_bin_size
433 ; lo_bound = minimum_bin_size
434 }
435 ;;
436
437 module R2 = struct
438 type inner =
439 { w : Int64.t
440 ; x : Int32.t
441 }
442 [@@deriving bin_io ~localize, fields ~iterators:fold, sexp_of]
443
444 let maximum_bin_size_of_inner =
445 Fields_of_inner.fold
446 ~init:0
447 ~w:(fun acc _ -> acc + Maximum.bin_size_int64)
448 ~x:(fun acc _ -> acc + Maximum.bin_size_int32)
449 ;;
450
451 let minimum_bin_size_of_inner =
452 Fields_of_inner.fold
453 ~init:0
454 ~w:(fun acc _ -> acc + Minimum.bin_size_int64)
455 ~x:(fun acc _ -> acc + Minimum.bin_size_int32)
456 ;;
457
458 type t =
459 { y : inner
460 ; z : unit
461 }
462 [@@deriving bin_io ~localize, fields ~iterators:fold, sexp_of]
463
464 let maximum_bin_size =
465 Fields.fold
466 ~init:0
467 ~y:(fun acc _ -> acc + maximum_bin_size_of_inner)
468 ~z:(fun acc _ -> acc + Maximum.bin_size_unit)
469 ;;
470
471 let minimum_bin_size =
472 Fields.fold
473 ~init:0
474 ~y:(fun acc _ -> acc + minimum_bin_size_of_inner)
475 ~z:(fun acc _ -> acc + Minimum.bin_size_unit)
476 ;;
477 end
478
479 let record2 =
480 let open R2 in
481 { writer = bin_write_t
482 ; writer_local = Some bin_write_t__local
483 ; reader = bin_read_t
484 ; values =
485 [ { y = { w = 0L; x = 0l }; z = () }
486 ; { y = { w = Int64.max_value; x = Int32.max_value }; z = () }
487 ]
488 ; equal = ( = )
489 ; sexp_of = [%sexp_of: t]
490 ; hi_bound = Some maximum_bin_size
491 ; lo_bound = minimum_bin_size
492 }
493 ;;
494
495 module Inline_record = struct
496 type inner =
497 | Inner of
498 { w : Int64.t
499 ; x : Int32.t
500 }
501 | Inner_other of unit
502 [@@deriving bin_io ~localize, sexp_of, variants]
503
504 let maximum_bin_size_of_inner =
505 1
506 + Variants_of_inner.fold
507 ~init:0
508 ~inner:(fun acc _ -> max acc (Maximum.bin_size_int64 + Maximum.bin_size_int32))
509 ~inner_other:(fun acc _ -> max acc Maximum.bin_size_unit)
510 ;;
511
512 let minimum_bin_size_of_inner =
513 1
514 + Variants_of_inner.fold
515 ~init:Int.max_value
516 ~inner:(fun acc _ -> min acc (Minimum.bin_size_int64 + Minimum.bin_size_int32))
517 ~inner_other:(fun acc _ -> min acc Minimum.bin_size_unit)
518 ;;
519
520 type t =
521 | Outer_other of unit
522 | Outer of
523 { y : inner
524 ; z : unit
525 }
526 [@@deriving bin_io ~localize, sexp_of, variants]
527
528 let maximum_bin_size =
529 1
530 + Variants.fold
531 ~init:0
532 ~outer:(fun acc _ ->
533 max acc (maximum_bin_size_of_inner + Maximum.bin_size_unit))
534 ~outer_other:(fun acc _ -> max acc Maximum.bin_size_unit)
535 ;;
536
537 let minimum_bin_size =
538 1
539 + Variants.fold
540 ~init:Int.max_value
541 ~outer:(fun acc _ ->
542 min acc (minimum_bin_size_of_inner + Minimum.bin_size_unit))
543 ~outer_other:(fun acc _ -> min acc Minimum.bin_size_unit)
544 ;;
545 end
546
547 let inline_record =
548 let open Inline_record in
549 { writer = bin_write_t
550 ; writer_local = Some bin_write_t__local
551 ; reader = bin_read_t
552 ; values =
553 [ Outer { y = Inner { w = 0L; x = 0l }; z = () }
554 ; Outer { y = Inner { w = Int64.max_value; x = Int32.max_value }; z = () }
555 ; Outer { y = Inner_other (); z = () }
556 ; Outer_other ()
557 ]
558 ; equal = ( = )
559 ; sexp_of = [%sexp_of: t]
560 ; hi_bound = Some maximum_bin_size
561 ; lo_bound = minimum_bin_size
562 }
563 ;;
564 end
565
566 let buf = Bigstring.create 1024
567
568 let gen_tests t =
569 let bin_protted_values =
570 List.map t.values ~f:(fun v ->
571 let len = t.writer buf ~pos:0 v in
572 let str = Bigstring.To_string.sub buf ~pos:0 ~len in
573 (match t.writer_local with
574 | None -> ()
575 | Some writer_local ->
576 let len = writer_local buf ~pos:0 v in
577 let str_local = Bigstring.To_string.sub buf ~pos:0 ~len in
578 if String.( <> ) str str_local
579 then
580 printf ", write_local output (%s) differs from write output (%s)" str_local str);
581 str)
582 in
583 let hex_size =
584 List.fold bin_protted_values ~init:0 ~f:(fun acc s -> Int.max acc (String.length s))
585 in
586 let min, max =
587 List.fold2_exn
588 t.values
589 bin_protted_values
590 ~init:(Int.max_value, 0)
591 ~f:(fun (min, max) v s ->
592 let len = String.length s in
593 printf !"%s -> %{Sexp}" (to_hex s hex_size) (t.sexp_of v);
594 Bigstring.From_string.blito ~src:s ~dst:buf ();
595 let pos_ref = ref 0 in
596 let v' = t.reader buf ~pos_ref in
597 let len' = !pos_ref in
598 let hi_bound = Option.value t.hi_bound ~default:Int.max_value in
599 if len < t.lo_bound || len > hi_bound
600 then printf ", bin_size outside of range %d..%d: %d" t.lo_bound hi_bound len;
601 if (not (t.equal v v')) || len <> len'
602 then
603 printf
604 !", read test failed: read %d byte%s as %{Sexp}"
605 len'
606 (if len' = 1 then "" else "s")
607 (t.sexp_of v');
608 Out_channel.output_char stdout '\n';
609 Int.min min len, Int.max max len)
610 in
611 match t.hi_bound with
612 | None ->
613 if min <> t.lo_bound
614 then printf "invalid lower bound: %d, expected: %d\n" min t.lo_bound
615 | Some hi_bound ->
616 if min <> t.lo_bound || max <> hi_bound
617 then printf "invalid bounds: %d..%d, expected: %d..%d\n" min max t.lo_bound hi_bound
618 ;;
619
620 let%expect_test "Non-integer bin_prot size tests" =
621 gen_tests Tests.unit;
622 [%expect {| 00 -> () |}];
623 gen_tests Tests.bool;
624 [%expect {|
625 01 -> true
626 00 -> false
627 |}];
628 gen_tests Tests.char;
629 [%expect
630 {|
631 00 -> "\000"
632 41 -> A
633 7a -> z
634 3b -> ";"
635 ff -> "\255"
636 |}];
637 gen_tests Tests.digest;
638 [%expect
639 {| ef cd ab 89 67 45 23 01 ef cd ab 89 67 45 23 01 -> 0123456789abcdef0123456789abcdef |}];
640 gen_tests Tests.float;
641 [%expect
642 {|
643 3c b0 00 00 00 00 00 00 -> 2.2204460492503131E-16
644 7f f0 00 00 00 00 00 00 -> INF
645 7f ef ff ff ff ff ff ff -> 1.7976931348623157E+308
646 7f f0 00 00 00 00 00 00 -> INF
647 00 10 00 00 00 00 00 00 -> 2.2250738585072014E-308
648 00 00 00 00 00 00 00 01 -> 4.94065645841247E-324
649 ff f0 00 00 00 00 00 00 -> -INF
650 bf f0 00 00 00 00 00 00 -> -1
651 ff f0 00 00 00 00 00 00 -> -INF
652 3f f0 00 00 00 00 00 00 -> 1
653 3e 7a d7 f2 9a bc af 48 -> 1E-07
654 00 00 00 00 00 00 00 00 -> 0
655 |}];
656 gen_tests Tests.float_nan;
657 Expect_test_patterns.require_match
658 [%here]
659 {|
660 7f f{8,0} 00 00 00 00 00 01 -> NAN (glob)
661 |};
662 gen_tests Tests.vec;
663 [%expect
664 {|
665 .. .. .. .. .. .. .. .. 00 -> ()
666 3f f0 00 00 00 00 00 00 01 -> (1)
667 |}];
668 gen_tests Tests.float32_vec;
669 [%expect {|
670 .. .. .. .. 00 -> ()
671 3f 80 00 00 01 -> (1)
672 |}];
673 gen_tests Tests.float64_vec;
674 [%expect
675 {|
676 .. .. .. .. .. .. .. .. 00 -> ()
677 3f f0 00 00 00 00 00 00 01 -> (1)
678 |}];
679 gen_tests Tests.mat;
680 [%expect
681 {|
682 .. .. .. .. .. .. .. .. 00 00 -> ()
683 3f f0 00 00 00 00 00 00 01 01 -> ((1))
684 |}];
685 gen_tests Tests.float32_mat;
686 [%expect {|
687 .. .. .. .. 00 00 -> ()
688 3f 80 00 00 01 01 -> ((1))
689 |}];
690 gen_tests Tests.float64_mat;
691 [%expect
692 {|
693 .. .. .. .. .. .. .. .. 00 00 -> ()
694 3f f0 00 00 00 00 00 00 01 01 -> ((1))
695 |}];
696 gen_tests Tests.bigstring;
697 [%expect {|
698 .. .. .. .. .. 00 -> ""
699 6f 6c 6c 65 68 05 -> hello
700 |}];
701 gen_tests Tests.floatarray;
702 [%expect
703 {|
704 .. .. .. .. .. .. .. .. 00 -> ()
705 00 00 00 00 00 00 00 00 01 -> (0)
706 |}];
707 gen_tests Tests.ref;
708 [%expect
709 {|
710 .. .. .. .. 00 -> 0
711 .. .. .. .. 01 -> 1
712 .. .. .. ff ff -> -1
713 7f ff ff ff fd -> 2147483647
714 80 00 00 00 fd -> -2147483648
715 |}];
716 gen_tests Tests.lazy_t;
717 [%expect
718 {|
719 .. .. .. .. 00 -> 0
720 .. .. .. .. 01 -> 1
721 .. .. .. ff ff -> -1
722 7f ff ff ff fd -> 2147483647
723 80 00 00 00 fd -> -2147483648
724 |}];
725 gen_tests Tests.option;
726 [%expect
727 {|
728 .. .. .. .. .. 00 -> ()
729 .. .. .. .. 00 01 -> (0)
730 .. .. .. .. 01 01 -> (1)
731 .. .. .. ff ff 01 -> (-1)
732 7f ff ff ff fd 01 -> (2147483647)
733 80 00 00 00 fd 01 -> (-2147483648)
734 |}];
735 gen_tests Tests.pair;
736 [%expect
737 {|
738 .. .. .. .. .. .. .. .. 00 00 -> (0 0)
739 .. .. .. .. .. .. .. .. 01 01 -> (1 1)
740 .. .. .. .. .. .. ff ff ff ff -> (-1 -1)
741 7f ff ff ff fd 7f ff ff ff fd -> (2147483647 2147483647)
742 80 00 00 00 fd 80 00 00 00 fd -> (-2147483648 -2147483648)
743 |}];
744 gen_tests Tests.triple;
745 [%expect
746 {|
747 .. .. .. .. .. .. .. .. .. .. .. .. 00 00 00 -> (0 0 0)
748 .. .. .. .. .. .. .. .. .. .. .. .. 01 01 01 -> (1 1 1)
749 .. .. .. .. .. .. .. .. .. ff ff ff ff ff ff -> (-1 -1 -1)
750 7f ff ff ff fd 7f ff ff ff fd 7f ff ff ff fd -> (2147483647 2147483647 2147483647)
751 80 00 00 00 fd 80 00 00 00 fd 80 00 00 00 fd -> (-2147483648 -2147483648 -2147483648)
752 |}];
753 gen_tests Tests.list;
754 [%expect
755 {|
756 .. .. .. .. .. .. .. .. .. .. 00 -> ()
757 .. .. .. .. .. .. .. .. .. 00 01 -> (0)
758 .. .. .. .. .. .. .. .. 01 00 02 -> (0 1)
759 .. .. .. .. .. .. .. ff ff 01 02 -> (1 -1)
760 .. .. .. .. 7f ff ff ff fd 00 02 -> (0 2147483647)
761 80 00 00 00 fd 7f ff ff ff fd 02 -> (2147483647 -2147483648)
762 |}];
763 gen_tests Tests.array;
764 [%expect
765 {|
766 .. .. .. .. .. .. .. .. .. .. 00 -> ()
767 .. .. .. .. .. .. .. .. .. 00 01 -> (0)
768 .. .. .. .. .. .. .. .. 01 00 02 -> (0 1)
769 .. .. .. .. .. .. .. ff ff 01 02 -> (1 -1)
770 .. .. .. .. 7f ff ff ff fd 00 02 -> (0 2147483647)
771 80 00 00 00 fd 7f ff ff ff fd 02 -> (2147483647 -2147483648)
772 |}];
773 gen_tests Tests.record1;
774 [%expect
775 {|
776 .. .. .. .. 00 00 00 00 00 00 00 00 00 -> ((x 0)(y 0))
777 7f f0 00 00 00 00 00 00 7f ff ff ff fd -> ((x 2147483647)(y INF))
778 |}];
779 gen_tests Tests.record2;
780 [%expect
781 {|
782 .. .. .. .. .. .. .. .. .. .. .. .. 00 00 00 -> ((y((w 0)(x 0)))(z()))
783 00 7f ff ff ff fd 7f ff ff ff ff ff ff ff fc -> ((y((w 9223372036854775807)(x 2147483647)))(z()))
784 |}];
785 gen_tests Tests.inline_record;
786 [%expect
787 {|
788 .. .. .. .. .. .. .. .. .. .. .. .. 00 00 00 00 01 -> (Outer(y(Inner(w 0)(x 0)))(z()))
789 00 7f ff ff ff fd 7f ff ff ff ff ff ff ff fc 00 01 -> (Outer(y(Inner(w 9223372036854775807)(x 2147483647)))(z()))
790 .. .. .. .. .. .. .. .. .. .. .. .. .. 00 00 01 01 -> (Outer(y(Inner_other()))(z()))
791 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 00 00 -> (Outer_other())
792 |}]
793 ;;
794
795 (* Polymorphic hash is not the same when running in javascript.
796 This makes the test fail because of different ordering. *)
797 let%expect_test ("Non-integer bin_prot size tests (no js)" [@tags "no-js"]) =
798 gen_tests Tests.hashtbl;
799 [%expect
800 {|
801 .. .. .. .. .. .. .. .. .. .. .. .. .. .. 00 -> ()
802 .. .. .. .. .. .. .. .. .. .. .. .. 00 00 01 -> ((0 0))
803 .. .. .. .. .. .. .. .. .. .. 00 00 01 01 02 -> ((0 0)(1 1))
804 .. .. 00 00 7f ff ff ff fd 7f ff ff ff fd 02 -> ((0 0)(2147483647 2147483647))
805 80 00 00 00 fd 80 00 00 00 fd ff ff ff ff 02 -> ((-2147483648 -2147483648)(-1 -1))
806 |}]
807 ;;