Skip to content

Commit

Permalink
test(core): properly test unused variable
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs committed Aug 8, 2024
1 parent fd5ad57 commit ae55fe2
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
91 changes: 91 additions & 0 deletions crates/cairo-lint-core/tests/test_files/unused_variables
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,97 @@ fn main() {

//! > ==========================================================================

//! > plenty unused variables

//! > cairo_code
fn main() {
let used: Option<felt252> = 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<felt252> = 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
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lint-core/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ae55fe2

Please sign in to comment.