From c8ed8c38ccfa0760434abce3954148c3ef7f67d9 Mon Sep 17 00:00:00 2001 From: Sander Spies Date: Wed, 3 Jun 2020 12:41:26 +0200 Subject: [PATCH] ReasonLIGO pretty printing testing. --- src/passes/1-parser/reasonligo/Pretty.ml | 2 +- src/test/contracts/dune | 165 ++++++++++++++++++ src/test/contracts/expected/address.religo | 6 + src/test/contracts/expected/amount.religo | 8 + src/test/contracts/expected/arithmetic.religo | 17 ++ .../expected/bad_address_format.religo | 3 + .../expected/balance_constant.religo | 7 + .../expected/bitwise_arithmetic.religo | 9 + .../expected/boolean_operators.religo | 9 + .../expected/bytes_arithmetic.religo | 5 + .../contracts/expected/bytes_unpack.religo | 20 +++ .../contracts/expected/check_signature.religo | 6 + src/test/contracts/expected/closure.religo | 8 + .../expected/condition-shadowing.religo | 15 ++ src/test/contracts/expected/condition.religo | 8 + src/test/contracts/expected/counter.religo | 5 + src/test/contracts/expected/crypto.religo | 3 + src/test/contracts/expected/empty_case.religo | 8 + src/test/contracts/expected/eq_bool.religo | 8 + src/test/contracts/expected/failwith.religo | 7 + .../contracts/expected/function-shared.religo | 5 + src/test/contracts/expected/high-order.religo | 53 ++++++ .../expected/implicit_account.religo | 3 + src/test/contracts/expected/included.religo | 1 + src/test/contracts/expected/includer.religo | 3 + src/test/contracts/expected/key_hash.religo | 8 + src/test/contracts/expected/lambda.religo | 5 + src/test/contracts/expected/lambda2.religo | 5 + .../contracts/expected/let_multiple.religo | 13 ++ src/test/contracts/expected/letin.religo | 39 +++++ src/test/contracts/expected/list.religo | 42 +++++ src/test/contracts/expected/loop.religo | 51 ++++++ src/test/contracts/expected/map.religo | 71 ++++++++ src/test/contracts/expected/match.religo | 17 ++ src/test/contracts/expected/match_bis.religo | 18 ++ .../expected/michelson_pair_tree.religo | 13 ++ .../expected/multiple-parameters.religo | 6 + src/test/contracts/expected/multisig.religo | 97 ++++++++++ .../contracts/expected/no_semicolon.religo | 18 ++ src/test/contracts/expected/pledge.religo | 35 ++++ src/test/contracts/expected/record.religo | 36 ++++ src/test/contracts/expected/recursion.religo | 17 ++ .../contracts/expected/self_address.religo | 1 + .../contracts/expected/set_arithmetic.religo | 17 ++ .../contracts/expected/set_delegate.religo | 6 + .../expected/single_record_item.religo | 3 + .../expected/string_arithmetic.religo | 5 + .../contracts/expected/super-counter.religo | 16 ++ src/test/contracts/expected/tuple.religo | 13 ++ src/test/contracts/expected/tuple_list.religo | 3 + .../expected/tuple_param_destruct.religo | 4 + src/test/contracts/expected/tuple_type.religo | 48 +++++ .../expected/tuples_no_annotation.religo | 9 + .../tuples_sequences_functions.religo | 65 +++++++ src/test/contracts/expected/variant.religo | 7 + src/test/contracts/expected/website2.religo | 18 ++ src/test/contracts/super-counter.religo | 2 +- src/test/integration_tests.ml | 1 + 58 files changed, 1091 insertions(+), 2 deletions(-) create mode 100644 src/test/contracts/dune create mode 100644 src/test/contracts/expected/address.religo create mode 100644 src/test/contracts/expected/amount.religo create mode 100644 src/test/contracts/expected/arithmetic.religo create mode 100644 src/test/contracts/expected/bad_address_format.religo create mode 100644 src/test/contracts/expected/balance_constant.religo create mode 100644 src/test/contracts/expected/bitwise_arithmetic.religo create mode 100644 src/test/contracts/expected/boolean_operators.religo create mode 100644 src/test/contracts/expected/bytes_arithmetic.religo create mode 100644 src/test/contracts/expected/bytes_unpack.religo create mode 100644 src/test/contracts/expected/check_signature.religo create mode 100644 src/test/contracts/expected/closure.religo create mode 100644 src/test/contracts/expected/condition-shadowing.religo create mode 100644 src/test/contracts/expected/condition.religo create mode 100644 src/test/contracts/expected/counter.religo create mode 100644 src/test/contracts/expected/crypto.religo create mode 100644 src/test/contracts/expected/empty_case.religo create mode 100644 src/test/contracts/expected/eq_bool.religo create mode 100644 src/test/contracts/expected/failwith.religo create mode 100644 src/test/contracts/expected/function-shared.religo create mode 100644 src/test/contracts/expected/high-order.religo create mode 100644 src/test/contracts/expected/implicit_account.religo create mode 100644 src/test/contracts/expected/included.religo create mode 100644 src/test/contracts/expected/includer.religo create mode 100644 src/test/contracts/expected/key_hash.religo create mode 100644 src/test/contracts/expected/lambda.religo create mode 100644 src/test/contracts/expected/lambda2.religo create mode 100644 src/test/contracts/expected/let_multiple.religo create mode 100644 src/test/contracts/expected/letin.religo create mode 100644 src/test/contracts/expected/list.religo create mode 100644 src/test/contracts/expected/loop.religo create mode 100644 src/test/contracts/expected/map.religo create mode 100644 src/test/contracts/expected/match.religo create mode 100644 src/test/contracts/expected/match_bis.religo create mode 100644 src/test/contracts/expected/michelson_pair_tree.religo create mode 100644 src/test/contracts/expected/multiple-parameters.religo create mode 100644 src/test/contracts/expected/multisig.religo create mode 100644 src/test/contracts/expected/no_semicolon.religo create mode 100644 src/test/contracts/expected/pledge.religo create mode 100644 src/test/contracts/expected/record.religo create mode 100644 src/test/contracts/expected/recursion.religo create mode 100644 src/test/contracts/expected/self_address.religo create mode 100644 src/test/contracts/expected/set_arithmetic.religo create mode 100644 src/test/contracts/expected/set_delegate.religo create mode 100644 src/test/contracts/expected/single_record_item.religo create mode 100644 src/test/contracts/expected/string_arithmetic.religo create mode 100644 src/test/contracts/expected/super-counter.religo create mode 100644 src/test/contracts/expected/tuple.religo create mode 100644 src/test/contracts/expected/tuple_list.religo create mode 100644 src/test/contracts/expected/tuple_param_destruct.religo create mode 100644 src/test/contracts/expected/tuple_type.religo create mode 100644 src/test/contracts/expected/tuples_no_annotation.religo create mode 100644 src/test/contracts/expected/tuples_sequences_functions.religo create mode 100644 src/test/contracts/expected/variant.religo create mode 100644 src/test/contracts/expected/website2.religo diff --git a/src/passes/1-parser/reasonligo/Pretty.ml b/src/passes/1-parser/reasonligo/Pretty.ml index f462d7a9b..e6902eaee 100644 --- a/src/passes/1-parser/reasonligo/Pretty.ml +++ b/src/passes/1-parser/reasonligo/Pretty.ml @@ -317,7 +317,7 @@ and pp_projection {value; _} = let fields = Utils.nsepseq_to_list field_path and sep = string "." ^^ break 0 in let fields = separate_map sep pp_selection fields in - group (pp_ident struct_name ^^ string "." ^^ break 0 ^^ fields) + group (pp_ident struct_name ^^ break 0 ^^ string "[" ^^ fields ^^ string "]") and pp_selection = function FieldName v -> string v.value diff --git a/src/test/contracts/dune b/src/test/contracts/dune new file mode 100644 index 000000000..b1cec5a5b --- /dev/null +++ b/src/test/contracts/dune @@ -0,0 +1,165 @@ +(rule (targets address.output) (action (with-stdout-to address.output (run ligo "pretty-print" "address.religo")))) +(rule (targets amount.output) (action (with-stdout-to amount.output (run ligo "pretty-print" "amount.religo")))) +(rule (targets arithmetic.output) (action (with-stdout-to arithmetic.output (run ligo "pretty-print" "arithmetic.religo")))) +(rule (targets bad_address_format.output) (action (with-stdout-to bad_address_format.output (run ligo "pretty-print" "bad_address_format.religo")))) +(rule (targets balance_constant.output) (action (with-stdout-to balance_constant.output (run ligo "pretty-print" "balance_constant.religo")))) +(rule (targets bitwise_arithmetic.output) (action (with-stdout-to bitwise_arithmetic.output (run ligo "pretty-print" "bitwise_arithmetic.religo")))) +(rule (targets boolean_operators.output) (action (with-stdout-to boolean_operators.output (run ligo "pretty-print" "boolean_operators.religo")))) +(rule (targets bytes_arithmetic.output) (action (with-stdout-to bytes_arithmetic.output (run ligo "pretty-print" "bytes_arithmetic.religo")))) +(rule (targets bytes_unpack.output) (action (with-stdout-to bytes_unpack.output (run ligo "pretty-print" "bytes_unpack.religo")))) +(rule (targets check_signature.output) (action (with-stdout-to check_signature.output (run ligo "pretty-print" "check_signature.religo")))) +(rule (targets closure.output) (action (with-stdout-to closure.output (run ligo "pretty-print" "closure.religo")))) +(rule (targets condition-shadowing.output) (action (with-stdout-to condition-shadowing.output (run ligo "pretty-print" "condition-shadowing.religo")))) +(rule (targets condition.output) (action (with-stdout-to condition.output (run ligo "pretty-print" "condition.religo")))) +(rule (targets counter.output) (action (with-stdout-to counter.output (run ligo "pretty-print" "counter.religo")))) +(rule (targets crypto.output) (action (with-stdout-to crypto.output (run ligo "pretty-print" "crypto.religo")))) +(rule (targets empty_case.output) (action (with-stdout-to empty_case.output (run ligo "pretty-print" "empty_case.religo")))) +(rule (targets eq_bool.output) (action (with-stdout-to eq_bool.output (run ligo "pretty-print" "eq_bool.religo")))) +(rule (targets failwith.output) (action (with-stdout-to failwith.output (run ligo "pretty-print" "failwith.religo")))) +(rule (targets function-shared.output) (action (with-stdout-to function-shared.output (run ligo "pretty-print" "function-shared.religo")))) +(rule (targets high-order.output) (action (with-stdout-to high-order.output (run ligo "pretty-print" "high-order.religo")))) +(rule (targets implicit_account.output) (action (with-stdout-to implicit_account.output (run ligo "pretty-print" "implicit_account.religo")))) +(rule (targets included.output) (action (with-stdout-to included.output (run ligo "pretty-print" "included.religo")))) +(rule (targets includer.output) (action (with-stdout-to includer.output (run ligo "pretty-print" "includer.religo")))) +(rule (targets key_hash.output) (action (with-stdout-to key_hash.output (run ligo "pretty-print" "key_hash.religo")))) +(rule (targets lambda.output) (action (with-stdout-to lambda.output (run ligo "pretty-print" "lambda.religo")))) +(rule (targets lambda2.output) (action (with-stdout-to lambda2.output (run ligo "pretty-print" "lambda2.religo")))) +(rule (targets let_multiple.output) (action (with-stdout-to let_multiple.output (run ligo "pretty-print" "let_multiple.religo")))) +(rule (targets letin.output) (action (with-stdout-to letin.output (run ligo "pretty-print" "letin.religo")))) +(rule (targets list.output) (action (with-stdout-to list.output (run ligo "pretty-print" "list.religo")))) +(rule (targets loop.output) (action (with-stdout-to loop.output (run ligo "pretty-print" "loop.religo")))) +(rule (targets map.output) (action (with-stdout-to map.output (run ligo "pretty-print" "map.religo")))) +(rule (targets match_bis.output) (action (with-stdout-to match_bis.output (run ligo "pretty-print" "match_bis.religo")))) +(rule (targets match.output) (action (with-stdout-to match.output (run ligo "pretty-print" "match.religo")))) +(rule (targets michelson_pair_tree.output) (action (with-stdout-to michelson_pair_tree.output (run ligo "pretty-print" "michelson_pair_tree.religo")))) +(rule (targets multiple-parameters.output) (action (with-stdout-to multiple-parameters.output (run ligo "pretty-print" "multiple-parameters.religo")))) +(rule (targets multisig.output) (action (with-stdout-to multisig.output (run ligo "pretty-print" "multisig.religo")))) +(rule (targets no_semicolon.output) (action (with-stdout-to no_semicolon.output (run ligo "pretty-print" "no_semicolon.religo")))) +(rule (targets pledge.output) (action (with-stdout-to pledge.output (run ligo "pretty-print" "pledge.religo")))) +(rule (targets record.output) (action (with-stdout-to record.output (run ligo "pretty-print" "record.religo")))) +(rule (targets recursion.output) (action (with-stdout-to recursion.output (run ligo "pretty-print" "recursion.religo")))) +(rule (targets self_address.output) (action (with-stdout-to self_address.output (run ligo "pretty-print" "self_address.religo")))) +(rule (targets set_arithmetic.output) (action (with-stdout-to set_arithmetic.output (run ligo "pretty-print" "set_arithmetic.religo")))) +(rule (targets set_delegate.output) (action (with-stdout-to set_delegate.output (run ligo "pretty-print" "set_delegate.religo")))) +(rule (targets single_record_item.output) (action (with-stdout-to single_record_item.output (run ligo "pretty-print" "single_record_item.religo")))) +(rule (targets string_arithmetic.output) (action (with-stdout-to string_arithmetic.output (run ligo "pretty-print" "string_arithmetic.religo")))) +(rule (targets super-counter.output) (action (with-stdout-to super-counter.output (run ligo "pretty-print" "super-counter.religo")))) +(rule (targets tuple_list.output) (action (with-stdout-to tuple_list.output (run ligo "pretty-print" "tuple_list.religo")))) +(rule (targets tuple_param_destruct.output) (action (with-stdout-to tuple_param_destruct.output (run ligo "pretty-print" "tuple_param_destruct.religo")))) +(rule (targets tuple_type.output) (action (with-stdout-to tuple_type.output (run ligo "pretty-print" "tuple_type.religo")))) +(rule (targets tuple.output) (action (with-stdout-to tuple.output (run ligo "pretty-print" "tuple.religo")))) +(rule (targets tuples_no_annotation.output) (action (with-stdout-to tuples_no_annotation.output (run ligo "pretty-print" "tuples_no_annotation.religo")))) +(rule (targets tuples_sequences_functions.output) (action (with-stdout-to tuples_sequences_functions.output (run ligo "pretty-print" "tuples_sequences_functions.religo")))) +(rule (targets variant.output) (action (with-stdout-to variant.output (run ligo "pretty-print" "variant.religo")))) +(rule (targets website2.output) (action (with-stdout-to website2.output (run ligo "pretty-print" "website2.religo")))) + + +(alias (name runtest) (action (diff expected/address.religo address.output))) +(alias (name runtest) (action (diff expected/amount.religo amount.output))) +(alias (name runtest) (action (diff expected/arithmetic.religo arithmetic.output))) +(alias (name runtest) (action (diff expected/bad_address_format.religo bad_address_format.output))) +(alias (name runtest) (action (diff expected/balance_constant.religo balance_constant.output))) +(alias (name runtest) (action (diff expected/bitwise_arithmetic.religo bitwise_arithmetic.output))) +(alias (name runtest) (action (diff expected/boolean_operators.religo boolean_operators.output))) +(alias (name runtest) (action (diff expected/bytes_arithmetic.religo bytes_arithmetic.output))) +(alias (name runtest) (action (diff expected/bytes_unpack.religo bytes_unpack.output))) +(alias (name runtest) (action (diff expected/check_signature.religo check_signature.output))) +(alias (name runtest) (action (diff expected/closure.religo closure.output))) +(alias (name runtest) (action (diff expected/condition-shadowing.religo condition-shadowing.output))) +(alias (name runtest) (action (diff expected/condition.religo condition.output))) +(alias (name runtest) (action (diff expected/counter.religo counter.output))) +(alias (name runtest) (action (diff expected/crypto.religo crypto.output))) +(alias (name runtest) (action (diff expected/empty_case.religo empty_case.output))) +(alias (name runtest) (action (diff expected/eq_bool.religo eq_bool.output))) +(alias (name runtest) (action (diff expected/failwith.religo failwith.output))) +(alias (name runtest) (action (diff expected/function-shared.religo function-shared.output))) +(alias (name runtest) (action (diff expected/high-order.religo high-order.output))) +(alias (name runtest) (action (diff expected/implicit_account.religo implicit_account.output))) +(alias (name runtest) (action (diff expected/included.religo included.output))) +(alias (name runtest) (action (diff expected/includer.religo includer.output))) +(alias (name runtest) (action (diff expected/key_hash.religo key_hash.output))) +(alias (name runtest) (action (diff expected/lambda.religo lambda.output))) +(alias (name runtest) (action (diff expected/lambda2.religo lambda2.output))) +(alias (name runtest) (action (diff expected/let_multiple.religo let_multiple.output))) +(alias (name runtest) (action (diff expected/letin.religo letin.output))) +(alias (name runtest) (action (diff expected/list.religo list.output))) +(alias (name runtest) (action (diff expected/loop.religo loop.output))) +(alias (name runtest) (action (diff expected/map.religo map.output))) +(alias (name runtest) (action (diff expected/match_bis.religo match_bis.output))) +(alias (name runtest) (action (diff expected/match.religo match.output))) +(alias (name runtest) (action (diff expected/michelson_pair_tree.religo michelson_pair_tree.output))) +(alias (name runtest) (action (diff expected/multiple-parameters.religo multiple-parameters.output))) +(alias (name runtest) (action (diff expected/multisig.religo multisig.output))) +(alias (name runtest) (action (diff expected/no_semicolon.religo no_semicolon.output))) +(alias (name runtest) (action (diff expected/pledge.religo pledge.output))) +(alias (name runtest) (action (diff expected/record.religo record.output))) +(alias (name runtest) (action (diff expected/recursion.religo recursion.output))) +(alias (name runtest) (action (diff expected/self_address.religo self_address.output))) +(alias (name runtest) (action (diff expected/set_arithmetic.religo set_arithmetic.output))) +(alias (name runtest) (action (diff expected/set_delegate.religo set_delegate.output))) +(alias (name runtest) (action (diff expected/single_record_item.religo single_record_item.output))) +(alias (name runtest) (action (diff expected/string_arithmetic.religo string_arithmetic.output))) +(alias (name runtest) (action (diff expected/super-counter.religo super-counter.output))) +(alias (name runtest) (action (diff expected/tuple_list.religo tuple_list.output))) +(alias (name runtest) (action (diff expected/tuple_param_destruct.religo tuple_param_destruct.output))) +(alias (name runtest) (action (diff expected/tuple_type.religo tuple_type.output))) +(alias (name runtest) (action (diff expected/tuple.religo tuple.output))) +(alias (name runtest) (action (diff expected/tuples_no_annotation.religo tuples_no_annotation.output))) +(alias (name runtest) (action (diff expected/tuples_sequences_functions.religo tuples_sequences_functions.output))) +(alias (name runtest) (action (diff expected/variant.religo variant.output))) +(alias (name runtest) (action (diff expected/website2.religo website2.output))) + +(alias (name runtest) (action (ignore-stdout (run ligo print-cst address.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst amount.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst arithmetic.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst bad_address_format.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst balance_constant.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst bitwise_arithmetic.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst boolean_operators.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst bytes_arithmetic.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst bytes_unpack.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst check_signature.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst closure.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst condition-shadowing.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst condition.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst counter.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst crypto.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst empty_case.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst eq_bool.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst failwith.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst function-shared.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst high-order.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst implicit_account.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst included.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst includer.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst key_hash.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst lambda.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst lambda2.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst let_multiple.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst letin.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst list.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst loop.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst map.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst match_bis.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst match.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst michelson_pair_tree.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst multiple-parameters.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst multisig.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst no_semicolon.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst pledge.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst record.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst recursion.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst self_address.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst set_arithmetic.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst set_delegate.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst single_record_item.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst string_arithmetic.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst super-counter.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst tuple_list.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst tuple_param_destruct.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst tuple_type.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst tuple.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst tuples_no_annotation.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst tuples_sequences_functions.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst variant.output -s reasonligo)))) +(alias (name runtest) (action (ignore-stdout (run ligo print-cst website2.output -s reasonligo)))) diff --git a/src/test/contracts/expected/address.religo b/src/test/contracts/expected/address.religo new file mode 100644 index 000000000..4979af040 --- /dev/null +++ b/src/test/contracts/expected/address.religo @@ -0,0 +1,6 @@ +let main = + (p: key_hash): address => + { + let c: contract(unit) = Tezos.implicit_account(p); + Tezos.address(c) + }; diff --git a/src/test/contracts/expected/amount.religo b/src/test/contracts/expected/amount.religo new file mode 100644 index 000000000..447dac88b --- /dev/null +++ b/src/test/contracts/expected/amount.religo @@ -0,0 +1,8 @@ +let check_ = + (p: unit): int => + if(Tezos.amount + == 100000000mutez) { + 42 + } else { + 0 + }; diff --git a/src/test/contracts/expected/arithmetic.religo b/src/test/contracts/expected/arithmetic.religo new file mode 100644 index 000000000..08c3fcfee --- /dev/null +++ b/src/test/contracts/expected/arithmetic.religo @@ -0,0 +1,17 @@ +let mod_op = (n: int): nat => n mod 42; + +let plus_op = (n: int): int => n + 42; + +let minus_op = (n: int): int => n - 42; + +let times_op = (n: int): int => n * 42; + +let div_op = (n: int): int => n / 2; + +let neg_op = (n: int): int => -n; + +let foo = (n: int): int => n + 10; + +let neg_op_2 = (b: int): int => -foo(b); + +let ediv_op = (n: int): option((int, nat)) => ediv(n 2); diff --git a/src/test/contracts/expected/bad_address_format.religo b/src/test/contracts/expected/bad_address_format.religo new file mode 100644 index 000000000..ee7f13c0d --- /dev/null +++ b/src/test/contracts/expected/bad_address_format.religo @@ -0,0 +1,3 @@ +let main = + (parameter: int, storage: address) => + ([] : list(operation), "KT1badaddr" : address); diff --git a/src/test/contracts/expected/balance_constant.religo b/src/test/contracts/expected/balance_constant.religo new file mode 100644 index 000000000..03de78dc7 --- /dev/null +++ b/src/test/contracts/expected/balance_constant.religo @@ -0,0 +1,7 @@ +type storage = tez; + +let main2 = + (p: unit, s: storage) => + ([] : list(operation), Tezos.balance); + +let main = (x: (unit, storage)) => main2(x[0] x[1]); diff --git a/src/test/contracts/expected/bitwise_arithmetic.religo b/src/test/contracts/expected/bitwise_arithmetic.religo new file mode 100644 index 000000000..8ea3f8d0b --- /dev/null +++ b/src/test/contracts/expected/bitwise_arithmetic.religo @@ -0,0 +1,9 @@ +let or_op = (n: nat): nat => Bitwise.or(n 4n); + +let and_op = (n: nat): nat => Bitwise.and(n 7n); + +let xor_op = (n: nat): nat => Bitwise.xor(n 7n); + +let lsl_op = (n: nat): nat => Bitwise.shift_left(n 7n); + +let lsr_op = (n: nat): nat => Bitwise.shift_right(n 7n); diff --git a/src/test/contracts/expected/boolean_operators.religo b/src/test/contracts/expected/boolean_operators.religo new file mode 100644 index 000000000..0c7f1ae28 --- /dev/null +++ b/src/test/contracts/expected/boolean_operators.religo @@ -0,0 +1,9 @@ +let or_true = (b: bool): bool => b || true; + +let or_false = (b: bool): bool => b || false; + +let and_true = (b: bool): bool => b && true; + +let and_false = (b: bool): bool => b && false; + +let not_bool = (b: bool): bool => ! b; diff --git a/src/test/contracts/expected/bytes_arithmetic.religo b/src/test/contracts/expected/bytes_arithmetic.religo new file mode 100644 index 000000000..372e268f1 --- /dev/null +++ b/src/test/contracts/expected/bytes_arithmetic.religo @@ -0,0 +1,5 @@ +let concat_op = (s: bytes): bytes => Bytes.concat(s 0x7070); + +let slice_op = (s: bytes): bytes => Bytes.slice(1n 2n s); + +let hasherman = (s: bytes): bytes => Crypto.sha256(s); diff --git a/src/test/contracts/expected/bytes_unpack.religo b/src/test/contracts/expected/bytes_unpack.religo new file mode 100644 index 000000000..ab91a5324 --- /dev/null +++ b/src/test/contracts/expected/bytes_unpack.religo @@ -0,0 +1,20 @@ +let id_string = + (p: string): option(string) => + { + let packed: bytes = Bytes.pack(p); + ((Bytes.unpack(packed)) : option(string)) + }; + +let id_int = + (p: int): option(int) => + { + let packed: bytes = Bytes.pack(p); + ((Bytes.unpack(packed)) : option(int)) + }; + +let id_address = + (p: address): option(address) => + { + let packed: bytes = Bytes.pack(p); + ((Bytes.unpack(packed)) : option(address)) + }; diff --git a/src/test/contracts/expected/check_signature.religo b/src/test/contracts/expected/check_signature.religo new file mode 100644 index 000000000..e4468ed5d --- /dev/null +++ b/src/test/contracts/expected/check_signature.religo @@ -0,0 +1,6 @@ +let check_signature = + (param: (key, signature, bytes)): bool => + { + let (pk, signed, msg) = param; + Crypto.check(pk signed msg) + }; diff --git a/src/test/contracts/expected/closure.religo b/src/test/contracts/expected/closure.religo new file mode 100644 index 000000000..229a89e98 --- /dev/null +++ b/src/test/contracts/expected/closure.religo @@ -0,0 +1,8 @@ +let test = + (k: int): int => + { + let j: int = k + 5; + let close: (int) => int) = (i: int) => i + j; + let j: int = 20; + close(20) + }; diff --git a/src/test/contracts/expected/condition-shadowing.religo b/src/test/contracts/expected/condition-shadowing.religo new file mode 100644 index 000000000..a31570a05 --- /dev/null +++ b/src/test/contracts/expected/condition-shadowing.religo @@ -0,0 +1,15 @@ +let main = + (i: int) => + { + let result = 0; + if(i + == 2) { + + let result = 42; + result + } else { + + let result = 0; + result + } + }; diff --git a/src/test/contracts/expected/condition.religo b/src/test/contracts/expected/condition.religo new file mode 100644 index 000000000..5fdc354e3 --- /dev/null +++ b/src/test/contracts/expected/condition.religo @@ -0,0 +1,8 @@ +let main = + (i: int) => + if(i + == 2) { + 42 + } else { + 0 + }; diff --git a/src/test/contracts/expected/counter.religo b/src/test/contracts/expected/counter.religo new file mode 100644 index 000000000..14af3847f --- /dev/null +++ b/src/test/contracts/expected/counter.religo @@ -0,0 +1,5 @@ +type storage = int; + +let main = + ((p, s): (int, storage)): (list(operation), storage) => + ([] : list(operation), p + s); diff --git a/src/test/contracts/expected/crypto.religo b/src/test/contracts/expected/crypto.religo new file mode 100644 index 000000000..4afc4a41c --- /dev/null +++ b/src/test/contracts/expected/crypto.religo @@ -0,0 +1,3 @@ +let hasherman512 = (s: bytes) => Crypto.sha512(s); + +let hasherman_blake = (s: bytes) => Crypto.blake2b(s); diff --git a/src/test/contracts/expected/empty_case.religo b/src/test/contracts/expected/empty_case.religo new file mode 100644 index 000000000..ebf6c24d6 --- /dev/null +++ b/src/test/contracts/expected/empty_case.religo @@ -0,0 +1,8 @@ +type foo = Bar(int) | Baz; + +let main = + (f: foo): int => + switch(f) { + | Bari => i + | Baz => (-1) + }; diff --git a/src/test/contracts/expected/eq_bool.religo b/src/test/contracts/expected/eq_bool.religo new file mode 100644 index 000000000..ec3bb0d3a --- /dev/null +++ b/src/test/contracts/expected/eq_bool.religo @@ -0,0 +1,8 @@ +let main = + ((a, b): (bool, bool)) => + if(a + == b) { + 999 + } else { + 1 + }; diff --git a/src/test/contracts/expected/failwith.religo b/src/test/contracts/expected/failwith.religo new file mode 100644 index 000000000..5e9680040 --- /dev/null +++ b/src/test/contracts/expected/failwith.religo @@ -0,0 +1,7 @@ +type storage = unit; + +let main = + (p: unit, storage) => + if(true) { + failwith("This contract always fails") + }; diff --git a/src/test/contracts/expected/function-shared.religo b/src/test/contracts/expected/function-shared.religo new file mode 100644 index 000000000..ab4fcc3b2 --- /dev/null +++ b/src/test/contracts/expected/function-shared.religo @@ -0,0 +1,5 @@ +let foo = (i: int): int => i + 20; + +let bar = (i: int): int => i + 50; + +let foobar = (i: int): int => foo(i) + bar(i); diff --git a/src/test/contracts/expected/high-order.religo b/src/test/contracts/expected/high-order.religo new file mode 100644 index 000000000..68fa5e33a --- /dev/null +++ b/src/test/contracts/expected/high-order.religo @@ -0,0 +1,53 @@ +let foobar = + (i: int): int => + { + let foo: int) => int = (i: int) => i; + let bar: (int) => int) => int) = + (f: int) => int) => f(i); + bar(foo) + }; + +let higher2 = + (i: int, f: int) => int): int => + { + let ii: int = f(i); + ii + }; + +let foobar2 = + (i: int): int => + { + let foo2: int) => int = (i: int) => i; + higher2(i foo2) + }; + +let a: int = 0; + +let foobar3 = + (i: int): int => + { + let foo2: int) => int = (i: int) => a + i; + higher2(i foo2) + }; + +let f = (i: int): int => i; + +let g = (i: int): int => f(i); + +let foobar4 = (i: int): int => g(g(i)); + +let higher3 = + (i: int, f: int) => int, g: int) => int): int => + { + let ii: int = f(g(i)); + ii + }; + +let foobar5 = + (i: int): int => + { + let a: int = 0; + let foo: int) => int = (i: int) => a + i; + let goo: int) => int = (i: int) => foo(i); + higher3(i foo goo) + }; diff --git a/src/test/contracts/expected/implicit_account.religo b/src/test/contracts/expected/implicit_account.religo new file mode 100644 index 000000000..8bfc216f8 --- /dev/null +++ b/src/test/contracts/expected/implicit_account.religo @@ -0,0 +1,3 @@ +let main = + (kh: key_hash): contract(unit) => + Tezos.implicit_account(kh); diff --git a/src/test/contracts/expected/included.religo b/src/test/contracts/expected/included.religo new file mode 100644 index 000000000..7ef8a7b77 --- /dev/null +++ b/src/test/contracts/expected/included.religo @@ -0,0 +1 @@ +let foo: int = 144; diff --git a/src/test/contracts/expected/includer.religo b/src/test/contracts/expected/includer.religo new file mode 100644 index 000000000..cd520f441 --- /dev/null +++ b/src/test/contracts/expected/includer.religo @@ -0,0 +1,3 @@ +let foo: int = 144; + +let bar: int = foo; diff --git a/src/test/contracts/expected/key_hash.religo b/src/test/contracts/expected/key_hash.religo new file mode 100644 index 000000000..bac557809 --- /dev/null +++ b/src/test/contracts/expected/key_hash.religo @@ -0,0 +1,8 @@ +let check_hash_key = + (kh1_k2: (key_hash, key)): (bool, key_hash) => + { + let (kh1, k2) = kh1_k2; + let kh2: key_hash = Crypto.hash_key(k2); + ((kh1 + == kh2), kh2) + }; diff --git a/src/test/contracts/expected/lambda.religo b/src/test/contracts/expected/lambda.religo new file mode 100644 index 000000000..dfa575e18 --- /dev/null +++ b/src/test/contracts/expected/lambda.religo @@ -0,0 +1,5 @@ +type storage = unit; + +let main = + ((p, s): (unit, storage)): unit => + ((useless: unit) => ())(()); diff --git a/src/test/contracts/expected/lambda2.religo b/src/test/contracts/expected/lambda2.religo new file mode 100644 index 000000000..9b0b129cf --- /dev/null +++ b/src/test/contracts/expected/lambda2.religo @@ -0,0 +1,5 @@ +type storage = unit; + +let main = + ((a, s): (unit, storage)): unit => + ((f: unit) => unit) => f(()))((useless: unit) => unit); diff --git a/src/test/contracts/expected/let_multiple.religo b/src/test/contracts/expected/let_multiple.religo new file mode 100644 index 000000000..449a434dc --- /dev/null +++ b/src/test/contracts/expected/let_multiple.religo @@ -0,0 +1,13 @@ +let (x: int, y: int) = (1, 2); + +let main = (p: unit): int => x + y; + +let (x: int, y: int) = (3, 3); + +let main_paren = (p: unit): int => x + y; + +let foobar: (int, int) = (23, 42); + +let (foo: int, bar: int) = foobar; + +let non_tuple_rhs = (p: unit): int => foo + bar; diff --git a/src/test/contracts/expected/letin.religo b/src/test/contracts/expected/letin.religo new file mode 100644 index 000000000..2e2c47239 --- /dev/null +++ b/src/test/contracts/expected/letin.religo @@ -0,0 +1,39 @@ +type storage = (int, int); + +let main = + (n: (int, storage)): (list(operation), storage) => + { + let x: (int, int) = + { + let x: int = 7; + (x + n[0], n[1.0] + n[1.1]) + }; + ([] : list(operation), x) + }; + +let f0 = (a: string) => true; + +let f1 = (a: string) => true; + +let f2 = (a: string) => true; + +let letin_nesting = + (_: unit) => + { + let s = "test"; + let p0 = f0(s); + assert(p0); + let p1 = f1(s); + assert(p1); + let p2 = f2(s); + assert(p2); + s + }; + +let letin_nesting2 = + (x: int) => + { + let y = 2; + let z = 3; + x + y + z + }; diff --git a/src/test/contracts/expected/list.religo b/src/test/contracts/expected/list.religo new file mode 100644 index 000000000..5985bf750 --- /dev/null +++ b/src/test/contracts/expected/list.religo @@ -0,0 +1,42 @@ +type storage = (int, list(int)); + +type parameter = list(int); + +type return = (list(operation), storage); + +let x: list(int) = []; + +let y: list(int) = [3, 4, 5]; + +let z: list(int) = [2, ...y]; + +let main = + ((action, s): (parameter, storage)): return => + { + let storage = + switch(action) { + | [] => s + | [hd, ...tl] => (s[0] + hd, tl) + }; + ([] : list(operation), storage) + }; + +let size_ = (s: list(int)): nat => List.length(s); + +let fold_op = + (s: list(int)): int => + { + let aggregate = (t: (int, int)) => t[0] + t[1]; + List.fold(aggregate s 10) + }; + +let map_op = + (s: list(int)): list(int) => + List.map((cur: int) => cur + 1 s); + +let iter_op = + (s: list(int)): unit => + { + let do_nothing = (useless: int) => unit; + List.iter(do_nothing s) + }; diff --git a/src/test/contracts/expected/loop.religo b/src/test/contracts/expected/loop.religo new file mode 100644 index 000000000..189373914 --- /dev/null +++ b/src/test/contracts/expected/loop.religo @@ -0,0 +1,51 @@ +let rec aux_simple = + (i: int): int => + if(i + < 100) { + aux_simple(i + 1) + } else { + i + }; + +let counter_simple = (n: int): int => aux_simple(n); + +type sum_aggregator = {counter: int, sum: int }; + +let counter = + (n: int): int => + { + let initial: sum_aggregator = {counter = 0, sum = 0 }; + let rec aggregate = + (prev: sum_aggregator): int => + if(prev[counter] + <= n) { + + + aggregate({ + counter = prev[counter] + 1, + sum = prev[counter] + prev[sum] + }) + } else { + prev[sum] + }; + aggregate(initial) + }; + +let rec aux_nest = + (prev: sum_aggregator): sum_aggregator => + if(prev[counter] + < 100) { + + let sum: int = prev[sum] + aux_simple(prev[counter]); + aux_nest({counter = prev[counter] + 1, sum = sum }) + } else { + ({counter = prev[counter], sum = prev[sum] }) + }; + +let counter_nest = + (n: int): int => + { + let initial: sum_aggregator = {counter = 0, sum = 0 }; + let out: sum_aggregator = aux_nest(initial); + out[sum] + }; diff --git a/src/test/contracts/expected/map.religo b/src/test/contracts/expected/map.religo new file mode 100644 index 000000000..8dd3a793a --- /dev/null +++ b/src/test/contracts/expected/map.religo @@ -0,0 +1,71 @@ +type foobar = map(int, int); + +let empty_map: foobar = Map.empty; + +let map1: foobar = + + Map.literal([(144, 23), + (51, 23), + (42, 23), + (120, 23), + (421, 23)]); + +let map2: foobar = Map.literal([(23, 0), (42, 0)]); + +let set_ = + (n: int, m: foobar): foobar => Map.update(23 Some (n) m); + +let add = (n: int, m: foobar): foobar => Map.add(23 n m); + +let rm = (m: foobar): foobar => Map.remove(42 m); + +let patch_ = + (m: foobar): foobar => + Map.literal([(0, 5), (1, 6), (2, 7)]); + +let patch_empty = + (m: foobar): foobar => + Map.literal([(0, 0), (1, 1), (2, 2)]); + +let patch_deep = + (m: (foobar, nat)): (foobar, nat) => + (Map.literal([(0, 0), (1, 9), (2, 2)]), 10n); + +let size_ = (m: foobar): nat => Map.size(m); + +let get = (m: foobar): option(int) => Map.find_opt(42 m); + +let get_ = (m: foobar): option(int) => Map.find_opt(42 m); + +let mem = (km: (int, foobar)): bool => Map.mem(km[0] km[1]); + +let iter_op = + (m: foobar): unit => + { + let assert_eq = (i: int, j: int) => assert(i == j); + Map.iter(assert_eq m) + }; + +let map_op = + (m: foobar): foobar => + { + let increment = (z: int, j: int) => j + 1; + Map.map(increment m) + }; + +let fold_op = + (m: foobar): foobar => + { + let aggregate = + (i: int, j: (int, int)) => i + j[0] + j[1]; + Map.fold(aggregate m 10) + }; + +let deep_op = + (m: foobar): foobar => + { + let coco = (0, m); + let coco = (0, Map.remove(42 coco[1])); + let coco = (0, Map.update(32 Some (16) coco[1])); + coco[1] + }; diff --git a/src/test/contracts/expected/match.religo b/src/test/contracts/expected/match.religo new file mode 100644 index 000000000..7dd01b0f5 --- /dev/null +++ b/src/test/contracts/expected/match.religo @@ -0,0 +1,17 @@ +type storage = int; + +type parameter = Add(int) | Sub(int); + +type return = (list(operation), storage); + +let main = + ((action, store): (parameter, storage)) => + { + let store = + store + + (switch(action) { + | Addn => n + | Subn => -n + }); + (([] : list(operation)), store) + }; diff --git a/src/test/contracts/expected/match_bis.religo b/src/test/contracts/expected/match_bis.religo new file mode 100644 index 000000000..59c76e0ec --- /dev/null +++ b/src/test/contracts/expected/match_bis.religo @@ -0,0 +1,18 @@ +type storage = int; + +type parameter = Increment(int) | Decrement(int); + +let add = (a: int, b: int) => a + b; + +let sub = (a: int, b: int) => a - b; + +let main = + ((action, store): (parameter, storage)) => + { + let store = + switch(action) { + | Incrementn => add(store n) + | Decrementn => sub(store n) + }; + (([] : list(operation)), store) + }; diff --git a/src/test/contracts/expected/michelson_pair_tree.religo b/src/test/contracts/expected/michelson_pair_tree.religo new file mode 100644 index 000000000..20e64dd2f --- /dev/null +++ b/src/test/contracts/expected/michelson_pair_tree.religo @@ -0,0 +1,13 @@ +type inner_storage = michelson_pair(int, "one", nat, "two"); + +type storage = michelson_pair + (int, "three", inner_storage, "four"); + +type return = (list(operation), storage); + +let main = + ((action, store): (unit, storage)): return => + { + let foo = (3, (1, 2n)); + (([] : list(operation)), (foo : storage)) + }; diff --git a/src/test/contracts/expected/multiple-parameters.religo b/src/test/contracts/expected/multiple-parameters.religo new file mode 100644 index 000000000..eac69a334 --- /dev/null +++ b/src/test/contracts/expected/multiple-parameters.religo @@ -0,0 +1,6 @@ +let abcde_curried = + (a: int, b: int, c: int, d: int, e: int): int => c + e + 3; + +let abcde = + (x: (int, int, int, int, int)): int => + abcde_curried(x[0] x[1] x[2] x[3] x[4]); diff --git a/src/test/contracts/expected/multisig.religo b/src/test/contracts/expected/multisig.religo new file mode 100644 index 000000000..1bb6ed29f --- /dev/null +++ b/src/test/contracts/expected/multisig.religo @@ -0,0 +1,97 @@ +type counter = nat; + +type threshold = nat; + +type authorized_keys = list(key); + +type id = string; + +type storage = { + id: id, + counter: counter, + threshold: threshold, + auth: authorized_keys +}; + +type message = unit) => list(operation); + +type dummy = (key_hash, signature); + +type signatures = list(dummy); + +type check_message_pt = { + counter: counter, + message: message, + signatures: signatures +}; + +type return = (list(operation), storage); + +type parameter = CheckMessage(check_message_pt); + +let check_message = + ((param, s): (check_message_pt, storage)): return => + { + let message: message = param[message]; + let s = + if(param[counter] + != s[counter]) { + (failwith("Counters does not match") : storage) + } else { + + let packed_payload: bytes = + + Bytes.pack((message, param[counter], s[id], + chain_id)); + let valid: nat = 0n; + let keys: authorized_keys = s[auth]; + let aux = + ((vk, pkh_sig): + ((nat, authorized_keys), (key_hash, signature))) + : + (nat, authorized_keys) => + { + let (valid, keys) = vk; + switch(keys) { + | [] => vk + | [key, ...keys] => + if(pkh_sig[0] + == Crypto.hash_key(key)) { + + let valid = + if( + Crypto.check(key + pkh_sig[1] + packed_payload)) { + valid + 1n + } else { + + (failwith("Invalid signature") + : nat) + }; + (valid, keys) + } else { + (valid, keys) + } + } + }; + let (valid, keys) = + List.fold(aux param[signatures] (valid, keys)); + if(valid + < s[threshold]) { + + ( + failwith("Not enough signatures passed the check") + : storage) + } else { + {...s, counter: s[counter] + 1n} + } + }; + (message(unit), s) + }; + +let main = + ((action, store): (parameter, storage)): return => + switch(action) { + | CheckMessagep => check_message((p, store)) + }; diff --git a/src/test/contracts/expected/no_semicolon.religo b/src/test/contracts/expected/no_semicolon.religo new file mode 100644 index 000000000..82db545df --- /dev/null +++ b/src/test/contracts/expected/no_semicolon.religo @@ -0,0 +1,18 @@ +type f = int; + +let a = + (b: f) => + { + if(b + == 2) { + 3 + } else { + 4 + } + }; + +let c = + (c: f) => + { + 3 + }; diff --git a/src/test/contracts/expected/pledge.religo b/src/test/contracts/expected/pledge.religo new file mode 100644 index 000000000..3d7fe2f46 --- /dev/null +++ b/src/test/contracts/expected/pledge.religo @@ -0,0 +1,35 @@ +type storage = address; + +type parameter = Donate(unit) +| Distribute((unit) => list(operation))); + +let donate = + ((p, s): (unit, storage)): (list(operation), storage) => + { + (([] : list(operation)), s) + }; + +let distribute = + ((p, s): (unit) => list(operation), storage)) + : + (list(operation), storage) => + { + if(Tezos.sender + == s) { + (p(()), s) + } else { + + ( + failwith("You're not the oracle for this distribution.") + : (list(operation), storage)) + } + }; + +let main = + ((p, s): (parameter, storage)): (list(operation), storage) => + { + switch(p) { + | Donate => donate(((), s)) + | Distributemsg => distribute((msg, s)) + } + }; diff --git a/src/test/contracts/expected/record.religo b/src/test/contracts/expected/record.religo new file mode 100644 index 000000000..8520955ee --- /dev/null +++ b/src/test/contracts/expected/record.religo @@ -0,0 +1,36 @@ +type foobar = {foo: int, bar: int }; + +let fb: foobar = {foo = 0, bar = 0 }; + +type abc = {a: int, b: int, c: int }; + +let abc: abc = {a = 42, b = 142, c = 242 }; + +let a: int = abc[a]; + +let b: int = abc[b]; + +let c: int = abc[c]; + +let projection = (r: foobar): int => r[foo] + r[bar]; + +let modify = + (r: foobar): foobar => {foo = 256, bar = r[bar] }; + +let modify_abc = (r: abc): abc => {...r, b: 2048, c: 42}; + +type big_record = {a: int, b: int, c: int, d: int, e: int }; + +let br: big_record = + { + a = 23, + b = 23, + c = 23, + d = 23, + e = 23 + }; + +type double_record = {inner: abc }; + +let modify_inner = + (r: double_record): double_record => {...r, inner.b: 2048}; diff --git a/src/test/contracts/expected/recursion.religo b/src/test/contracts/expected/recursion.religo new file mode 100644 index 000000000..5551c9a6c --- /dev/null +++ b/src/test/contracts/expected/recursion.religo @@ -0,0 +1,17 @@ +let rec sum = + ((n, acc): (int, int)): int => + if(n + < 1) { + acc + } else { + sum((n - 1, acc + n)) + }; + +let rec fibo = + ((n, n_1, n_0): (int, int, int)): int => + if(n + < 2) { + n_1 + } else { + fibo((n - 1, n_1 + n_0, n_1)) + }; diff --git a/src/test/contracts/expected/self_address.religo b/src/test/contracts/expected/self_address.religo new file mode 100644 index 000000000..db48e28df --- /dev/null +++ b/src/test/contracts/expected/self_address.religo @@ -0,0 +1 @@ +let main = (p: unit): address => Tezos.self_address; diff --git a/src/test/contracts/expected/set_arithmetic.religo b/src/test/contracts/expected/set_arithmetic.religo new file mode 100644 index 000000000..62cf2c971 --- /dev/null +++ b/src/test/contracts/expected/set_arithmetic.religo @@ -0,0 +1,17 @@ +let literal_op = + (p: unit): set(string) => + Set.literal(["foo", "bar", "foobar"]); + +let add_op = + (s: set(string)): set(string) => Set.add("foobar" s); + +let remove_op = + (s: set(string)): set(string) => Set.remove("foobar" s); + +let remove_deep = + (s: (set(string), nat)): set(string) => + Set.remove("foobar" s[0]); + +let mem_op = (s: set(string)): bool => Set.mem("foobar" s); + +let size_op = (s: set(string)): nat => Set.cardinal(s); diff --git a/src/test/contracts/expected/set_delegate.religo b/src/test/contracts/expected/set_delegate.religo new file mode 100644 index 000000000..278464cf6 --- /dev/null +++ b/src/test/contracts/expected/set_delegate.religo @@ -0,0 +1,6 @@ +let main = + (p: key_hash): list(operation) => + { + let unused: operation = (Tezos.set_delegate(Some (p))); + ([] : list(operation)) + }; diff --git a/src/test/contracts/expected/single_record_item.religo b/src/test/contracts/expected/single_record_item.religo new file mode 100644 index 000000000..d21e8d2a8 --- /dev/null +++ b/src/test/contracts/expected/single_record_item.religo @@ -0,0 +1,3 @@ +type p = {x: int }; + +let o = (p: int): p => {x = p }; diff --git a/src/test/contracts/expected/string_arithmetic.religo b/src/test/contracts/expected/string_arithmetic.religo new file mode 100644 index 000000000..741cf6c2f --- /dev/null +++ b/src/test/contracts/expected/string_arithmetic.religo @@ -0,0 +1,5 @@ +let size_op = (s: string): nat => String.length(s); + +let slice_op = (s: string): string => String.sub(1n 2n s); + +let concat_syntax = (s: string) => s ++ "test_literal"; diff --git a/src/test/contracts/expected/super-counter.religo b/src/test/contracts/expected/super-counter.religo new file mode 100644 index 000000000..de213ce92 --- /dev/null +++ b/src/test/contracts/expected/super-counter.religo @@ -0,0 +1,16 @@ +type parameter = Increment(int) | Decrement(int); + +type storage = int; + +type return = (list(operation), storage); + +let main = + ((action, store): (parameter, storage)): return => + { + let store = + switch(action) { + | Incrementn => store + n + | Decrementn => store - n + }; + ([] : list(operation), store) + }; diff --git a/src/test/contracts/expected/tuple.religo b/src/test/contracts/expected/tuple.religo new file mode 100644 index 000000000..d9c25255e --- /dev/null +++ b/src/test/contracts/expected/tuple.religo @@ -0,0 +1,13 @@ +type abc = (int, int, int); + +let projection_abc = (tpl: abc): int => tpl[1]; + +type foobar = (int, int); + +let fb: foobar = (0, 0); + +let projection = (tpl: foobar): int => tpl[0] + tpl[1]; + +type big_tuple = (int, int, int, int, int); + +let br: big_tuple = (23, 23, 23, 23, 23); diff --git a/src/test/contracts/expected/tuple_list.religo b/src/test/contracts/expected/tuple_list.religo new file mode 100644 index 000000000..534159047 --- /dev/null +++ b/src/test/contracts/expected/tuple_list.religo @@ -0,0 +1,3 @@ +type z = list((int, int)); + +let o: z = [(2, 4), (4, 6)]; diff --git a/src/test/contracts/expected/tuple_param_destruct.religo b/src/test/contracts/expected/tuple_param_destruct.religo new file mode 100644 index 000000000..e09319247 --- /dev/null +++ b/src/test/contracts/expected/tuple_param_destruct.religo @@ -0,0 +1,4 @@ +let sum = ((result, i): (int, int)): int => result - i; + +let parentheses = + ((result, i): (((int, int),),)): int => result - i; diff --git a/src/test/contracts/expected/tuple_type.religo b/src/test/contracts/expected/tuple_type.religo new file mode 100644 index 000000000..29d02a01e --- /dev/null +++ b/src/test/contracts/expected/tuple_type.religo @@ -0,0 +1,48 @@ +type fun_type = (int, int) => int; + +let arguments = + (b: int, c: int) => + { + b + c + }; + +let arguments_type_def = (b: fun_type) => b(5 3); + +let arguments_test = + (_: int) => arguments_type_def(arguments); + +type tuple_type = (int, int)) => int; + +let tuple = + ((a, b): (int, int)) => + { + a + b + }; + +let tuple_type_def = (b: tuple_type) => b((5, 3)); + +let tuple_test = (_: int) => tuple_type_def(tuple); + +let arguments_inline = + (b: int, c: int) => + { + b + c + }; + +let arguments_type_def_inline = + (b: (int, int) => int) => b(5 3); + +let arguments_test_inline = + (_: int) => arguments_type_def_inline(arguments_inline); + +let tuple_inline = + ((a, b): (int, int)) => + { + a + b + }; + +let tuple_type_def_inline = + (b: (int, int)) => int) => b((5, 3)); + +let tuple_test_inline = + (_: int) => tuple_type_def_inline(tuple_inline); diff --git a/src/test/contracts/expected/tuples_no_annotation.religo b/src/test/contracts/expected/tuples_no_annotation.religo new file mode 100644 index 000000000..7cd18c185 --- /dev/null +++ b/src/test/contracts/expected/tuples_no_annotation.religo @@ -0,0 +1,9 @@ +type storage = (int, string, nat, bool); + +type parameter = int; + +let main = + ((p, storage): (parameter, storage)) => + { + ([] : list(operation), (2, "2", 2n, false)) + }; diff --git a/src/test/contracts/expected/tuples_sequences_functions.religo b/src/test/contracts/expected/tuples_sequences_functions.religo new file mode 100644 index 000000000..edb34456b --- /dev/null +++ b/src/test/contracts/expected/tuples_sequences_functions.religo @@ -0,0 +1,65 @@ +let a = 1; + +let b = 1n; + +let c = 2mutez; + +let d = 1n + 2n; + +let e = 1mutez + 3mutez; + +let f = (a, c); + +let g = (a + 1, c); + +let h = ("a" ++ "2", d); + +let i = (a: int, b: int) => a + b; + +let j = (a: int, b: int) => a - b; + +let m = + { + let z = 3; + z + }; + +let n = (a: int): int => a + 1; + +let o = (a: int): int => a + 1; + +let n = (a: int, b: int): int => a + 1; + +let o = (a: int, b: int): int => a + 1; + +let p = + { + { + 3 + } + }; + +let q = + { + f = 3, + g = 6, + h = {i = "bla", j = 1 + 2, k = {l = 1, z = 2 } } + }; + +let s = + { + let a = 2; + { + z = a, + a = a + } + }; + +let t = (((((((2))))))); + +let u = + if(true) { + 1 + } else { + 2 + }; diff --git a/src/test/contracts/expected/variant.religo b/src/test/contracts/expected/variant.religo new file mode 100644 index 000000000..7846818c7 --- /dev/null +++ b/src/test/contracts/expected/variant.religo @@ -0,0 +1,7 @@ +type foobar = Foo(int) | Bar(bool) | Kee(nat); + +let foo: foobar = Foo (42); + +let bar: foobar = Bar (true); + +let kee: foobar = Kee (23n); diff --git a/src/test/contracts/expected/website2.religo b/src/test/contracts/expected/website2.religo new file mode 100644 index 000000000..852cf446b --- /dev/null +++ b/src/test/contracts/expected/website2.religo @@ -0,0 +1,18 @@ +type storage = int; + +type parameter = Increment(int) | Decrement(int); + +let add = ((a, b): (int, int)): int => a + b; + +let sub = ((a, b): (int, int)): int => a - b; + +let main = + ((p, storage): (parameter, storage)) => + { + let storage = + switch(p) { + | Incrementn => add((storage, n)) + | Decrementn => sub((storage, n)) + }; + ([] : list(operation), storage) + }; diff --git a/src/test/contracts/super-counter.religo b/src/test/contracts/super-counter.religo index 53eba61af..7245f15fc 100644 --- a/src/test/contracts/super-counter.religo +++ b/src/test/contracts/super-counter.religo @@ -6,7 +6,7 @@ type storage = int; type return = (list (operation), storage); -let main = ((action, store): (parameter, storage) : return => { +let main = ((action, store): (parameter, storage)) : return => { let store = switch (action) { | Increment (n) => store + n diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index bbe645b47..4ee2e841c 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -2492,6 +2492,7 @@ let main = test_suite "Integration (End to End)" [ test "counter contract" counter_contract ; test "super counter contract" super_counter_contract ; test "super counter contract" super_counter_contract_mligo ; + test "super counter contract (reasonligo)" super_counter_contract_religo ; test "dispatch counter contract" dispatch_counter_contract ; test "basic (mligo)" basic_mligo ; test "basic (religo)" basic_religo ;