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