From 2ee748b7f57bcd5696e8b778329a987d41020135 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 6 Feb 2020 19:44:14 +0100 Subject: [PATCH] Add tests --- test/libyul/yulSyntaxTests/assignment_fail.yul | 12 ++++++++++++ test/libyul/yulSyntaxTests/for_loop_condition.yul | 7 +++++++ .../yulSyntaxTests/for_loop_condition_fail.yul | 8 ++++++++ .../yulSyntaxTests/for_loop_condition_fail_ewasm.yul | 8 ++++++++ test/libyul/yulSyntaxTests/type_check_cases.yul | 8 ++++++++ test/libyul/yulSyntaxTests/type_check_cases_fail.yul | 10 ++++++++++ .../type_check_cases_fail_evmtyped.yul | 10 ++++++++++ .../yulSyntaxTests/type_check_if_condition.yul | 7 +++++++ .../yulSyntaxTests/type_check_if_condition_fail.yul | 8 ++++++++ .../yulSyntaxTests/user_defined_functions_fail.yul | 12 ++++++++++++ .../yulSyntaxTests/user_defined_functions_fine.yul | 10 ++++++++++ 11 files changed, 100 insertions(+) create mode 100644 test/libyul/yulSyntaxTests/assignment_fail.yul create mode 100644 test/libyul/yulSyntaxTests/for_loop_condition.yul create mode 100644 test/libyul/yulSyntaxTests/for_loop_condition_fail.yul create mode 100644 test/libyul/yulSyntaxTests/for_loop_condition_fail_ewasm.yul create mode 100644 test/libyul/yulSyntaxTests/type_check_cases.yul create mode 100644 test/libyul/yulSyntaxTests/type_check_cases_fail.yul create mode 100644 test/libyul/yulSyntaxTests/type_check_cases_fail_evmtyped.yul create mode 100644 test/libyul/yulSyntaxTests/type_check_if_condition.yul create mode 100644 test/libyul/yulSyntaxTests/type_check_if_condition_fail.yul create mode 100644 test/libyul/yulSyntaxTests/user_defined_functions_fail.yul create mode 100644 test/libyul/yulSyntaxTests/user_defined_functions_fine.yul diff --git a/test/libyul/yulSyntaxTests/assignment_fail.yul b/test/libyul/yulSyntaxTests/assignment_fail.yul new file mode 100644 index 000000000..59c18bfd3 --- /dev/null +++ b/test/libyul/yulSyntaxTests/assignment_fail.yul @@ -0,0 +1,12 @@ +{ + let x:u256 + let y := x + let z:bool + z := y + y := z +} +// ==== +// dialect: evmTyped +// ---- +// TypeError: (51-52): Assigning a value of type "u256" to a variable of type "bool". +// TypeError: (62-63): Assigning a value of type "bool" to a variable of type "u256". diff --git a/test/libyul/yulSyntaxTests/for_loop_condition.yul b/test/libyul/yulSyntaxTests/for_loop_condition.yul new file mode 100644 index 000000000..72ed7b71f --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_loop_condition.yul @@ -0,0 +1,7 @@ +{ + let x:bool + for {} x {} {} +} +// ==== +// dialect: evmTyped +// ---- diff --git a/test/libyul/yulSyntaxTests/for_loop_condition_fail.yul b/test/libyul/yulSyntaxTests/for_loop_condition_fail.yul new file mode 100644 index 000000000..903f5471a --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_loop_condition_fail.yul @@ -0,0 +1,8 @@ +{ + let x + for {} x {} {} +} +// ==== +// dialect: evmTyped +// ---- +// TypeError: (23-24): Expected a value of boolean type "bool" but got "u256" diff --git a/test/libyul/yulSyntaxTests/for_loop_condition_fail_ewasm.yul b/test/libyul/yulSyntaxTests/for_loop_condition_fail_ewasm.yul new file mode 100644 index 000000000..cbe266f9f --- /dev/null +++ b/test/libyul/yulSyntaxTests/for_loop_condition_fail_ewasm.yul @@ -0,0 +1,8 @@ +{ + let x + for {} x {} {} +} +// ==== +// dialect: ewasm +// ---- +// TypeError: (23-24): Expected a value of boolean type "i32" but got "i64" diff --git a/test/libyul/yulSyntaxTests/type_check_cases.yul b/test/libyul/yulSyntaxTests/type_check_cases.yul new file mode 100644 index 000000000..4e09457c8 --- /dev/null +++ b/test/libyul/yulSyntaxTests/type_check_cases.yul @@ -0,0 +1,8 @@ +{ + switch 7:i64 + case 0:i64 {} + case 2:i64 {} +} +// ==== +// dialect: ewasm +// ---- diff --git a/test/libyul/yulSyntaxTests/type_check_cases_fail.yul b/test/libyul/yulSyntaxTests/type_check_cases_fail.yul new file mode 100644 index 000000000..c799bec4b --- /dev/null +++ b/test/libyul/yulSyntaxTests/type_check_cases_fail.yul @@ -0,0 +1,10 @@ +{ + switch 7:i32 + case 0:i64 {} + case 2:i64 {} +} +// ==== +// dialect: ewasm +// ---- +// TypeError: (28-33): Expected a value of type "i32" but got "i64" +// TypeError: (46-51): Expected a value of type "i32" but got "i64" diff --git a/test/libyul/yulSyntaxTests/type_check_cases_fail_evmtyped.yul b/test/libyul/yulSyntaxTests/type_check_cases_fail_evmtyped.yul new file mode 100644 index 000000000..c1db211f0 --- /dev/null +++ b/test/libyul/yulSyntaxTests/type_check_cases_fail_evmtyped.yul @@ -0,0 +1,10 @@ +{ + switch 7 + case true:bool {} + case true:bool {} +} +// ==== +// dialect: evmTyped +// ---- +// TypeError: (24-33): Expected a value of type "u256" but got "bool" +// TypeError: (46-55): Expected a value of type "u256" but got "bool" diff --git a/test/libyul/yulSyntaxTests/type_check_if_condition.yul b/test/libyul/yulSyntaxTests/type_check_if_condition.yul new file mode 100644 index 000000000..eaccf63f6 --- /dev/null +++ b/test/libyul/yulSyntaxTests/type_check_if_condition.yul @@ -0,0 +1,7 @@ +{ + let x:i32 + if x {} +} +// ==== +// dialect: ewasm +// ---- diff --git a/test/libyul/yulSyntaxTests/type_check_if_condition_fail.yul b/test/libyul/yulSyntaxTests/type_check_if_condition_fail.yul new file mode 100644 index 000000000..a79d50e34 --- /dev/null +++ b/test/libyul/yulSyntaxTests/type_check_if_condition_fail.yul @@ -0,0 +1,8 @@ +{ + let x:i64 + if x {} +} +// ==== +// dialect: ewasm +// ---- +// TypeError: (23-24): Expected a value of boolean type "i32" but got "i64" diff --git a/test/libyul/yulSyntaxTests/user_defined_functions_fail.yul b/test/libyul/yulSyntaxTests/user_defined_functions_fail.yul new file mode 100644 index 000000000..324f937d4 --- /dev/null +++ b/test/libyul/yulSyntaxTests/user_defined_functions_fail.yul @@ -0,0 +1,12 @@ +{ + function f(a:u256, b:u256, c:bool) -> r:bool, t { + r := lt(a, b) + t := bool_to_u256(not(c)) + } + let x, y: bool := f(1, 2: u256, true) +} +// ==== +// dialect: evmTyped +// ---- +// TypeError: (126-127): Assigning value of type "bool" to variable of type "u256. +// TypeError: (129-136): Assigning value of type "u256" to variable of type "bool. diff --git a/test/libyul/yulSyntaxTests/user_defined_functions_fine.yul b/test/libyul/yulSyntaxTests/user_defined_functions_fine.yul new file mode 100644 index 000000000..e24ea923e --- /dev/null +++ b/test/libyul/yulSyntaxTests/user_defined_functions_fine.yul @@ -0,0 +1,10 @@ +{ + function f(a:u256, b:u256, c:bool) -> r:bool, t { + r := lt(a, b) + t := bool_to_u256(not(c)) + } + let x: bool, y: u256 := f(1, 2: u256, true) +} +// ==== +// dialect: evmTyped +// ----