File: test_pp.ml

package info (click to toggle)
janest-base 0.17.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,632 kB
  • sloc: ml: 48,653; ansic: 281; javascript: 126; makefile: 14
file content (52 lines) | stat: -rw-r--r-- 968 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
open! Import

let to_string pp v =
  pp Stdlib.Format.str_formatter v;
  Stdlib.Format.flush_str_formatter ()
;;

let print pp v = Stdlib.Printf.printf "%s\n" (to_string pp v)
let print_all pp vs = List.iter ~f:(print pp) vs

let%expect_test "pretty-printers" =
  print_all Char.pp [ '\000'; '\r'; 'a' ];
  [%expect {|
    '\000'
    '\r'
    'a'
    |}];
  print_all String.pp [ ""; "foo"; "abc\tdef" ];
  [%expect {|
    ""
    "foo"
    "abc\tdef"
    |}];
  print_all Sign.pp Sign.all;
  [%expect {|
    Neg
    Zero
    Pos
    |}];
  print_all Bool.pp Bool.all;
  [%expect {|
    false
    true
    |}];
  print_all Unit.pp Unit.all;
  [%expect {| () |}];
  print_all Nothing.pp Nothing.all;
  [%expect {| |}];
  print_all Float.pp [ 0.; 3.14; 1.0 /. 0.0 ];
  [%expect {|
    0.
    3.14
    inf
    |}];
  print_all Int.pp [ 0; 1 ];
  [%expect {|
    0
    1
    |}];
  print Info.pp (Info.create_s [%sexp "hello", "world"]);
  [%expect {| (hello world) |}]
;;