From eb855958184eec4ae63110b141d58726521611fe Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Wed, 20 Nov 2019 04:48:04 -0800 Subject: [PATCH] Add is_nat operator to CameLIGO --- src/passes/operators/operators.ml | 2 ++ src/test/contracts/isnat.mligo | 1 + src/test/integration_tests.ml | 14 ++++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 src/test/contracts/isnat.mligo diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index f7378aefd..e1bfb0417 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -208,6 +208,8 @@ module Simplify = struct ("abs" , "ABS") ; ("unit" , "UNIT") ; ("source" , "SOURCE") ; + + ("Michelson.is_nat" , "ISNAT") ; ] let type_constants = type_constants diff --git a/src/test/contracts/isnat.mligo b/src/test/contracts/isnat.mligo new file mode 100644 index 000000000..c5bea0294 --- /dev/null +++ b/src/test/contracts/isnat.mligo @@ -0,0 +1 @@ +let main (i: int) : nat option = Michelson.is_nat i diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index def453160..b509a845f 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1225,6 +1225,19 @@ let is_nat () : unit result = expect_eq program "main" input expected in ok () +let is_nat_mligo () : unit result = + let%bind program = mtype_file "./contracts/isnat.mligo" in + let%bind () = + let input = e_int 10 in + let expected = e_some (e_nat 10) in + expect_eq program "main" input expected + in + let%bind () = + let input = e_int (-10) in + let expected = e_none () in + expect_eq program "main" input expected + in ok () + let simple_access_ligo () : unit result = let%bind program = type_file "./contracts/simple_access.ligo" in let make_input = e_tuple [e_int 0; e_int 1] in @@ -1328,6 +1341,7 @@ let main = test_suite "Integration (End to End)" [ test "balance constant" balance_constant ; test "balance constant (mligo)" balance_constant_mligo ; test "is_nat" is_nat ; + test "is_not (mligo)" is_nat_mligo ; test "simple_access (ligo)" simple_access_ligo; test "deep_access (ligo)" deep_access_ligo; test "entrypoints (ligo)" entrypoints_ligo ;