File: t_option.ml

package info (click to toggle)
ocaml-containers 3.15%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,412 kB
  • sloc: ml: 33,221; sh: 122; makefile: 32
file content (30 lines) | stat: -rw-r--r-- 1,149 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
open CCOption
module T = (val Containers_testlib.make ~__FILE__ ())
include T;;

eq None (filter (( = ) 0) (Some 1));;
eq (Some 0) (filter (( = ) 0) (Some 0));;
eq None (filter (fun _ -> true) None);;

eq
  (try
     get_exn_or "ohno" (None : unit option);
     false
   with Invalid_argument s -> s = "ohno")
;;

t @@ fun () -> 123 = get_exn_or "yes" (Some 123);;
t @@ fun () -> sequence_l [ None; Some 1; Some 2 ] = None;;
t @@ fun () -> sequence_l [ Some 1; Some 2; Some 3 ] = Some [ 1; 2; 3 ];;
t @@ fun () -> sequence_l [] = Some [];;
t @@ fun () -> choice_iter (Iter.of_list [ None; Some 1; Some 2 ]) = Some 1;;
t @@ fun () -> choice_iter Iter.empty = None;;
t @@ fun () -> choice_iter (Iter.repeat None |> Iter.take 100) = None;;
t @@ fun () -> choice_seq (CCSeq.of_list [ None; Some 1; Some 2 ]) = Some 1;;
t @@ fun () -> choice_seq CCSeq.empty = None;;
t @@ fun () -> choice_seq (CCSeq.repeat None |> CCSeq.take 100) = None;;
t @@ fun () -> flatten None = None;;
t @@ fun () -> flatten (Some None) = None;;
t @@ fun () -> flatten (Some (Some 1)) = Some 1;;
t @@ fun () -> return_if false 1 = None;;
t @@ fun () -> return_if true 1 = Some 1