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 = [ |
| 71 Uri.parse('foo/bar.dart'), |
| 72 Uri.parse('src/bar.dart'), |
| 73 Uri.parse('dart:async') |
| 74 ]; |
| 75 uris2.forEach((uri) { |
| 76 test(uri.toString(), () { |
| 77 expect(isPackage(uri), isFalse); |
| 78 }); |
| 79 }); |
| 80 }); |
| 81 |
| 82 group('samePackage', () { |
| 83 test('identity', () { |
| 84 expect( |
| 85 samePackage(Uri.parse('package:foo/src/bar.dart'), |
| 86 Uri.parse('package:foo/src/bar.dart')), |
| 87 isTrue); |
| 88 }); |
| 89 test('foo/bar.dart', () { |
| 90 expect( |
| 91 samePackage(Uri.parse('package:foo/src/bar.dart'), |
| 92 Uri.parse('package:foo/bar.dart')), |
| 93 isTrue); |
| 94 }); |
| 95 }); |
| 96 |
| 97 group('implementation', () { |
| 98 var uris = [ |
| 99 Uri.parse('package:foo/src/bar.dart'), |
| 100 Uri.parse('package:foo/src/baz/bar.dart') |
| 101 ]; |
| 102 uris.forEach((uri) { |
| 103 test(uri.toString(), () { |
| 104 expect(isImplementation(uri), isTrue); |
| 105 }); |
| 106 }); |
| 107 var uris2 = [ |
| 108 Uri.parse('package:foo/bar.dart'), |
| 109 Uri.parse('src/bar.dart') |
| 110 ]; |
| 111 uris2.forEach((uri) { |
| 112 test(uri.toString(), () { |
| 113 expect(isImplementation(uri), isFalse); |
| 114 }); |
| 115 }); |
| 116 }); |
| 117 }); |
| 118 |
58 group('names', () { | 119 group('names', () { |
59 group('keywords', () { | 120 group('keywords', () { |
60 var good = ['class', 'if', 'assert', 'catch', 'import']; | 121 var good = ['class', 'if', 'assert', 'catch', 'import']; |
61 testEach(good, isKeyWord, isTrue); | 122 testEach(good, isKeyWord, isTrue); |
62 var bad = ['_class', 'iff', 'assert_', 'Catch']; | 123 var bad = ['_class', 'iff', 'assert_', 'Catch']; |
63 testEach(bad, isKeyWord, isFalse); | 124 testEach(bad, isKeyWord, isFalse); |
64 }); | 125 }); |
65 group('identifiers', () { | 126 group('identifiers', () { |
66 var good = ['foo', '_if', '_', 'f2', 'fooBar', 'foo_bar']; | 127 var good = ['foo', '_if', '_', 'f2', 'fooBar', 'foo_bar']; |
67 testEach(good, isValidDartIdentifier, isTrue); | 128 testEach(good, isValidDartIdentifier, isTrue); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 if (_expected.column != null) { | 418 if (_expected.column != null) { |
358 if (_expected.column != other.column || | 419 if (_expected.column != other.column || |
359 _expected.length != other.length) { | 420 _expected.length != other.length) { |
360 return false; | 421 return false; |
361 } | 422 } |
362 } | 423 } |
363 return _expected.type == other.type && | 424 return _expected.type == other.type && |
364 _expected.lineNumber == other.lineNumber; | 425 _expected.lineNumber == other.lineNumber; |
365 } | 426 } |
366 } | 427 } |
OLD | NEW |