Skip to content

Commit a6d6e91

Browse files
committed
Add tests for Odin
1 parent 0adf50f commit a6d6e91

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed

crates/codebook/tests/test_odin.rs

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
use codebook::{
2+
parser::{TextRange, WordLocation},
3+
queries::LanguageType,
4+
};
5+
6+
mod utils;
7+
8+
#[test]
9+
fn test_odin_location() {
10+
utils::init_logging();
11+
let sample_text = include_str!("./examples/example.odin");
12+
let expected = vec![
13+
// Comments
14+
WordLocation::new(
15+
"Commennt".to_string(),
16+
vec![TextRange { start_byte: 196, end_byte: 204 }],
17+
),
18+
WordLocation::new(
19+
"cooment".to_string(),
20+
vec![TextRange { start_byte: 215, end_byte: 222 }],
21+
),
22+
WordLocation::new(
23+
"Netsed".to_string(),
24+
vec![TextRange { start_byte: 229, end_byte: 235 }],
25+
),
26+
// Procedure declarations
27+
WordLocation::new(
28+
"proecdure".to_string(),
29+
vec![TextRange { start_byte: 253, end_byte: 262 }],
30+
),
31+
WordLocation::new(
32+
"porocedure".to_string(),
33+
vec![TextRange { start_byte: 379, end_byte: 389 }],
34+
),
35+
WordLocation::new(
36+
"overloded".to_string(),
37+
vec![TextRange { start_byte: 498, end_byte: 507 }],
38+
),
39+
WordLocation::new(
40+
"deafult".to_string(),
41+
vec![TextRange { start_byte: 565, end_byte: 572 }],
42+
),
43+
WordLocation::new(
44+
"varidic".to_string(),
45+
vec![TextRange { start_byte: 635, end_byte: 642 }],
46+
),
47+
// Parameters
48+
WordLocation::new(
49+
"prameter".to_string(),
50+
vec![
51+
TextRange { start_byte: 274, end_byte: 282 },
52+
TextRange { start_byte: 401, end_byte: 409 },
53+
TextRange { start_byte: 584, end_byte: 592 },
54+
],
55+
),
56+
WordLocation::new(
57+
"paramter".to_string(),
58+
vec![
59+
TextRange { start_byte: 297, end_byte: 305 },
60+
TextRange { start_byte: 424, end_byte: 432 },
61+
],
62+
),
63+
WordLocation::new(
64+
"numberes".to_string(),
65+
vec![TextRange { start_byte: 651, end_byte: 659 }],
66+
),
67+
// Constants
68+
WordLocation::new(
69+
"CONSATANT".to_string(),
70+
vec![TextRange { start_byte: 699, end_byte: 708 }],
71+
),
72+
WordLocation::new(
73+
"COONSTANT".to_string(),
74+
vec![TextRange { start_byte: 729, end_byte: 738 }],
75+
),
76+
WordLocation::new(
77+
"TWOOF".to_string(),
78+
vec![TextRange { start_byte: 1448, end_byte: 1453 }],
79+
),
80+
// Variable declarations
81+
WordLocation::new(
82+
"assignement".to_string(),
83+
vec![
84+
TextRange { start_byte: 783, end_byte: 794 },
85+
TextRange { start_byte: 845, end_byte: 856 },
86+
TextRange { start_byte: 864, end_byte: 875 },
87+
],
88+
),
89+
WordLocation::new(
90+
"anotther".to_string(),
91+
vec![TextRange { start_byte: 811, end_byte: 819 }],
92+
),
93+
WordLocation::new(
94+
"annother".to_string(),
95+
vec![TextRange { start_byte: 825, end_byte: 833 }],
96+
),
97+
// Strings
98+
WordLocation::new(
99+
"Helloep".to_string(),
100+
vec![TextRange { start_byte: 937, end_byte: 944 }],
101+
),
102+
WordLocation::new(
103+
"Wordl".to_string(),
104+
vec![TextRange { start_byte: 948, end_byte: 953 }],
105+
),
106+
WordLocation::new(
107+
"Helolo".to_string(),
108+
vec![TextRange { start_byte: 1969, end_byte: 1975 }],
109+
),
110+
WordLocation::new(
111+
"Wlorld".to_string(),
112+
vec![TextRange { start_byte: 1977, end_byte: 1983 }],
113+
),
114+
// Struct declarations and fields
115+
WordLocation::new(
116+
"Awseome".to_string(),
117+
vec![TextRange { start_byte: 1153, end_byte: 1160 }],
118+
),
119+
WordLocation::new(
120+
"Compacot".to_string(),
121+
vec![TextRange { start_byte: 1299, end_byte: 1307 }],
122+
),
123+
WordLocation::new(
124+
"aples".to_string(),
125+
vec![TextRange { start_byte: 1328, end_byte: 1333 }],
126+
),
127+
WordLocation::new(
128+
"banananas".to_string(),
129+
vec![TextRange { start_byte: 1335, end_byte: 1344 }],
130+
),
131+
WordLocation::new(
132+
"ornages".to_string(),
133+
vec![TextRange { start_byte: 1346, end_byte: 1353 }],
134+
),
135+
// Enum declaration and members
136+
WordLocation::new(
137+
"Cratfy".to_string(),
138+
vec![TextRange { start_byte: 1462, end_byte: 1468 }],
139+
),
140+
WordLocation::new(
141+
"Aapple".to_string(),
142+
vec![TextRange { start_byte: 1485, end_byte: 1491 }],
143+
),
144+
WordLocation::new(
145+
"Baanana".to_string(),
146+
vec![TextRange { start_byte: 1495, end_byte: 1502 }],
147+
),
148+
WordLocation::new(
149+
"Oranege".to_string(),
150+
vec![TextRange { start_byte: 1510, end_byte: 1517 }],
151+
),
152+
// Union declaration
153+
WordLocation::new(
154+
"Unberakable".to_string(),
155+
vec![TextRange { start_byte: 1583, end_byte: 1594 }],
156+
),
157+
// Bit field declaration and members
158+
WordLocation::new(
159+
"Frutty".to_string(),
160+
vec![TextRange { start_byte: 1625, end_byte: 1631 }],
161+
),
162+
WordLocation::new(
163+
"verison".to_string(),
164+
vec![TextRange { start_byte: 1664, end_byte: 1671 }],
165+
),
166+
WordLocation::new(
167+
"ttl".to_string(),
168+
vec![TextRange { start_byte: 1691, end_byte: 1694 }],
169+
),
170+
WordLocation::new(
171+
"opration".to_string(),
172+
vec![TextRange { start_byte: 1750, end_byte: 1758 }],
173+
),
174+
WordLocation::new(
175+
"opernd".to_string(),
176+
vec![TextRange { start_byte: 1782, end_byte: 1788 }],
177+
),
178+
WordLocation::new(
179+
"oprand".to_string(),
180+
vec![TextRange { start_byte: 1811, end_byte: 1817 }],
181+
),
182+
];
183+
let not_expected = ["fmt", "println"];
184+
let processor = utils::get_processor();
185+
let misspelled = processor
186+
.spell_check(sample_text, Some(LanguageType::Odin), None)
187+
.to_vec();
188+
println!("Misspelled words: {misspelled:?}");
189+
for e in &expected {
190+
println!("Expecting: {e:?}");
191+
let miss = misspelled.iter().find(|r| r.word == e.word).unwrap();
192+
// assert_eq!(miss.locations, e.locations);
193+
assert!(miss.locations.len() == e.locations.len());
194+
for location in &miss.locations {
195+
assert!(e.locations.contains(location));
196+
}
197+
}
198+
for result in misspelled {
199+
assert!(!not_expected.contains(&result.word.as_str()));
200+
}
201+
}

0 commit comments

Comments
 (0)