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