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