extend variant cases

This commit is contained in:
Galfour 2019-04-23 17:54:45 +00:00
parent f68d592653
commit 212ccd56c7
3 changed files with 11 additions and 1 deletions

View File

@ -1,9 +1,11 @@
type foobar is
| Foo of int
| Bar of bool
| Kee of nat
function fb(const p : foobar) : int is
block { skip } with (case p of
| Foo (n) -> n
| Bar (t) -> 42
| Kee (n) -> 23
end)

View File

@ -1,8 +1,10 @@
type foobar is
| Foo of int
| Bar of bool
| Kee of nat
const foo : foobar = Foo (42)
const bar : foobar = Bar (True)
const kee : foobar = Kee (23n)

View File

@ -22,6 +22,9 @@ let variant () : unit result =
let%bind () =
let expected = e_a_constructor "Bar" (e_a_bool true) in
expect_evaluate program "bar" expected in
let%bind () =
let expected = e_a_constructor "Kee" (e_a_nat 23) in
expect_evaluate program "kee" expected in
ok ()
let variant_matching () : unit result =
@ -29,7 +32,10 @@ let variant_matching () : unit result =
let%bind () =
let make_input = fun n -> e_a_constructor "Foo" (e_a_int n) in
let make_expected = e_a_int in
expect_n program "fb" make_input make_expected
expect_n program "fb" make_input make_expected >>? fun () ->
expect program "fb" (e_a_constructor "Kee" (e_a_nat 50)) (e_a_int 23) >>? fun () ->
expect program "fb" (e_a_constructor "Bar" (e_a_bool true)) (e_a_int 42) >>? fun () ->
ok ()
in
ok ()