forked from software-mansion/cairo-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.rs
155 lines (141 loc) · 4.89 KB
/
tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use std::collections::HashMap;
use std::path::Path;
use std::sync::{LazyLock, Mutex};
use annotate_snippets::Renderer;
use cairo_lang_compiler::db::RootDatabase;
use cairo_lang_filesystem::ids::FileId;
use cairo_lang_semantic::diagnostic::SemanticDiagnosticKind;
use cairo_lang_semantic::inline_macros::get_default_plugin_suite;
use cairo_lang_semantic::test_utils::setup_test_crate_ex;
use cairo_lang_syntax::node::SyntaxNode;
use cairo_lang_test_plugin::test_plugin_suite;
use cairo_lang_test_utils::parse_test_file::{dump_to_test_file, parse_test_file, Test};
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use cairo_lang_utils::Upcast;
use cairo_lint_core::diagnostics::format_diagnostic;
use cairo_lint_core::fix::{apply_import_fixes, collect_unused_imports, fix_semantic_diagnostic, Fix, ImportFix};
use cairo_lint_core::plugin::cairo_lint_plugin_suite;
use cairo_lint_test_utils::{get_diags, test_file, Tests};
use ctor::dtor;
use itertools::Itertools;
use paste::paste;
use pretty_assertions::assert_eq;
use test_case::test_case;
const CRATE_CONFIG: &str = r#"
edition = "2024_07"
[experimental_features]
negative_impls = true
coupons = true
"#;
test_file!(unused_variables, unused_variables, "one unused variable", "two unused variable", "plenty unused variables");
test_file!(
single_match,
destructuring_match,
"simple destructuring match",
"simple destructuring match second arm",
"simple destructuring match with scope",
"simple destructuring match with unit in scope",
"nested destructuring match",
"destructuring match twisted",
"destructuring match twisted differently",
"destructuring match second arm",
"destructuring comprehensive match",
"reversed destructuring comprehensive match",
"simple destructuring match with unit and comment in scope",
"simple destructuring match with comment in scope",
"comprehensive match"
);
test_file!(
unused_imports,
unused_imports,
"single unused import",
"multiple unused imports",
"unused import aliased",
"unused import trait",
"multi with one used and one unused",
"mix of multi and leaf imports in a single statement",
"multiple import statements lines with some used and some unused"
);
test_file!(
double_parens,
double_parens,
"simple double parens",
"unnecessary parentheses in arithmetic expression",
"necessary parentheses in arithmetic expression",
"tuple double parens",
"assert expressions",
"double parens with function call",
"double parens with return",
"double parens in let statement",
"double parens in struct field access",
"double parens in match arm"
);
test_file!(
double_comparison,
double_comparison,
"double comparison equal or greater than",
"double comparison equal or less than",
"double comparison greater than or equal",
"double comparison greater than or less than",
"double comparison greater than or equal and less than or equal",
"double comparison less than or equal",
"double comparison less than or greater than",
"double comparison less than or equal and greater than or equal",
"not redundant double comparison equal or greater than",
"contradictory less than and greater than",
"contradictory equal and less than",
"redundant greater than or equal and less than or equal"
);
test_file!(
loops,
loop_match_pop_front,
"simple loop match pop front",
"simple loop match pop front with let",
"simple loop match pop front impl path",
"simple loop match pop front multiple dots",
"loop match pop front with comment in some",
"loop match pop front with comment in none",
"loop match pop front with sutff in none"
);
test_file!(breaks, breaks, "Simple break", "Break inside of if", "Break inside of if with comment");
test_file!(
ifs,
equatable_if_let,
"simple equality cases ok",
"complex equality destructuring if let",
"Simple Value Pattern Matching",
"Enum Unit Variant Pattern Matching",
"Complex Equality Destructuring",
"Matching With Simple Structs field"
);
test_file!(
bool_comparison,
bool_comparison,
"Comparison with true",
"Comparison with true on LHS",
"Comparison with false",
"Comparison with false on LHS",
"Negated comparison with true",
"Negated comparison with true on LHS",
"Negated comparison with false",
"Negated comparison with false on LHS"
);
test_file!(
duplicate_underscore_args,
duplicate_underscore_args,
"duplicate underscore args",
"duplicate underscore args2",
"duplicate underscore longer args",
"duplicate underscore longer args2",
"duplicate underscore longer args3",
"duplicate underscore longer args4"
);
test_file!(
ifs,
collapsible_if_else,
"Simple else if with new line",
"Simple else if without new line",
"Multiple else if",
"Else if with multiple statements",
"Else if inside loop"
);