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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
open! Core
open! Import
open Bonsai.For_open
open Proc
open Bonsai.Let_syntax
module Path = Bonsai.Private.Path
let%expect_test "path" =
let component =
let%sub () = opaque_const () in
let%sub path = Bonsai.Private.path in
return (Value.map path ~f:Path.to_unique_identifier_string)
in
let handle = Handle.create (Result_spec.string (module String)) component in
Handle.show handle;
[%expect {| bonsai_path_x_y_y_x |}]
;;
let%expect_test "path constant folding" =
let component =
let%sub () = Bonsai.const () in
let%sub path = Bonsai.Private.path in
return (Value.map path ~f:Path.to_unique_identifier_string)
in
let handle = Handle.create (Result_spec.string (module String)) component in
Handle.show handle;
[%expect {| bonsai_path_x_x |}]
;;
let assert_path_unique_id_is_alpha path =
let unique_id = Path.to_unique_identifier_string path in
assert (
String.for_all unique_id ~f:(function
| 'a' .. 'z' | '_' -> true
| _ -> false))
;;
let%test_unit "all the values are alpha" =
let string_id = Type_equal.Id.create ~name:"string" [%sexp_of: string] in
let keyed = Path.Elem.keyed ~compare:String.compare string_id |> unstage in
Quickcheck.test
String.quickcheck_generator
~sexp_of:[%sexp_of: string]
~f:(fun string ->
let path = Path.append Path.empty (Path.Elem.Assoc (keyed string)) in
assert_path_unique_id_is_alpha path)
;;
let%test_unit "larger groupings of paths behave" =
let string_id = Type_equal.Id.create ~name:"string" [%sexp_of: string] in
let keyed = Path.Elem.keyed ~compare:String.compare string_id |> unstage in
let module P = struct
type t =
| From
| Into
| Assoc of string
| Switch of int
[@@deriving quickcheck, sexp]
let to_path_element = function
| From -> Path.Elem.Subst_from
| Into -> Path.Elem.Subst_into
| Assoc s -> Path.Elem.Assoc (keyed s)
| Switch i -> Path.Elem.Switch i
;;
end
in
Quickcheck.test
[%quickcheck.generator: P.t list]
~sexp_of:[%sexp_of: P.t list]
~f:(fun path ->
let path =
path |> List.map ~f:P.to_path_element |> List.fold ~init:Path.empty ~f:Path.append
in
assert_path_unique_id_is_alpha path)
;;