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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/observe/test/transform_test.dart
diff --git a/pkg/observe/test/transform_test.dart b/pkg/observe/test/transform_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9f12c2b8252a9afb4848d9733cc717a75739dab0
--- /dev/null
+++ b/pkg/observe/test/transform_test.dart
@@ -0,0 +1,78 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'package:barback/barback.dart';
+import 'package:observe/transform.dart';
+import 'package:unittest/compact_vm_config.dart';
+import 'package:unittest/unittest.dart';
+
+main() {
+ useCompactVMConfiguration();
+
+ 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.
+ _testInitializers('this.a', '(a) : __\$a = a');
+ _testInitializers('{this.a}', '({a}) : __\$a = a');
+ _testInitializers('[this.a]', '([a]) : __\$a = a');
+ _testInitializers('this.a, this.b', '(a, b) : __\$a = a, __\$b = b');
+ _testInitializers('{this.a, this.b}', '({a, b}) : __\$a = a, __\$b = b');
+ _testInitializers('[this.a, this.b]', '([a, b]) : __\$a = a, __\$b = b');
+ _testInitializers('this.a, [this.b]', '(a, [b]) : __\$a = a, __\$b = b');
+ _testInitializers('this.a, {this.b}', '(a, {b}) : __\$a = a, __\$b = b');
+ });
+}
+
+_testInitializers(String args, String expected) {
+ test(args, () {
+ var constructor = 'MyClass(';
+ var code = '''
+ class MyClass {
+ @observable var a;
+ @observable var b;
+ MyClass($args);
+ }''';
+
+ return _transform(code).then((output) {
+ var begin = output.indexOf(constructor) + constructor.length - 1;
+ var end = output.indexOf(';', begin);
+ if (end == -1) end = output.length;
+ var init = output.substring(begin, end).trim().replaceAll(' ', ' ');
+ expect(init, expected);
+ });
+ });
+}
+
+/** Helper that applies the transform by creating mock assets. */
+Future<String> _transform(String code) {
+ var id = new AssetId('foo', 'a/b/c.dart');
+ var asset = new Asset.fromString(id, code);
+ var transformer = new ObservableTransformer();
+ return transformer.isPrimary(asset).then((isPrimary) {
+ expect(isPrimary, isTrue);
+ var transform = new _MockTransform(asset);
+ return transformer.apply(transform).then((_) {
+ expect(transform.outs, hasLength(1));
+ expect(transform.outs[0].id, id);
+ return transform.outs.first.readAsString();
+ });
+ });
+}
+
+class _MockTransform implements Transform {
+ List<Asset> outs = [];
+ Asset _asset;
+ AssetId get primaryId => _asset.id;
+ TransformLogger logger = new TransformLogger(false);
+ Future<Asset> get primaryInput => new Future.value(_asset);
+
+ _MockTransform(this._asset);
+ Future<Asset> getInput(Asset id) {
+ if (id == primaryId) return primaryInput;
+ fail();
+ }
+
+ void addOutput(Asset output) {
+ outs.add(output);
+ }
+}
« 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