OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 barback.test.transformer_test; | 5 library barback.test.transformer_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import 'package:barback/src/utils.dart'; | |
11 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
12 | 11 |
13 import 'utils.dart'; | 12 import 'utils.dart'; |
14 | 13 |
15 main() { | 14 main() { |
16 initConfig(); | 15 initConfig(); |
17 | 16 |
18 group("isPrimary", () { | 17 group("isPrimary", () { |
19 test("defaults to allowedExtensions", () { | 18 test("defaults to allowedExtensions", () { |
20 var transformer = new ExtensionTransformer(".txt .bin"); | 19 var transformer = new ExtensionTransformer(".txt .bin"); |
21 expect(transformer.isPrimary(new AssetId("pkg", "foo.txt")), isTrue); | 20 expect(transformer.isPrimary(new AssetId("pkg", "foo.txt")), |
| 21 completion(isTrue)); |
22 | 22 |
23 expect(transformer.isPrimary(new AssetId("pkg", "foo.bin")), isTrue); | 23 expect(transformer.isPrimary(new AssetId("pkg", "foo.bin")), |
| 24 completion(isTrue)); |
24 | 25 |
25 expect(transformer.isPrimary(new AssetId("pkg", "foo.nottxt")), isFalse); | 26 expect(transformer.isPrimary(new AssetId("pkg", "foo.nottxt")), |
| 27 completion(isFalse)); |
26 }); | 28 }); |
27 | 29 |
28 test("supports multi-level extensions with allowedExtensions", () { | 30 test("supports multi-level extensions with allowedExtensions", () { |
29 var transformer = new ExtensionTransformer(".dart.js"); | 31 var transformer = new ExtensionTransformer(".dart.js"); |
30 expect(transformer.isPrimary(new AssetId("pkg", "foo.dart.js")), isTrue); | 32 expect(transformer.isPrimary(new AssetId("pkg", "foo.dart.js")), |
| 33 completion(isTrue)); |
31 | 34 |
32 expect(transformer.isPrimary(new AssetId("pkg", "foo.js")), isFalse); | 35 expect(transformer.isPrimary(new AssetId("pkg", "foo.js")), |
33 | 36 completion(isFalse)); |
34 expect(transformer.isPrimary(new AssetId("pkg", "foo.dart")), isFalse); | 37 expect(transformer.isPrimary(new AssetId("pkg", "foo.dart")), |
| 38 completion(isFalse)); |
35 }); | 39 }); |
36 | 40 |
37 test("throws an error for extensions without periods", () { | 41 test("throws an error for extensions without periods", () { |
38 expect(() => new ExtensionTransformer("dart"), throwsFormatException); | 42 expect(() => new ExtensionTransformer("dart"), throwsFormatException); |
39 }); | 43 }); |
40 | 44 |
41 test("allows all files if allowedExtensions is not overridden", () { | 45 test("allows all files if allowedExtensions is not overridden", () { |
42 var transformer = new MockTransformer(); | 46 var transformer = new MockTransformer(); |
43 expect(transformer.isPrimary(new AssetId("pkg", "foo.txt")), isTrue); | 47 expect(transformer.isPrimary(new AssetId("pkg", "foo.txt")), |
| 48 completion(isTrue)); |
44 | 49 |
45 expect(transformer.isPrimary(new AssetId("pkg", "foo.bin")), isTrue); | 50 expect(transformer.isPrimary(new AssetId("pkg", "foo.bin")), |
| 51 completion(isTrue)); |
46 | 52 |
47 expect(transformer.isPrimary(new AssetId("pkg", "anything")), isTrue); | 53 expect(transformer.isPrimary(new AssetId("pkg", "anything")), |
| 54 completion(isTrue)); |
48 }); | 55 }); |
49 }); | 56 }); |
50 } | 57 } |
51 | 58 |
52 class MockTransformer extends Transformer { | 59 class MockTransformer extends Transformer { |
53 MockTransformer(); | 60 MockTransformer(); |
54 | 61 |
55 Future apply(Transform transform) => new Future.value(); | 62 Future apply(Transform transform) => new Future.value(); |
56 } | 63 } |
57 | 64 |
58 class ExtensionTransformer extends Transformer { | 65 class ExtensionTransformer extends Transformer { |
59 final String allowedExtensions; | 66 final String allowedExtensions; |
60 | 67 |
61 ExtensionTransformer(this.allowedExtensions); | 68 ExtensionTransformer(this.allowedExtensions); |
62 | 69 |
63 Future apply(Transform transform) => new Future.value(); | 70 Future apply(Transform transform) => new Future.value(); |
64 } | 71 } |
OLD | NEW |