@@ -18,6 +18,7 @@ import 'package:unittest/unittest.dart';
18
18
19
19
import '../bin/lint.dart' as dartlint;
20
20
import 'package:dart_lint/src/rules/camel_case_types.dart' ;
21
+ import 'package:dart_lint/src/rules/library_names.dart' ;
21
22
22
23
const String ruleDir = 'test/rules' ;
23
24
@@ -33,13 +34,19 @@ void defineLinterEngineTests() {
33
34
expect (msg, expected);
34
35
});
35
36
}
36
- _test ('exception' , 'EXCEPTION: LinterException: foo' ,
37
+ _test (
38
+ 'exception' ,
39
+ 'EXCEPTION: LinterException: foo' ,
37
40
(r) => r.exception (new LinterException ('foo' )));
38
41
_test ('logError' , 'ERROR: foo' , (r) => r.logError ('foo' ));
39
- _test ('logError2' , 'ERROR: foo' ,
42
+ _test (
43
+ 'logError2' ,
44
+ 'ERROR: foo' ,
40
45
(r) => r.logError2 ('foo' , new Exception ()));
41
46
_test ('logInformation' , 'INFO: foo' , (r) => r.logInformation ('foo' ));
42
- _test ('logInformation2' , 'INFO: foo' ,
47
+ _test (
48
+ 'logInformation2' ,
49
+ 'INFO: foo' ,
43
50
(r) => r.logInformation2 ('foo' , new Exception ()));
44
51
_test ('warn' , 'WARN: foo' , (r) => r.warn ('foo' ));
45
52
});
@@ -50,7 +57,8 @@ void defineLinterEngineTests() {
50
57
});
51
58
test ('toString' , () {
52
59
expect (const LinterException ().toString (), equals ('LinterException' ));
53
- expect (const LinterException ('foo' ).toString (),
60
+ expect (
61
+ const LinterException ('foo' ).toString (),
54
62
equals ('LinterException: foo' ));
55
63
});
56
64
});
@@ -61,7 +69,8 @@ void defineLinterEngineTests() {
61
69
expect (new CamelCaseString ('Foo' ).humanized, equals ('Foo' ));
62
70
});
63
71
test ('validation' , () {
64
- expect (() => new CamelCaseString ('foo' ),
72
+ expect (
73
+ () => new CamelCaseString ('foo' ),
65
74
throwsA (new isInstanceOf <ArgumentError >()));
66
75
});
67
76
test ('toString' , () {
@@ -90,9 +99,10 @@ void defineLinterEngineTests() {
90
99
bool visited;
91
100
var options =
92
101
new LinterOptions (() => [new MockLinter ((n) => visited = true )]);
93
- new SourceLinter (options).lintLibrarySource (
94
- libraryName: 'testLibrary' ,
95
- libraryContents: 'library testLibrary;' );
102
+ new SourceLinter (
103
+ options).lintLibrarySource (
104
+ libraryName: 'testLibrary' ,
105
+ libraryContents: 'library testLibrary;' );
96
106
expect (visited, isTrue);
97
107
});
98
108
});
@@ -129,11 +139,11 @@ void defineLinterEngineTests() {
129
139
group ('io' , () {
130
140
test ('link' , () {
131
141
Link l = new Link ('bogus' );
132
- expect (processFile (l), isFalse);
142
+ expect (lintFile (l), isFalse);
133
143
});
134
144
test ('bad extension' , () {
135
145
File f = new File ('bogus.txt' );
136
- expect (processFile (f), isFalse);
146
+ expect (lintFile (f), isFalse);
137
147
});
138
148
});
139
149
@@ -146,23 +156,26 @@ void defineLinterEngineTests() {
146
156
test ('html - strong' , () {
147
157
Hyperlink link =
148
158
new Hyperlink ('dart' , 'http://dartlang.org' , bold: true );
149
- expect (link.html, equals (
150
- '<a href="http://dartlang.org"><strong>dart</strong></a>' ));
159
+ expect (
160
+ link.html,
161
+ equals ('<a href="http://dartlang.org"><strong>dart</strong></a>' ));
151
162
});
152
163
});
153
164
group ('kind' , () {
154
165
test ('priority' , () {
155
- expect (Kind .supported, orderedEquals (
156
- [Kind .DO , Kind .DONT , Kind .PREFER , Kind .AVOID , Kind .CONSIDER ]));
166
+ expect (
167
+ Kind .supported,
168
+ orderedEquals ([Kind .DO , Kind .DONT , Kind .PREFER , Kind .AVOID , Kind .CONSIDER ]));
157
169
});
158
170
test ('comparing' , () {
159
171
expect (Kind .DO .compareTo (Kind .DONT ), equals (- 1 ));
160
172
});
161
173
});
162
174
group ('rule' , () {
163
175
test ('sorting' , () {
164
- expect (Kind .supported, orderedEquals (
165
- [Kind .DO , Kind .DONT , Kind .PREFER , Kind .AVOID , Kind .CONSIDER ]));
176
+ expect (
177
+ Kind .supported,
178
+ orderedEquals ([Kind .DO , Kind .DONT , Kind .PREFER , Kind .AVOID , Kind .CONSIDER ]));
166
179
});
167
180
test ('comparing' , () {
168
181
LintRule r1 = new MockLintRule ('Bar' , Kind .DO );
@@ -202,15 +215,14 @@ defineRuleUnitTests() {
202
215
group ('camel case' , () {
203
216
group ('upper' , () {
204
217
var good = [
205
- '_FooBar' ,
206
- 'FooBar' ,
207
- '_Foo' ,
208
- 'Foo' ,
209
- 'F' ,
210
- 'FB' ,
211
- 'F1' ,
212
- 'FooBar1'
213
- ];
218
+ '_FooBar' ,
219
+ 'FooBar' ,
220
+ '_Foo' ,
221
+ 'Foo' ,
222
+ 'F' ,
223
+ 'FB' ,
224
+ 'F1' ,
225
+ 'FooBar1' ];
214
226
good.forEach (
215
227
(s) => test ('"$s "' , () => expect (isUpperCamelCase (s), isTrue)));
216
228
@@ -219,6 +231,15 @@ defineRuleUnitTests() {
219
231
(s) => test ('"$s "' , () => expect (isUpperCamelCase (s), isFalse)));
220
232
});
221
233
});
234
+ group ('lower_case_underscores' , () {
235
+ var good = ['foo_bar' , 'foo' , 'foo_bar_baz' ];
236
+ good.forEach (
237
+ (s) => test ('"$s "' , () => expect (isLowerCaseUnderScore (s), isTrue)));
238
+
239
+ var bad = ['Foo' , 'fooBar' , 'foo_Bar' , 'foo_' , '_f' , 'F_B' ];
240
+ bad.forEach (
241
+ (s) => test ('"$s "' , () => expect (isLowerCaseUnderScore (s), isFalse)));
242
+ });
222
243
});
223
244
}
224
245
@@ -231,7 +252,8 @@ void defineSanityTests() {
231
252
expect (extractAnnotation ('int x; //LINT' ), isNotNull);
232
253
expect (extractAnnotation ('int x; // OK' ), isNull);
233
254
expect (extractAnnotation ('int x;' ), isNull);
234
- expect (extractAnnotation ('dynamic x; // LINT dynamic is bad' ).message,
255
+ expect (
256
+ extractAnnotation ('dynamic x; // LINT dynamic is bad' ).message,
235
257
equals ('dynamic is bad' ));
236
258
expect (extractAnnotation ('dynamic x; //LINT' ).message, isNull);
237
259
expect (extractAnnotation ('dynamic x; //LINT ' ).message, isNull);
@@ -241,18 +263,28 @@ void defineSanityTests() {
241
263
expect (
242
264
new Annotation ('Actual message (to be ignored)' , ErrorType .LINT , 1 ),
243
265
matchesAnnotation (null , ErrorType .LINT , 1 ));
244
- expect (new Annotation ('Message' , ErrorType .LINT , 1 ),
266
+ expect (
267
+ new Annotation ('Message' , ErrorType .LINT , 1 ),
245
268
matchesAnnotation ('Message' , ErrorType .LINT , 1 ));
246
269
});
247
270
test ('inequality' , () {
248
- expect (() => expect (new Annotation ('Message' , ErrorType .LINT , 1 ),
249
- matchesAnnotation ('Message' , ErrorType .HINT , 1 )),
271
+ expect (
272
+ () =>
273
+ expect (
274
+ new Annotation ('Message' , ErrorType .LINT , 1 ),
275
+ matchesAnnotation ('Message' , ErrorType .HINT , 1 )),
250
276
throwsA (new isInstanceOf <TestFailure >()));
251
- expect (() => expect (new Annotation ('Message' , ErrorType .LINT , 1 ),
252
- matchesAnnotation ('Message2' , ErrorType .LINT , 1 )),
277
+ expect (
278
+ () =>
279
+ expect (
280
+ new Annotation ('Message' , ErrorType .LINT , 1 ),
281
+ matchesAnnotation ('Message2' , ErrorType .LINT , 1 )),
253
282
throwsA (new isInstanceOf <TestFailure >()));
254
- expect (() => expect (new Annotation ('Message' , ErrorType .LINT , 1 ),
255
- matchesAnnotation ('Message' , ErrorType .LINT , 2 )),
283
+ expect (
284
+ () =>
285
+ expect (
286
+ new Annotation ('Message' , ErrorType .LINT , 1 ),
287
+ matchesAnnotation ('Message' , ErrorType .LINT , 2 )),
256
288
throwsA (new isInstanceOf <TestFailure >()));
257
289
});
258
290
});
@@ -283,9 +315,9 @@ main() {
283
315
defineRuleUnitTests ();
284
316
}
285
317
286
- AnnotationMatcher matchesAnnotation (
287
- String message, ErrorType type, int lineNumber) =>
288
- new AnnotationMatcher (new Annotation (message, type, lineNumber));
318
+ AnnotationMatcher matchesAnnotation (String message, ErrorType type,
319
+ int lineNumber) =>
320
+ new AnnotationMatcher (new Annotation (message, type, lineNumber));
289
321
290
322
void testRule (String ruleName, File file) {
291
323
test ('$ruleName ' , () {
@@ -329,8 +361,10 @@ class Annotation {
329
361
330
362
Annotation (this .message, this .type, this .lineNumber);
331
363
332
- Annotation .forError (AnalysisError error, LineInfo lineInfo) : this (
333
- error.message, error.errorCode.type,
364
+ Annotation .forError (AnalysisError error, LineInfo lineInfo)
365
+ : this (
366
+ error.message,
367
+ error.errorCode.type,
334
368
lineInfo.getLocation (error.offset).lineNumber);
335
369
336
370
Annotation .forLint ([String message]) : this (message, ErrorType .LINT , null );
@@ -371,7 +405,8 @@ class AnnotationMatcher extends Matcher {
371
405
class MockLinter extends LintRule {
372
406
VisitorCallback visitorCallback;
373
407
374
- MockLinter ([nodeVisitor v]) : super (
408
+ MockLinter ([nodeVisitor v])
409
+ : super (
375
410
name: 'MockLint' ,
376
411
group: Group .STYLE_GUIDE ,
377
412
kind: Kind .AVOID ,
0 commit comments