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

Side by Side Diff: pkg/observe/test/transform_test.dart

Issue 22396004: Make observable transform a barback transform. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: changes alone (patchset 1 has the existing code, in the new location) Created 7 years, 4 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
(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 import 'dart:async';
6 import 'package:barback/barback.dart';
7 import 'package:observe/transform.dart';
8 import 'package:unittest/compact_vm_config.dart';
9 import 'package:unittest/unittest.dart';
10
11 main() {
12 useCompactVMConfiguration();
13
14 group('fixes contructor calls ', () {
15 _testInitializers('this.a', '(a) : __\$a = a');
16 _testInitializers('{this.a}', '({a}) : __\$a = a');
17 _testInitializers('[this.a]', '([a]) : __\$a = a');
18 _testInitializers('this.a, this.b', '(a, b) : __\$a = a, __\$b = b');
19 _testInitializers('{this.a, this.b}', '({a, b}) : __\$a = a, __\$b = b');
20 _testInitializers('[this.a, this.b]', '([a, b]) : __\$a = a, __\$b = b');
21 _testInitializers('this.a, [this.b]', '(a, [b]) : __\$a = a, __\$b = b');
22 _testInitializers('this.a, {this.b}', '(a, {b}) : __\$a = a, __\$b = b');
23 });
24 }
25
26 _testInitializers(String args, String expected) {
27 test(args, () {
28 var constructor = 'MyClass(';
29 var code = '''
30 class MyClass {
31 @observable var a;
32 @observable var b;
33 MyClass($args);
34 }''';
35
36 return _transform(code).then((output) {
37 var begin = output.indexOf(constructor) + constructor.length - 1;
38 var end = output.indexOf(';', begin);
39 if (end == -1) end = output.length;
40 var init = output.substring(begin, end).trim().replaceAll(' ', ' ');
41 expect(init, expected);
42 });
43 });
44 }
45
46 /** Helper that applies the transform by creating mock assets. */
47 Future<String> _transform(String code) {
48 var id = new AssetId('foo', 'a/b/c.dart');
49 var asset = new Asset.fromString(id, code);
50 var transformer = new ObservableTransformer();
51 return transformer.isPrimary(asset).then((isPrimary) {
52 expect(isPrimary, isTrue);
53 var transform = new _MockTransform(asset);
54 return transformer.apply(transform).then((_) {
55 expect(transform.outs, hasLength(2));
56 expect(transform.outs[0].id, id);
57 expect(transform.outs[1].id.path, '${id.path}.map');
58 return transform.outs.first.readAsString();
59 });
60 });
61 }
62
63 class _MockTransform implements Transform {
64 List<Asset> outs = [];
65 Asset _asset;
66 AssetId get primaryId => _asset.id;
67 Log log = new Log(false);
68 Future<Asset> get primaryInput => new Future.value(_asset);
69
70 _MockTransform(this._asset);
71 Future<Asset> getInput(Asset id) {
72 if (id == primaryId) return primaryInput;
73 throw "unsupported";
Bob Nystrom 2013/08/08 22:47:09 Maybe fail() here since it's a test failure if thi
Siggi Cherem (dart-lang) 2013/08/08 23:10:41 Done.
74 }
75
76 void addOutput(Asset output) {
77 outs.add(output);
78 }
79 }
OLDNEW
« pkg/observe/lib/transform.dart ('K') | « pkg/observe/pubspec.yaml ('k') | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698