Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: pkg/barback/test/transformer_test.dart

Issue 243793005: Don't require Transformer methods to return Futures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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");
Bob Nystrom 2014/04/21 22:32:23 Why not just make these sync?
nweiz 2014/04/21 22:46:24 Done.
20 expect(transformer.isPrimary(new AssetId("pkg", "foo.txt")), 21 expect(syncFuture(() =>
22 transformer.isPrimary(new AssetId("pkg", "foo.txt"))),
21 completion(isTrue)); 23 completion(isTrue));
22 24
23 expect(transformer.isPrimary(new AssetId("pkg", "foo.bin")), 25 expect(syncFuture(() =>
26 transformer.isPrimary(new AssetId("pkg", "foo.bin"))),
24 completion(isTrue)); 27 completion(isTrue));
25 28
26 expect(transformer.isPrimary(new AssetId("pkg", "foo.nottxt")), 29 expect(syncFuture(() =>
30 transformer.isPrimary(new AssetId("pkg", "foo.nottxt"))),
27 completion(isFalse)); 31 completion(isFalse));
28 }); 32 });
29 33
30 test("supports multi-level extensions with allowedExtensions", () { 34 test("supports multi-level extensions with allowedExtensions", () {
31 var transformer = new ExtensionTransformer(".dart.js"); 35 var transformer = new ExtensionTransformer(".dart.js");
32 expect(transformer.isPrimary(new AssetId("pkg", "foo.dart.js")), 36 expect(syncFuture(() =>
37 transformer.isPrimary(new AssetId("pkg", "foo.dart.js"))),
33 completion(isTrue)); 38 completion(isTrue));
34 39
35 expect(transformer.isPrimary(new AssetId("pkg", "foo.js")), 40 expect(syncFuture(() =>
41 transformer.isPrimary(new AssetId("pkg", "foo.js"))),
36 completion(isFalse)); 42 completion(isFalse));
37 expect(transformer.isPrimary(new AssetId("pkg", "foo.dart")), 43
44 expect(syncFuture(() =>
45 transformer.isPrimary(new AssetId("pkg", "foo.dart"))),
38 completion(isFalse)); 46 completion(isFalse));
39 }); 47 });
40 48
41 test("throws an error for extensions without periods", () { 49 test("throws an error for extensions without periods", () {
42 expect(() => new ExtensionTransformer("dart"), throwsFormatException); 50 expect(() => new ExtensionTransformer("dart"), throwsFormatException);
43 }); 51 });
44 52
45 test("allows all files if allowedExtensions is not overridden", () { 53 test("allows all files if allowedExtensions is not overridden", () {
46 var transformer = new MockTransformer(); 54 var transformer = new MockTransformer();
47 expect(transformer.isPrimary(new AssetId("pkg", "foo.txt")), 55 expect(syncFuture(() =>
56 transformer.isPrimary(new AssetId("pkg", "foo.txt"))),
48 completion(isTrue)); 57 completion(isTrue));
49 58
50 expect(transformer.isPrimary(new AssetId("pkg", "foo.bin")), 59 expect(syncFuture(() =>
60 transformer.isPrimary(new AssetId("pkg", "foo.bin"))),
51 completion(isTrue)); 61 completion(isTrue));
52 62
53 expect(transformer.isPrimary(new AssetId("pkg", "anything")), 63 expect(syncFuture(() =>
64 transformer.isPrimary(new AssetId("pkg", "anything"))),
54 completion(isTrue)); 65 completion(isTrue));
55 }); 66 });
56 }); 67 });
57 } 68 }
58 69
59 class MockTransformer extends Transformer { 70 class MockTransformer extends Transformer {
60 MockTransformer(); 71 MockTransformer();
61 72
62 Future apply(Transform transform) => new Future.value(); 73 Future apply(Transform transform) => new Future.value();
63 } 74 }
64 75
65 class ExtensionTransformer extends Transformer { 76 class ExtensionTransformer extends Transformer {
66 final String allowedExtensions; 77 final String allowedExtensions;
67 78
68 ExtensionTransformer(this.allowedExtensions); 79 ExtensionTransformer(this.allowedExtensions);
69 80
70 Future apply(Transform transform) => new Future.value(); 81 Future apply(Transform transform) => new Future.value();
71 } 82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698