Chromium Code Reviews| Index: utils/tests/pub/validator_test.dart |
| diff --git a/utils/tests/pub/validator_test.dart b/utils/tests/pub/validator_test.dart |
| index eaada1a0aae22bb1ff092b9e078b024a9ffc5687..f734c230e5c4857a13254e14b1ab4eca135e4765 100644 |
| --- a/utils/tests/pub/validator_test.dart |
| +++ b/utils/tests/pub/validator_test.dart |
| @@ -12,6 +12,7 @@ import '../../../pkg/unittest/lib/unittest.dart'; |
| import '../../pub/entrypoint.dart'; |
| import '../../pub/io.dart'; |
| import '../../pub/validator.dart'; |
| +import '../../pub/validator/name.dart'; |
| import '../../pub/validator/pubspec_field.dart'; |
| void expectNoValidationError(ValidatorCreator fn) { |
| @@ -29,6 +30,8 @@ void expectValidationWarning(ValidatorCreator fn) { |
| Validator pubspecField(Entrypoint entrypoint) => |
| new PubspecFieldValidator(entrypoint); |
| +Validator name(Entrypoint entrypoint) => new NameValidator(entrypoint); |
| + |
| main() { |
| group('should consider a package valid if it', () { |
| test('looks normal', () { |
| @@ -44,6 +47,18 @@ main() { |
| expectNoValidationError(pubspecField); |
| run(); |
| }); |
| + |
| + test('has a badly-named library in lib/src', () { |
| + dir(appPath, [ |
| + libPubspec("test_pkg", "1.0.0"), |
| + dir("lib", [ |
| + file("test_pkg.dart", "int i = 1;"), |
| + dir("src", [file("8ball.dart", "int j = 2;")]) |
| + ]) |
| + ]).scheduleCreate(); |
| + expectNoValidationError(name); |
| + run(); |
|
Bob Nystrom
2012/12/07 17:07:43
I like this.
|
| + }); |
| }); |
| group('should consider a package invalid if it', () { |
| @@ -110,5 +125,71 @@ main() { |
| expectValidationWarning(pubspecField); |
| run(); |
| }); |
| + |
| + test('has an empty package name', () { |
| + dir(appPath, [libPubspec("", "1.0.0")]).scheduleCreate(); |
| + expectValidationError(name); |
| + run(); |
| + }); |
| + |
| + test('has a package name with an invalid character', () { |
| + dir(appPath, [libPubspec("test-pkg", "1.0.0")]).scheduleCreate(); |
| + expectValidationError(name); |
| + run(); |
| + }); |
| + |
| + test('has a package name that begins with a number', () { |
| + dir(appPath, [libPubspec("8ball", "1.0.0")]).scheduleCreate(); |
| + expectValidationError(name); |
| + run(); |
| + }); |
| + |
| + test('has a package name that contains upper-case letters', () { |
| + dir(appPath, [libPubspec("TestPkg", "1.0.0")]).scheduleCreate(); |
| + expectValidationWarning(name); |
| + run(); |
| + }); |
| + |
| + test('has a package name that is a Dart identifier', () { |
| + dir(appPath, [libPubspec("operator", "1.0.0")]).scheduleCreate(); |
| + expectValidationError(name); |
| + run(); |
| + }); |
| + |
| + test('has a library name with an invalid character', () { |
| + dir(appPath, [ |
| + libPubspec("test_pkg", "1.0.0"), |
| + dir("lib", [file("test-pkg.dart", "int i = 0;")]) |
| + ]).scheduleCreate(); |
| + expectValidationError(name); |
| + run(); |
| + }); |
| + |
| + test('has a library name that begins with a number', () { |
| + dir(appPath, [ |
| + libPubspec("test_pkg", "1.0.0"), |
| + dir("lib", [file("8ball.dart", "int i = 0;")]) |
| + ]).scheduleCreate(); |
| + expectValidationError(name); |
| + run(); |
| + }); |
| + |
| + test('has a library name that contains upper-case letters', () { |
| + dir(appPath, [ |
| + libPubspec("test_pkg", "1.0.0"), |
| + dir("lib", [file("TestPkg.dart", "int i = 0;")]) |
| + ]).scheduleCreate(); |
| + expectValidationWarning(name); |
| + run(); |
| + }); |
| + |
| + test('has a library name that is a Dart identifier', () { |
| + dir(appPath, [ |
| + libPubspec("test_pkg", "1.0.0"), |
| + dir("lib", [file("operator.dart", "int i = 0;")]) |
| + ]).scheduleCreate(); |
| + expectValidationError(name); |
| + run(); |
| + }); |
| }); |
| } |