| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 pubspec_test; | 5 library pubspec_test; |
| 6 | 6 |
| 7 import '../../../pkg/unittest/lib/unittest.dart'; | 7 import '../../../pkg/unittest/lib/unittest.dart'; |
| 8 import 'test_pub.dart'; | 8 import 'test_pub.dart'; |
| 9 import '../../pub/pubspec.dart'; | 9 import '../../pub/pubspec.dart'; |
| 10 import '../../pub/source.dart'; | 10 import '../../pub/source.dart'; |
| 11 import '../../pub/source_registry.dart'; | 11 import '../../pub/source_registry.dart'; |
| 12 import '../../pub/utils.dart'; | 12 import '../../pub/utils.dart'; |
| 13 import '../../pub/version.dart'; | 13 import '../../pub/version.dart'; |
| 14 | 14 |
| 15 class MockSource extends Source { | 15 class MockSource extends Source { |
| 16 final String name = "mock"; | 16 final String name = "mock"; |
| 17 final bool shouldCache = false; | 17 final bool shouldCache = false; |
| 18 void validateDescription(description, {bool fromLockFile: false}) { | 18 void validateDescription(description, {bool fromLockFile: false}) { |
| 19 if (description != 'ok') throw new FormatException('Bad'); | 19 if (description != 'ok') throw new FormatException('Bad'); |
| 20 } | 20 } |
| 21 String packageName(description) => 'foo'; | 21 String packageName(description) => 'foo'; |
| 22 } | 22 } |
| 23 | 23 |
| 24 main() { | 24 main() { |
| 25 initConfig(); |
| 25 group('Pubspec', () { | 26 group('Pubspec', () { |
| 26 group('parse()', () { | 27 group('parse()', () { |
| 27 var sources = new SourceRegistry(); | 28 var sources = new SourceRegistry(); |
| 28 sources.register(new MockSource()); | 29 sources.register(new MockSource()); |
| 29 | 30 |
| 30 expectFormatError(String pubspec) { | 31 expectFormatError(String pubspec) { |
| 31 expect(() => new Pubspec.parse(pubspec, sources), | 32 expect(() => new Pubspec.parse(pubspec, sources), |
| 32 throwsFormatException); | 33 throwsFormatException); |
| 33 } | 34 } |
| 34 | 35 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 70 |
| 70 test("throws if 'homepage' is not a string", () { | 71 test("throws if 'homepage' is not a string", () { |
| 71 expectFormatError('homepage:'); | 72 expectFormatError('homepage:'); |
| 72 expectFormatError('homepage: [not, a, string]'); | 73 expectFormatError('homepage: [not, a, string]'); |
| 73 }); | 74 }); |
| 74 | 75 |
| 75 test("throws if 'homepage' doesn't have an HTTP scheme", () { | 76 test("throws if 'homepage' doesn't have an HTTP scheme", () { |
| 76 new Pubspec.parse('homepage: http://ok.com', sources); | 77 new Pubspec.parse('homepage: http://ok.com', sources); |
| 77 new Pubspec.parse('homepage: https://also-ok.com', sources); | 78 new Pubspec.parse('homepage: https://also-ok.com', sources); |
| 78 | 79 |
| 79 expectFormatError('ftp://badscheme.com'); | 80 expectFormatError('homepage: ftp://badscheme.com'); |
| 80 expectFormatError('javascript:alert("!!!")'); | 81 expectFormatError('homepage: javascript:alert("!!!")'); |
| 81 expectFormatError('data:image/png;base64,somedata'); | 82 expectFormatError('homepage: data:image/png;base64,somedata'); |
| 82 expectFormatError('homepage: no-scheme.com'); | 83 expectFormatError('homepage: no-scheme.com'); |
| 83 }); | 84 }); |
| 84 | 85 |
| 86 test("throws if 'documentation' is not a string", () { |
| 87 expectFormatError('documentation:'); |
| 88 expectFormatError('documentation: [not, a, string]'); |
| 89 }); |
| 90 |
| 91 test("throws if 'documentation' doesn't have an HTTP scheme", () { |
| 92 new Pubspec.parse('documentation: http://ok.com', sources); |
| 93 new Pubspec.parse('documentation: https://also-ok.com', sources); |
| 94 |
| 95 expectFormatError('documentation: ftp://badscheme.com'); |
| 96 expectFormatError('documentation: javascript:alert("!!!")'); |
| 97 expectFormatError('documentation: data:image/png;base64,somedata'); |
| 98 expectFormatError('documentation: no-scheme.com'); |
| 99 }); |
| 100 |
| 85 test("throws if 'authors' is not a string or a list of strings", () { | 101 test("throws if 'authors' is not a string or a list of strings", () { |
| 86 new Pubspec.parse('authors: ok fine', sources); | 102 new Pubspec.parse('authors: ok fine', sources); |
| 87 new Pubspec.parse('authors: [also, ok, fine]', sources); | 103 new Pubspec.parse('authors: [also, ok, fine]', sources); |
| 88 | 104 |
| 89 expectFormatError('authors: 123'); | 105 expectFormatError('authors: 123'); |
| 90 expectFormatError('authors: {not: {a: string}}'); | 106 expectFormatError('authors: {not: {a: string}}'); |
| 91 expectFormatError('authors: [ok, {not: ok}]'); | 107 expectFormatError('authors: [ok, {not: ok}]'); |
| 92 }); | 108 }); |
| 93 | 109 |
| 94 test("throws if 'author' is not a string", () { | 110 test("throws if 'author' is not a string", () { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 test("throws if the sdk isn't a valid version constraint", () { | 168 test("throws if the sdk isn't a valid version constraint", () { |
| 153 expectFormatError(''' | 169 expectFormatError(''' |
| 154 environment: | 170 environment: |
| 155 sdk: "oopies" | 171 sdk: "oopies" |
| 156 '''); | 172 '''); |
| 157 }); | 173 }); |
| 158 }); | 174 }); |
| 159 }); | 175 }); |
| 160 }); | 176 }); |
| 161 } | 177 } |
| OLD | NEW |