OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library linter.test.rule; | 5 library linter.test.rule; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
11 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
12 import 'package:linter/src/ast.dart'; | 12 import 'package:linter/src/ast.dart'; |
13 import 'package:linter/src/io.dart'; | 13 import 'package:linter/src/io.dart'; |
14 import 'package:linter/src/linter.dart'; | 14 import 'package:linter/src/linter.dart'; |
15 import 'package:linter/src/rules.dart'; | 15 import 'package:linter/src/rules.dart'; |
16 import 'package:linter/src/rules/camel_case_types.dart'; | 16 import 'package:linter/src/rules/camel_case_types.dart'; |
17 import 'package:linter/src/rules/implementation_imports.dart'; | |
17 import 'package:linter/src/rules/package_prefixed_library_names.dart'; | 18 import 'package:linter/src/rules/package_prefixed_library_names.dart'; |
18 import 'package:linter/src/util.dart'; | 19 import 'package:linter/src/util.dart'; |
19 import 'package:path/path.dart' as p; | 20 import 'package:path/path.dart' as p; |
20 import 'package:unittest/unittest.dart'; | 21 import 'package:unittest/unittest.dart'; |
21 | 22 |
22 main() { | 23 main() { |
23 groupSep = ' | '; | 24 groupSep = ' | '; |
24 | 25 |
25 defineSanityTests(); | 26 defineSanityTests(); |
26 defineRuleTests(); | 27 defineRuleTests(); |
(...skipping 21 matching lines...) Expand all Loading... | |
48 if (file is! File || !isPubspecFile(file)) continue; | 49 if (file is! File || !isPubspecFile(file)) continue; |
49 var ruleName = p.basename(pubTestDir.path); | 50 var ruleName = p.basename(pubTestDir.path); |
50 testRule(ruleName, file); | 51 testRule(ruleName, file); |
51 } | 52 } |
52 } | 53 } |
53 }); | 54 }); |
54 }); | 55 }); |
55 } | 56 } |
56 | 57 |
57 defineRuleUnitTests() { | 58 defineRuleUnitTests() { |
59 group('uris', () { | |
60 group('isPackage', () { | |
61 var uris = [ | |
62 Uri.parse('package:foo/src/bar.dart'), | |
63 Uri.parse('package:foo/src/baz/bar.dart') | |
64 ]; | |
65 uris.forEach((uri) { | |
66 test(uri.toString(), () { | |
67 expect(isPackage(uri), isTrue); | |
68 }); | |
69 }); | |
70 var uris2 = [Uri.parse('foo/bar.dart'), Uri.parse('src/bar.dart')]; | |
Brian Wilkerson
2015/10/31 21:04:30
Include a non-package, but absolute, URI (such as
pquitslund
2015/10/31 23:13:09
Good one. Done!
| |
71 uris2.forEach((uri) { | |
72 test(uri.toString(), () { | |
73 expect(isPackage(uri), isFalse); | |
74 }); | |
75 }); | |
76 }); | |
77 | |
78 group('samePackage', () { | |
79 test('identity', () { | |
80 expect( | |
81 samePackage(Uri.parse('package:foo/src/bar.dart'), | |
82 Uri.parse('package:foo/src/bar.dart')), | |
83 isTrue); | |
84 }); | |
85 test('foo/bar.dart', () { | |
86 expect( | |
87 samePackage(Uri.parse('package:foo/src/bar.dart'), | |
88 Uri.parse('package:foo/bar.dart')), | |
89 isTrue); | |
90 }); | |
91 }); | |
92 | |
93 group('implementation', () { | |
94 var uris = [ | |
95 Uri.parse('package:foo/src/bar.dart'), | |
96 Uri.parse('package:foo/src/baz/bar.dart') | |
97 ]; | |
98 uris.forEach((uri) { | |
99 test(uri.toString(), () { | |
100 expect(isImplementation(uri), isTrue); | |
101 }); | |
102 }); | |
103 var uris2 = [ | |
104 Uri.parse('package:foo/bar.dart'), | |
105 Uri.parse('src/bar.dart') | |
106 ]; | |
107 uris2.forEach((uri) { | |
108 test(uri.toString(), () { | |
109 expect(isImplementation(uri), isFalse); | |
110 }); | |
111 }); | |
112 }); | |
113 }); | |
114 | |
58 group('names', () { | 115 group('names', () { |
59 group('keywords', () { | 116 group('keywords', () { |
60 var good = ['class', 'if', 'assert', 'catch', 'import']; | 117 var good = ['class', 'if', 'assert', 'catch', 'import']; |
61 testEach(good, isKeyWord, isTrue); | 118 testEach(good, isKeyWord, isTrue); |
62 var bad = ['_class', 'iff', 'assert_', 'Catch']; | 119 var bad = ['_class', 'iff', 'assert_', 'Catch']; |
63 testEach(bad, isKeyWord, isFalse); | 120 testEach(bad, isKeyWord, isFalse); |
64 }); | 121 }); |
65 group('identifiers', () { | 122 group('identifiers', () { |
66 var good = ['foo', '_if', '_', 'f2', 'fooBar', 'foo_bar']; | 123 var good = ['foo', '_if', '_', 'f2', 'fooBar', 'foo_bar']; |
67 testEach(good, isValidDartIdentifier, isTrue); | 124 testEach(good, isValidDartIdentifier, isTrue); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 if (_expected.column != null) { | 414 if (_expected.column != null) { |
358 if (_expected.column != other.column || | 415 if (_expected.column != other.column || |
359 _expected.length != other.length) { | 416 _expected.length != other.length) { |
360 return false; | 417 return false; |
361 } | 418 } |
362 } | 419 } |
363 return _expected.type == other.type && | 420 return _expected.type == other.type && |
364 _expected.lineNumber == other.lineNumber; | 421 _expected.lineNumber == other.lineNumber; |
365 } | 422 } |
366 } | 423 } |
OLD | NEW |