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

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: 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 ', () {
Jennifer Messerly 2013/08/09 05:44:03 idea: revive the test that checks we inserted the
Siggi Cherem (dart-lang) 2013/08/09 22:09:09 Done.
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(1));
56 expect(transform.outs[0].id, id);
57 return transform.outs.first.readAsString();
58 });
59 });
60 }
61
62 class _MockTransform implements Transform {
63 List<Asset> outs = [];
64 Asset _asset;
65 AssetId get primaryId => _asset.id;
66 TransformLogger logger = new TransformLogger(false);
67 Future<Asset> get primaryInput => new Future.value(_asset);
68
69 _MockTransform(this._asset);
70 Future<Asset> getInput(Asset id) {
71 if (id == primaryId) return primaryInput;
72 fail();
73 }
74
75 void addOutput(Asset output) {
76 outs.add(output);
77 }
78 }
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