From 6fc1b6430bcf7f78276abdb4495b436d4dc0b2d5 Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Wed, 12 Jun 2019 23:27:54 -0700 Subject: [PATCH] Add a little bit of tez tests, fix cameligo lexer bug --- src/passes/1-parser/ligodity/Lexer.mll | 2 +- src/test/contracts/tez.ligo | 4 ++++ src/test/contracts/tez.mligo | 5 +++++ src/test/integration_tests.ml | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/test/contracts/tez.ligo create mode 100644 src/test/contracts/tez.mligo diff --git a/src/passes/1-parser/ligodity/Lexer.mll b/src/passes/1-parser/ligodity/Lexer.mll index 9c2274f36..e94e67447 100644 --- a/src/passes/1-parser/ligodity/Lexer.mll +++ b/src/passes/1-parser/ligodity/Lexer.mll @@ -276,7 +276,7 @@ rule scan = parse | integer as n { Token.Int (n, Z.of_string n) } | integer as n "p" { Token.Nat (n ^ "p", Z.of_string n) } -| integer as tz "tz" { Token.Mtz (tz ^ "tz", Z.of_string tz) } +| integer as tz "tz" { Token.Mtz (tz ^ "tz", Z.mul (Z.of_int 1_000_000) (Z.of_string tz)) } | decimal as tz "tz" { match format_tz tz with Some z -> Token.Mtz (tz ^ "tz", z) diff --git a/src/test/contracts/tez.ligo b/src/test/contracts/tez.ligo new file mode 100644 index 000000000..14d7d194f --- /dev/null +++ b/src/test/contracts/tez.ligo @@ -0,0 +1,4 @@ +const add_tez : tez = 21mtz + 21mtz; +const sub_tez : tez = 21mtz - 20mtz; +(* is this enough? *) +const not_enough_tez : tez = 4611686018427387903mtz; diff --git a/src/test/contracts/tez.mligo b/src/test/contracts/tez.mligo new file mode 100644 index 000000000..e2aaed7f8 --- /dev/null +++ b/src/test/contracts/tez.mligo @@ -0,0 +1,5 @@ +let add_tez : tez = 0.000021tz + 0.000021tz +let sub_tez : tez = 0.000021tz - 0.000020tz +let not_enough_tez : tez = 4611686018427.387903tz + +let add_more_tez : tez = 100tz + 10tz + 1tz + 0.1tz + 0.01tz + 0.001tz diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 172ab1c6e..7297a0c31 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -787,6 +787,21 @@ let website2_ligo () : unit result = e_pair (e_typed_list [] t_operation) (e_int (op 42 n)) in expect_eq_n program "main" make_input make_expected +let tez_ligo () : unit result = + let%bind program = type_file "./contracts/tez.ligo" in + let%bind _ = expect_eq_evaluate program "add_tez" (e_mutez 42) in + let%bind _ = expect_eq_evaluate program "sub_tez" (e_mutez 1) in + let%bind _ = expect_eq_evaluate program "not_enough_tez" (e_mutez 4611686018427387903) in + ok () + +let tez_mligo () : unit result = + let%bind program = mtype_file "./contracts/tez.mligo" in + let%bind _ = expect_eq_evaluate program "add_tez" (e_mutez 42) in + let%bind _ = expect_eq_evaluate program "sub_tez" (e_mutez 1) in + let%bind _ = expect_eq_evaluate program "not_enough_tez" (e_mutez 4611686018427387903) in + let%bind _ = expect_eq_evaluate program "add_more_tez" (e_mutez 111111000) in + ok () + let main = test_suite "Integration (End to End)" [ test "type alias" type_alias ; test "function" function_ ; @@ -844,6 +859,8 @@ let main = test_suite "Integration (End to End)" [ test "lambda mligo" lambda_mligo ; test "lambda ligo" lambda_ligo ; (* test "lambda2 mligo" lambda2_mligo ; *) + test "tez (ligo)" tez_ligo ; + test "tez (mligo)" tez_mligo ; test "website1 ligo" website1_ligo ; test "website2 ligo" website2_ligo ; ]