diff --git a/src/bin/expect_tests/dune b/src/bin/expect_tests/dune index 65504a168..099f8a7b7 100644 --- a/src/bin/expect_tests/dune +++ b/src/bin/expect_tests/dune @@ -1,6 +1,6 @@ (library (name cli_expect_tests) (libraries simple-utils cli) - (inline_tests (deps (source_tree ../../test/contracts))) + (inline_tests (deps (source_tree ../../test/contracts) (source_tree ../../test/lexer))) (preprocess (pps ppx_let ppx_expect)) (flags (:standard -open Simple_utils))) diff --git a/src/bin/expect_tests/lexer_tests.ml b/src/bin/expect_tests/lexer_tests.ml new file mode 100644 index 000000000..06188eba2 --- /dev/null +++ b/src/bin/expect_tests/lexer_tests.ml @@ -0,0 +1,153 @@ +open Cli_expect + +let%expect_test _ = + run_ligo_bad [ "compile-contract" ; "../../test/lexer/broken_string.ligo" ; "main" ] ; + [%expect {| +ligo: lexer error: The string starting here is interrupted by a line break. + Hint: Remove the break, close the string before or insert a backslash. + {"parser_loc":"in file \"broken_string.ligo\", line 1, characters 18-19"} + |} ]; + + run_ligo_bad [ "compile-contract" ; "../../test/lexer/broken_string.mligo" ; "main" ] ; + [%expect {| +ligo: lexer error: The string starting here is interrupted by a line break. + Hint: Remove the break, close the string before or insert a backslash. + {"parser_loc":"in file \"broken_string.mligo\", line 1, characters 8-9"} + |} ]; + + run_ligo_bad [ "compile-contract" ; "../../test/lexer/broken_string.religo" ; "main" ] ; + [%expect {| +ligo: lexer error: The string starting here is interrupted by a line break. + Hint: Remove the break, close the string before or insert a backslash. + {"parser_loc":"in file \"broken_string.religo\", line 1, characters 8-9"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/negative_byte_sequence.ligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Negative byte sequence. + Hint: Remove the leading minus sign. + {"parser_loc":"in file \"negative_byte_sequence.ligo\", line 1, characters 18-23"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/negative_byte_sequence.mligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Negative byte sequence. + Hint: Remove the leading minus sign. + {"parser_loc":"in file \"negative_byte_sequence.mligo\", line 1, characters 8-13"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/negative_byte_sequence.religo" ; "main" ] ; + [%expect {| +ligo: lexer error: Negative byte sequence. + Hint: Remove the leading minus sign. + {"parser_loc":"in file \"negative_byte_sequence.religo\", line 1, characters 8-13"} + |} ]; + + run_ligo_bad [ "compile-contract" ; "../../test/lexer/reserved_name.ligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Reserved name: args. + Hint: Change the name. + {"parser_loc":"in file \"reserved_name.ligo\", line 1, characters 4-8"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/reserved_name.religo" ; "main" ] ; + [%expect {| +ligo: lexer error: Reserved name: end. + Hint: Change the name. + {"parser_loc":"in file \"reserved_name.religo\", line 1, characters 4-7"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/reserved_name.mligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Reserved name: object. + Hint: Change the name. + {"parser_loc":"in file \"reserved_name.mligo\", line 1, characters 4-10"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/unexpected_character.ligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Unexpected character '\239'. + {"parser_loc":"in file \"unexpected_character.ligo\", line 1, characters 18-19"} + |} ]; + + run_ligo_bad [ "compile-contract" ; "../../test/lexer/unexpected_character.mligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Unexpected character '\239'. + {"parser_loc":"in file \"unexpected_character.mligo\", line 1, characters 8-9"} + |} ]; + + run_ligo_bad [ "compile-contract" ; "../../test/lexer/unexpected_character.religo" ; "main" ] ; + [%expect {| +ligo: lexer error: Unexpected character '\239'. + {"parser_loc":"in file \"unexpected_character.religo\", line 1, characters 8-9"} + |} ]; + + run_ligo_bad [ "compile-contract" ; "../../test/lexer/unterminated_comment.mligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Unterminated comment. + Hint: Close with "*)". + {"parser_loc":"in file \"unterminated_comment.mligo\", line 1, characters 0-2"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_symbol.ligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Invalid symbol. + Hint: Check the LIGO syntax you use. + {"parser_loc":"in file \"invalid_symbol.ligo\", line 1, characters 17-20"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_symbol.mligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Invalid symbol. + Hint: Check the LIGO syntax you use. + {"parser_loc":"in file \"invalid_symbol.mligo\", line 1, characters 10-13"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_symbol.religo" ; "main" ] ; + [%expect {| +ligo: lexer error: Invalid symbol. + Hint: Check the LIGO syntax you use. + {"parser_loc":"in file \"invalid_symbol.religo\", line 1, characters 10-11"} + |} ]; + + run_ligo_bad [ "compile-contract" ; "../../test/lexer/missing_break.ligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Missing break. + Hint: Insert some space. + {"parser_loc":"in file \"missing_break.ligo\", line 1, characters 18-18"} + |} ]; + + run_ligo_bad [ "compile-contract" ; "../../test/lexer/missing_break.mligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Missing break. + Hint: Insert some space. + {"parser_loc":"in file \"missing_break.mligo\", line 1, characters 11-11"} + |} ]; + + run_ligo_bad [ "compile-contract" ; "../../test/lexer/missing_break.religo" ; "main" ] ; + [%expect {| +ligo: lexer error: Missing break. + Hint: Insert some space. + {"parser_loc":"in file \"missing_break.religo\", line 1, characters 11-11"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_character_in_string.ligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Invalid character in string. + Hint: Remove or replace the character. + {"parser_loc":"in file \"invalid_character_in_string.ligo\", line 1, characters 19-20"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_character_in_string.mligo" ; "main" ] ; + [%expect {| +ligo: lexer error: Invalid character in string. + Hint: Remove or replace the character. + {"parser_loc":"in file \"invalid_character_in_string.mligo\", line 1, characters 9-10"} + |} ]; + +run_ligo_bad [ "compile-contract" ; "../../test/lexer/invalid_character_in_string.religo" ; "main" ] ; + [%expect {| +ligo: lexer error: Invalid character in string. + Hint: Remove or replace the character. + {"parser_loc":"in file \"invalid_character_in_string.religo\", line 1, characters 9-10"} + |} ] \ No newline at end of file diff --git a/src/test/lexer/broken_string.ligo b/src/test/lexer/broken_string.ligo new file mode 100644 index 000000000..870fe9481 --- /dev/null +++ b/src/test/lexer/broken_string.ligo @@ -0,0 +1,4 @@ +const a: string = "broken +over +multiple +lines"; \ No newline at end of file diff --git a/src/test/lexer/broken_string.mligo b/src/test/lexer/broken_string.mligo new file mode 100644 index 000000000..0e9b58689 --- /dev/null +++ b/src/test/lexer/broken_string.mligo @@ -0,0 +1,4 @@ +let a = "broken +over +multiple +lines"; \ No newline at end of file diff --git a/src/test/lexer/broken_string.religo b/src/test/lexer/broken_string.religo new file mode 100644 index 000000000..0e9b58689 --- /dev/null +++ b/src/test/lexer/broken_string.religo @@ -0,0 +1,4 @@ +let a = "broken +over +multiple +lines"; \ No newline at end of file diff --git a/src/test/lexer/invalid_character_in_string.ligo b/src/test/lexer/invalid_character_in_string.ligo new file mode 100644 index 000000000..48f7167d1 --- /dev/null +++ b/src/test/lexer/invalid_character_in_string.ligo @@ -0,0 +1 @@ +const z: string = " "; \ No newline at end of file diff --git a/src/test/lexer/invalid_character_in_string.mligo b/src/test/lexer/invalid_character_in_string.mligo new file mode 100644 index 000000000..f80aa6504 --- /dev/null +++ b/src/test/lexer/invalid_character_in_string.mligo @@ -0,0 +1 @@ +let z = " "; \ No newline at end of file diff --git a/src/test/lexer/invalid_character_in_string.religo b/src/test/lexer/invalid_character_in_string.religo new file mode 100644 index 000000000..f80aa6504 --- /dev/null +++ b/src/test/lexer/invalid_character_in_string.religo @@ -0,0 +1 @@ +let z = " "; \ No newline at end of file diff --git a/src/test/lexer/invalid_symbol.ligo b/src/test/lexer/invalid_symbol.ligo new file mode 100644 index 000000000..77f5d0984 --- /dev/null +++ b/src/test/lexer/invalid_symbol.ligo @@ -0,0 +1 @@ +const b: int = 1 ... 10; \ No newline at end of file diff --git a/src/test/lexer/invalid_symbol.mligo b/src/test/lexer/invalid_symbol.mligo new file mode 100644 index 000000000..91a1290ea --- /dev/null +++ b/src/test/lexer/invalid_symbol.mligo @@ -0,0 +1 @@ +let b = 1 ... 10; \ No newline at end of file diff --git a/src/test/lexer/invalid_symbol.religo b/src/test/lexer/invalid_symbol.religo new file mode 100644 index 000000000..246855122 --- /dev/null +++ b/src/test/lexer/invalid_symbol.religo @@ -0,0 +1 @@ +let b = 1 # 10; \ No newline at end of file diff --git a/src/test/lexer/missing_break.ligo b/src/test/lexer/missing_break.ligo new file mode 100644 index 000000000..48d580b70 --- /dev/null +++ b/src/test/lexer/missing_break.ligo @@ -0,0 +1 @@ +const a: int = 300zennies; \ No newline at end of file diff --git a/src/test/lexer/missing_break.mligo b/src/test/lexer/missing_break.mligo new file mode 100644 index 000000000..6a2b62143 --- /dev/null +++ b/src/test/lexer/missing_break.mligo @@ -0,0 +1 @@ +let a = 300zennies; \ No newline at end of file diff --git a/src/test/lexer/missing_break.religo b/src/test/lexer/missing_break.religo new file mode 100644 index 000000000..6a2b62143 --- /dev/null +++ b/src/test/lexer/missing_break.religo @@ -0,0 +1 @@ +let a = 300zennies; \ No newline at end of file diff --git a/src/test/lexer/negative_byte_sequence.ligo b/src/test/lexer/negative_byte_sequence.ligo new file mode 100644 index 000000000..b70da4d24 --- /dev/null +++ b/src/test/lexer/negative_byte_sequence.ligo @@ -0,0 +1 @@ +const a: string = -0x222; \ No newline at end of file diff --git a/src/test/lexer/negative_byte_sequence.mligo b/src/test/lexer/negative_byte_sequence.mligo new file mode 100644 index 000000000..2494567f4 --- /dev/null +++ b/src/test/lexer/negative_byte_sequence.mligo @@ -0,0 +1 @@ +let a = -0x222; \ No newline at end of file diff --git a/src/test/lexer/negative_byte_sequence.religo b/src/test/lexer/negative_byte_sequence.religo new file mode 100644 index 000000000..2494567f4 --- /dev/null +++ b/src/test/lexer/negative_byte_sequence.religo @@ -0,0 +1 @@ +let a = -0x222; \ No newline at end of file diff --git a/src/test/lexer/reserved_name.ligo b/src/test/lexer/reserved_name.ligo new file mode 100644 index 000000000..dfa90cb08 --- /dev/null +++ b/src/test/lexer/reserved_name.ligo @@ -0,0 +1 @@ +let args = 1; \ No newline at end of file diff --git a/src/test/lexer/reserved_name.mligo b/src/test/lexer/reserved_name.mligo new file mode 100644 index 000000000..c053ff506 --- /dev/null +++ b/src/test/lexer/reserved_name.mligo @@ -0,0 +1 @@ +let object = 1; \ No newline at end of file diff --git a/src/test/lexer/reserved_name.religo b/src/test/lexer/reserved_name.religo new file mode 100644 index 000000000..8803e9edf --- /dev/null +++ b/src/test/lexer/reserved_name.religo @@ -0,0 +1 @@ +let end = 1; \ No newline at end of file diff --git a/src/test/lexer/unexpected_character.ligo b/src/test/lexer/unexpected_character.ligo new file mode 100644 index 000000000..ac31cca58 --- /dev/null +++ b/src/test/lexer/unexpected_character.ligo @@ -0,0 +1 @@ +const x: string = ���; \ No newline at end of file diff --git a/src/test/lexer/unexpected_character.mligo b/src/test/lexer/unexpected_character.mligo new file mode 100644 index 000000000..2568a40b6 --- /dev/null +++ b/src/test/lexer/unexpected_character.mligo @@ -0,0 +1 @@ +let x = ���; \ No newline at end of file diff --git a/src/test/lexer/unexpected_character.religo b/src/test/lexer/unexpected_character.religo new file mode 100644 index 000000000..2568a40b6 --- /dev/null +++ b/src/test/lexer/unexpected_character.religo @@ -0,0 +1 @@ +let x = ���; \ No newline at end of file diff --git a/src/test/lexer/unterminated_comment.mligo b/src/test/lexer/unterminated_comment.mligo new file mode 100644 index 000000000..9f845562c --- /dev/null +++ b/src/test/lexer/unterminated_comment.mligo @@ -0,0 +1 @@ +(* not closed \ No newline at end of file