| OLD | NEW |
| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'package:barback/barback.dart'; | 6 import 'package:barback/barback.dart'; |
| 7 import 'package:observe/transform.dart'; | 7 import 'package:observe/transform.dart'; |
| 8 import 'package:unittest/compact_vm_config.dart'; | 8 import 'package:unittest/compact_vm_config.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 group('fixes contructor calls ', () { | 39 group('fixes contructor calls ', () { |
| 40 _testInitializers('this.a', '(a) : __\$a = a'); | 40 _testInitializers('this.a', '(a) : __\$a = a'); |
| 41 _testInitializers('{this.a}', '({a}) : __\$a = a'); | 41 _testInitializers('{this.a}', '({a}) : __\$a = a'); |
| 42 _testInitializers('[this.a]', '([a]) : __\$a = a'); | 42 _testInitializers('[this.a]', '([a]) : __\$a = a'); |
| 43 _testInitializers('this.a, this.b', '(a, b) : __\$a = a, __\$b = b'); | 43 _testInitializers('this.a, this.b', '(a, b) : __\$a = a, __\$b = b'); |
| 44 _testInitializers('{this.a, this.b}', '({a, b}) : __\$a = a, __\$b = b'); | 44 _testInitializers('{this.a, this.b}', '({a, b}) : __\$a = a, __\$b = b'); |
| 45 _testInitializers('[this.a, this.b]', '([a, b]) : __\$a = a, __\$b = b'); | 45 _testInitializers('[this.a, this.b]', '([a, b]) : __\$a = a, __\$b = b'); |
| 46 _testInitializers('this.a, [this.b]', '(a, [b]) : __\$a = a, __\$b = b'); | 46 _testInitializers('this.a, [this.b]', '(a, [b]) : __\$a = a, __\$b = b'); |
| 47 _testInitializers('this.a, {this.b}', '(a, {b}) : __\$a = a, __\$b = b'); | 47 _testInitializers('this.a, {this.b}', '(a, {b}) : __\$a = a, __\$b = b'); |
| 48 }); | 48 }); |
| 49 |
| 50 group('test full text', () { |
| 51 test('with changes', () { |
| 52 return _transform(_sampleObservable('A', 'foo')) |
| 53 .then((output) => expect(output, _sampleObservableOutput('A', 'foo'))); |
| 54 }); |
| 55 |
| 56 test('no changes', () { |
| 57 var input = 'class A {/*@observable annotation to trigger transform */;}'; |
| 58 return _transform(input).then((output) => expect(output, input)); |
| 59 }); |
| 60 }); |
| 49 } | 61 } |
| 50 | 62 |
| 51 _testClause(String clauses, String expected) { | 63 _testClause(String clauses, String expected) { |
| 52 test(clauses, () { | 64 test(clauses, () { |
| 53 var className = 'MyClass'; | 65 var className = 'MyClass'; |
| 54 if (clauses.contains('<T>')) className += '<T>'; | 66 if (clauses.contains('<T>')) className += '<T>'; |
| 55 var code = ''' | 67 var code = ''' |
| 56 class $className $clauses { | 68 class $className $clauses { |
| 57 @observable var field; | 69 @observable var field; |
| 58 }'''; | 70 }'''; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 _MockTransform(this._asset); | 123 _MockTransform(this._asset); |
| 112 Future<Asset> getInput(Asset id) { | 124 Future<Asset> getInput(Asset id) { |
| 113 if (id == primaryInput.id) return new Future.value(primaryInput); | 125 if (id == primaryInput.id) return new Future.value(primaryInput); |
| 114 fail(); | 126 fail(); |
| 115 } | 127 } |
| 116 | 128 |
| 117 void addOutput(Asset output) { | 129 void addOutput(Asset output) { |
| 118 outs.add(output); | 130 outs.add(output); |
| 119 } | 131 } |
| 120 } | 132 } |
| 133 |
| 134 String _sampleObservable(String className, String fieldName) => ''' |
| 135 library ${className}_$fieldName; |
| 136 import 'package:observe/observe.dart'; |
| 137 |
| 138 class $className extends ObservableBase { |
| 139 @observable int $fieldName; |
| 140 $className(this.$fieldName); |
| 141 } |
| 142 '''; |
| 143 |
| 144 String _sampleObservableOutput(String className, String fieldName) => ''' |
| 145 library ${className}_$fieldName; |
| 146 import 'package:observe/observe.dart'; |
| 147 |
| 148 class $className extends ChangeNotifierBase { |
| 149 int __\$$fieldName; |
| 150 int get $fieldName => __\$$fieldName; |
| 151 set $fieldName(int value) { |
| 152 __\$$fieldName = notifyPropertyChange(const Symbol('$fieldName'), __\$$field
Name, value); |
| 153 } |
| 154 |
| 155 $className($fieldName) : __\$$fieldName = $fieldName; |
| 156 } |
| 157 '''; |
| OLD | NEW |