From ae55fe29eb85c44372ca845bce6dd91d7b77a084 Mon Sep 17 00:00:00 2001 From: LucasLvy Date: Thu, 8 Aug 2024 16:18:25 +0200 Subject: [PATCH] test(core): properly test unused variable --- .../tests/test_files/unused_variables | 91 +++++++++++++++++++ crates/cairo-lint-core/tests/tests.rs | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/crates/cairo-lint-core/tests/test_files/unused_variables b/crates/cairo-lint-core/tests/test_files/unused_variables index bd801c6c..3ca6199c 100644 --- a/crates/cairo-lint-core/tests/test_files/unused_variables +++ b/crates/cairo-lint-core/tests/test_files/unused_variables @@ -18,6 +18,97 @@ fn main() { //! > ========================================================================== +//! > plenty unused variables + +//! > cairo_code +fn main() { + let used: Option = Option::Some(1); + let b = 1; + { + let c = 1_u32; + } + if true { + if false { + let d = 3_u32; + } else { + let e = false; + } + let f = array![]; + } else { + let g = Option::None; + match used { + Option::Some(not_used) => 1_u32, + Option::None => 2_u32, + }; + } +} + +//! > diagnostics +warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + --> lib.cairo:5:13 + let c = 1_u32; + ^ + +warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + --> lib.cairo:9:17 + let d = 3_u32; + ^ + +warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + --> lib.cairo:11:17 + let e = false; + ^ + +warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + --> lib.cairo:13:13 + let f = array![]; + ^ + +warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + --> lib.cairo:17:26 + Option::Some(not_used) => 1_u32, + ^******^ + +warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + --> lib.cairo:15:13 + let g = Option::None; + ^ + +warning[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + --> lib.cairo:3:9 + let b = 1; + ^ + +error: Type annotations needed. Failed to infer ?3. + --> lib.cairo:13:17 + let f = array![]; + ^******^ + +//! > fixed +fn main() { + let used: Option = Option::Some(1); + let _b = 1; + { + let _c = 1_u32; + } + if true { + if false { + let _d = 3_u32; + } else { + let _e = false; + } + let _f = array![]; + } else { + let _g = Option::None; + match used { + Option::Some(_not_used) => 1_u32, + Option::None => 2_u32, + }; + } +} + +//! > ========================================================================== + //! > two unused variable //! > cairo_code diff --git a/crates/cairo-lint-core/tests/tests.rs b/crates/cairo-lint-core/tests/tests.rs index 90cc0fe3..68c8548a 100644 --- a/crates/cairo-lint-core/tests/tests.rs +++ b/crates/cairo-lint-core/tests/tests.rs @@ -15,7 +15,7 @@ use paste::paste; use pretty_assertions::assert_eq; use test_case::test_case; -test_file!(unused_variables, "one unused variable", "two unused variable"); +test_file!(unused_variables, "one unused variable", "two unused variable", "plenty unused variables"); test_file!( destruct_if_let,