From c4cc4fcba91e296341e006227f0c50b265035c3e Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Tue, 22 Oct 2019 19:28:13 -0700 Subject: [PATCH] Add set size op for CameLIGO and PascaLIGO --- src/passes/operators/operators.ml | 2 ++ src/test/contracts/set_arithmetic.ligo | 4 ++-- src/test/contracts/set_arithmetic.mligo | 4 ++++ src/test/integration_tests.ml | 12 ++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/test/contracts/set_arithmetic.mligo diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 65b55c18e..f9665be7c 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -82,6 +82,7 @@ module Simplify = struct ("set_remove" , "SET_REMOVE") ; ("set_iter" , "SET_ITER") ; ("set_fold" , "SET_FOLD") ; + ("set_size" , "SIZE"); ("list_iter" , "LIST_ITER") ; ("list_fold" , "LIST_FOLD") ; ("list_map" , "LIST_MAP") ; @@ -154,6 +155,7 @@ module Simplify = struct ("Set.add" , "SET_ADD") ; ("Set.remove" , "SET_REMOVE") ; ("Set.fold" , "SET_FOLD") ; + ("Set.size", "SIZE") ; ("Map.find_opt" , "MAP_FIND_OPT") ; ("Map.find" , "MAP_FIND") ; diff --git a/src/test/contracts/set_arithmetic.ligo b/src/test/contracts/set_arithmetic.ligo index 879d13940..1744814c8 100644 --- a/src/test/contracts/set_arithmetic.ligo +++ b/src/test/contracts/set_arithmetic.ligo @@ -32,5 +32,5 @@ function patch_op_empty (var s: set(string)) : set(string) is function mem_op (const s : set(string)) : bool is begin skip end with set_mem("foobar" , s) - - +function size_op (const s : set(string)) : nat is + set_size(s); diff --git a/src/test/contracts/set_arithmetic.mligo b/src/test/contracts/set_arithmetic.mligo new file mode 100644 index 000000000..23947077d --- /dev/null +++ b/src/test/contracts/set_arithmetic.mligo @@ -0,0 +1,4 @@ +(* Test set operations in CameLIGO *) + +let size_op (s: string set) : nat = + Set.size s diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 401f446ce..a639d0a78 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -280,6 +280,10 @@ let set_arithmetic () : unit result = expect_eq program "patch_op_empty" (e_set [e_string "foo" ; e_string "bar"]) (e_set [e_string "foo" ; e_string "bar"]) in + let%bind () = + expect_eq program "size_op" + (e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"]) + (e_nat 3) in let%bind () = expect_eq program "mem_op" (e_set [e_string "foo" ; e_string "bar" ; e_string "foobar"]) @@ -295,6 +299,13 @@ let set_arithmetic () : unit result = in ok () +let set_arithmetic_mligo () : unit result = + let%bind program = mtype_file "./contracts/set_arithmetic.mligo" in + let%bind () = + expect_eq program "size_op" + (e_set [e_string "foo"; e_string "bar"; e_string "foobar"]) + (e_nat 3) in ok () + let unit_expression () : unit result = let%bind program = type_file "./contracts/unit.ligo" in expect_eq_evaluate program "u" (e_unit ()) @@ -936,6 +947,7 @@ let main = test_suite "Integration (End to End)" [ test "string_arithmetic (mligo)" string_arithmetic_mligo ; test "bytes_arithmetic" bytes_arithmetic ; test "set_arithmetic" set_arithmetic ; + test "set_arithmetic (mligo)" set_arithmetic_mligo ; test "unit" unit_expression ; test "string" string_expression ; test "option" option ;