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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
use codebook::queries::LanguageType;
use super::utils::assert_spelling_at;
#[test]
fn test_dart_simple() {
let sample_text = r#"
import 'dart:math';
import 'package:flutter/materail.dart';
/// A documntation comment
class MyWidgett extends StatelessWidget {
final String titlee;
final int countr;
const MyWidgett({required this.titlee, required this.countr});
// Regular coment with misspeling
String getMessge() {
var greting = "Helllo Worlld";
if (countr == 0) {
return "No itemms";
}
return greting + " numbr $countr";
}
/* Block coment
* with misspeled words
*/
List<String> getItemms() {
return ["firstt", "seconnd", "thirdd"];
}
}
enum Statuss {
activve,
inacive,
}
"#;
// Import URI contents (dart, package, flutter, and even the misspelled
// materail) are not spell-checked; exact set equality guards that.
assert_spelling_at(
LanguageType::Dart,
sample_text,
&[
("documntation", &[0]),
// Flagged at the class definition; the `const MyWidgett({...})`
// constructor is not.
("Widgett", &[0]),
// Fields are flagged at their definitions; `this.titlee`,
// `this.countr`, and the `$countr` interpolation are not.
("titlee", &[0]),
("countr", &[0]),
// Both the line comment and the block comment are checked.
("coment", &[0, 1]),
("misspeling", &[0]),
("misspeled", &[0]),
("Messge", &[0]),
// Flagged at the declaration; the later usage is not.
("greting", &[0]),
("Helllo", &[0]),
("Worlld", &[0]),
("itemms", &[0]),
("numbr", &[0]),
("Itemms", &[0]),
("firstt", &[0]),
("seconnd", &[0]),
("thirdd", &[0]),
("Statuss", &[0]),
("activve", &[0]),
("inacive", &[0]),
],
);
}
#[test]
fn test_dart_string_interpolation() {
let sample_text = r#"
class Foo {
String usrname = "bob";
void doStuff() {
var greting = "Helllo";
logg('Deleeted accaunt for $usrname');
print("Greting is $greting and numbr ${usrname.length}");
}
}
"#;
// Not flagged: "bob" (valid word in string content), `logg` (function
// call reference, not a definition), and `length` (interpolation
// expression member).
assert_spelling_at(
LanguageType::Dart,
sample_text,
&[
// Flagged at the field definition; the `$usrname` and
// `${usrname.length}` interpolation references are not.
("usrname", &[0]),
// Flagged at the declaration; the `$greting` interpolation is not.
("greting", &[0]),
("Helllo", &[0]),
// String content around interpolations is checked.
("Deleeted", &[0]),
("accaunt", &[0]),
("Greting", &[0]),
("numbr", &[0]),
],
);
}
#[test]
fn test_dart_class_fields() {
let sample_text = r#"
class UserAccaunt {
final String usrname;
final Map<String, UserAccaunt> _accaunts = {};
int _balanse = 0;
}
"#;
// Type references (String, Map, int, and the `UserAccaunt` inside the
// Map generic) are not spell-checked; exact set equality guards that.
assert_spelling_at(
LanguageType::Dart,
sample_text,
&[
// Class name flagged at the definition only.
("Accaunt", &[0]),
// Class fields are flagged at their definitions.
("usrname", &[0]),
("accaunts", &[0]),
("balanse", &[0]),
],
);
}
#[test]
fn test_dart_arrow_body_strings() {
let sample_text = r#"
class Foo {
String usrname = "bob";
int _balanse = 0;
@override
String toString() => 'Accaunt(usrname: $usrname, balanse: $_balanse)';
}
"#;
assert_spelling_at(
LanguageType::Dart,
sample_text,
&[
// String content in the arrow body is checked.
("Accaunt", &[0]),
// Flagged at the field definition and at the literal text inside
// the arrow-body string; the `$usrname` interpolation is not.
("usrname", &[0, 1]),
("balanse", &[0, 1]),
],
);
}
#[test]
fn test_dart_type_references_not_flagged() {
let sample_text = r#"
typedef MyCallbak = void Function(int);
mixin Loggabel {}
class Foo with Loggabel {
final Map<String, List<int>> dataa = {};
final MyCallbak? callbak;
Foo({required this.dataa, this.callbak});
Future<List<String>> fetchStuf() async {
return [];
}
}
"#;
// Type references (Map, String, List, int, Future) are not
// spell-checked; exact set equality guards that.
assert_spelling_at(
LanguageType::Dart,
sample_text,
&[
// Flagged at the typedef definition; the `MyCallbak?` field type
// reference is not.
("Callbak", &[0]),
// Flagged at the mixin definition; the `with Loggabel` reference
// is not.
("Loggabel", &[0]),
// Fields are flagged at definitions; `this.dataa`/`this.callbak`
// are not.
("dataa", &[0]),
("callbak", &[0]),
("Stuf", &[0]),
],
);
}