| 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 |
| 11 main() { | 11 main() { |
| 12 useCompactVMConfiguration(); | 12 useCompactVMConfiguration(); |
| 13 | 13 |
| 14 group('replaces Observable for ChangeNotifier', () { | 14 group('replaces Observable for ChangeNotifier', () { |
| 15 _testClause('extends ObservableBase', 'extends ChangeNotifierBase'); | 15 _testClause('extends Observable', 'extends ChangeNotifier'); |
| 16 _testClause('extends Base with ObservableMixin', | 16 _testClause('extends Base with Observable', |
| 17 'extends Base with ChangeNotifierMixin'); | 17 'extends Base with ChangeNotifier'); |
| 18 _testClause('extends Base<T> with ObservableMixin', | 18 _testClause('extends Base<T> with Observable', |
| 19 'extends Base<T> with ChangeNotifierMixin'); | 19 'extends Base<T> with ChangeNotifier'); |
| 20 _testClause('extends Base with Mixin, ObservableMixin', | 20 _testClause('extends Base with Mixin, Observable', |
| 21 'extends Base with Mixin, ChangeNotifierMixin'); | 21 'extends Base with Mixin, ChangeNotifier'); |
| 22 _testClause('extends Base with ObservableMixin, Mixin', | 22 _testClause('extends Base with Observable, Mixin', |
| 23 'extends Base with ChangeNotifierMixin, Mixin'); | 23 'extends Base with ChangeNotifier, Mixin'); |
| 24 _testClause('extends Base with Mixin<T>, ObservableMixin', | 24 _testClause('extends Base with Mixin<T>, Observable', |
| 25 'extends Base with Mixin<T>, ChangeNotifierMixin'); | 25 'extends Base with Mixin<T>, ChangeNotifier'); |
| 26 _testClause('extends Base with Mixin, ObservableMixin, Mixin2', | 26 _testClause('extends Base with Mixin, Observable, Mixin2', |
| 27 'extends Base with Mixin, ChangeNotifierMixin, Mixin2'); | 27 'extends Base with Mixin, ChangeNotifier, Mixin2'); |
| 28 _testClause('extends ObservableBase implements Interface', | 28 _testClause('extends Observable implements Interface', |
| 29 'extends ChangeNotifierBase implements Interface'); | 29 'extends ChangeNotifier implements Interface'); |
| 30 _testClause('extends ObservableBase implements Interface<T>', | 30 _testClause('extends Observable implements Interface<T>', |
| 31 'extends ChangeNotifierBase implements Interface<T>'); | 31 'extends ChangeNotifier implements Interface<T>'); |
| 32 _testClause('extends Base with ObservableMixin implements Interface', | 32 _testClause('extends Base with Observable implements Interface', |
| 33 'extends Base with ChangeNotifierMixin implements Interface'); | 33 'extends Base with ChangeNotifier implements Interface'); |
| 34 _testClause( | 34 _testClause( |
| 35 'extends Base with Mixin, ObservableMixin implements I1, I2', | 35 'extends Base with Mixin, Observable implements I1, I2', |
| 36 'extends Base with Mixin, ChangeNotifierMixin implements I1, I2'); | 36 'extends Base with Mixin, ChangeNotifier implements I1, I2'); |
| 37 }); | 37 }); |
| 38 | 38 |
| 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'); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 static void _mockLogFn(AssetId asset, LogLevel level, String message, | 143 static void _mockLogFn(AssetId asset, LogLevel level, String message, |
| 144 Span span) { | 144 Span span) { |
| 145 // Do nothing. | 145 // Do nothing. |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 String _sampleObservable(String annotation) => ''' | 149 String _sampleObservable(String annotation) => ''' |
| 150 library A_foo; | 150 library A_foo; |
| 151 import 'package:observe/observe.dart'; | 151 import 'package:observe/observe.dart'; |
| 152 | 152 |
| 153 class A extends ObservableBase { | 153 class A extends Observable { |
| 154 @$annotation int foo; | 154 @$annotation int foo; |
| 155 A(this.foo); | 155 A(this.foo); |
| 156 } | 156 } |
| 157 '''; | 157 '''; |
| 158 | 158 |
| 159 String _sampleObservableOutput(String annotation) => | 159 String _sampleObservableOutput(String annotation) => |
| 160 "library A_foo;\n" | 160 "library A_foo;\n" |
| 161 "import 'package:observe/observe.dart';\n\n" | 161 "import 'package:observe/observe.dart';\n\n" |
| 162 "class A extends ChangeNotifierBase {\n" | 162 "class A extends ChangeNotifier {\n" |
| 163 " @reflectable @$annotation int get foo => __\$foo; int __\$foo; " | 163 " @reflectable @$annotation int get foo => __\$foo; int __\$foo; " |
| 164 "${_makeSetter('int', 'foo')}\n" | 164 "${_makeSetter('int', 'foo')}\n" |
| 165 " A(foo) : __\$foo = foo;\n" | 165 " A(foo) : __\$foo = foo;\n" |
| 166 "}\n"; | 166 "}\n"; |
| 167 | 167 |
| 168 _makeSetter(type, name) => '@reflectable set $name($type value) { ' | 168 _makeSetter(type, name) => '@reflectable set $name($type value) { ' |
| 169 '__\$$name = notifyPropertyChange(#$name, __\$$name, value); }'; | 169 '__\$$name = notifyPropertyChange(#$name, __\$$name, value); }'; |
| 170 | 170 |
| 171 String _complexObservable(String annotation) => ''' | 171 String _complexObservable(String annotation) => ''' |
| 172 class Foo extends ObservableBase { | 172 class Foo extends Observable { |
| 173 @$annotation | 173 @$annotation |
| 174 @otherMetadata | 174 @otherMetadata |
| 175 Foo | 175 Foo |
| 176 foo/*D*/= 1, bar =/*A*/2/*B*/, | 176 foo/*D*/= 1, bar =/*A*/2/*B*/, |
| 177 quux/*C*/; | 177 quux/*C*/; |
| 178 | 178 |
| 179 @$annotation var baz; | 179 @$annotation var baz; |
| 180 } | 180 } |
| 181 '''; | 181 '''; |
| 182 | 182 |
| 183 String _complexObservableOutput(String meta) => | 183 String _complexObservableOutput(String meta) => |
| 184 "class Foo extends ChangeNotifierBase {\n" | 184 "class Foo extends ChangeNotifier {\n" |
| 185 " @reflectable @$meta\n" | 185 " @reflectable @$meta\n" |
| 186 " @otherMetadata\n" | 186 " @otherMetadata\n" |
| 187 " Foo\n" | 187 " Foo\n" |
| 188 " get foo => __\$foo; Foo __\$foo/*D*/= 1; " | 188 " get foo => __\$foo; Foo __\$foo/*D*/= 1; " |
| 189 "${_makeSetter('Foo', 'foo')} " | 189 "${_makeSetter('Foo', 'foo')} " |
| 190 "@reflectable @$meta @otherMetadata Foo get bar => __\$bar; " | 190 "@reflectable @$meta @otherMetadata Foo get bar => __\$bar; " |
| 191 "Foo __\$bar =/*A*/2/*B*/; ${_makeSetter('Foo', 'bar')}\n" | 191 "Foo __\$bar =/*A*/2/*B*/; ${_makeSetter('Foo', 'bar')}\n" |
| 192 " @reflectable @$meta @otherMetadata Foo get quux => __\$quux; " | 192 " @reflectable @$meta @otherMetadata Foo get quux => __\$quux; " |
| 193 "Foo __\$quux/*C*/; ${_makeSetter('Foo', 'quux')}\n\n" | 193 "Foo __\$quux/*C*/; ${_makeSetter('Foo', 'quux')}\n\n" |
| 194 " @reflectable @$meta dynamic get baz => __\$baz; dynamic __\$baz; " | 194 " @reflectable @$meta dynamic get baz => __\$baz; dynamic __\$baz; " |
| 195 "${_makeSetter('dynamic', 'baz')}\n" | 195 "${_makeSetter('dynamic', 'baz')}\n" |
| 196 "}\n"; | 196 "}\n"; |
| OLD | NEW |