| 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 29 matching lines...) Expand all Loading... |
| 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 | 49 |
| 50 group('test full text', () { | 50 for (var annotation in ['observable', 'published']) { |
| 51 test('with changes', () { | 51 group('@$annotation full text', () { |
| 52 return _transform(_sampleObservable('A', 'foo')) | 52 test('with changes', () { |
| 53 .then((output) => expect(output, _sampleObservableOutput('A', 'foo'))); | 53 return _transform(_sampleObservable(annotation)).then( |
| 54 (out) => expect(out, _sampleObservableOutput(annotation))); |
| 55 }); |
| 56 |
| 57 test('complex with changes', () { |
| 58 return _transform(_complexObservable(annotation)).then( |
| 59 (out) => expect(out, _complexObservableOutput(annotation))); |
| 60 }); |
| 61 |
| 62 test('no changes', () { |
| 63 var input = 'class A {/*@$annotation annotation to trigger transform */;
}'; |
| 64 return _transform(input).then((output) => expect(output, input)); |
| 65 }); |
| 54 }); | 66 }); |
| 55 | 67 } |
| 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 }); | |
| 61 } | 68 } |
| 62 | 69 |
| 63 _testClause(String clauses, String expected) { | 70 _testClause(String clauses, String expected) { |
| 64 test(clauses, () { | 71 test(clauses, () { |
| 65 var className = 'MyClass'; | 72 var className = 'MyClass'; |
| 66 if (clauses.contains('<T>')) className += '<T>'; | 73 if (clauses.contains('<T>')) className += '<T>'; |
| 67 var code = ''' | 74 var code = ''' |
| 68 class $className $clauses { | 75 class $className $clauses { |
| 69 @observable var field; | 76 @observable var field; |
| 70 }'''; | 77 }'''; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 }); | 121 }); |
| 115 } | 122 } |
| 116 | 123 |
| 117 class _MockTransform implements Transform { | 124 class _MockTransform implements Transform { |
| 118 List<Asset> outs = []; | 125 List<Asset> outs = []; |
| 119 Asset _asset; | 126 Asset _asset; |
| 120 TransformLogger logger = new TransformLogger(false); | 127 TransformLogger logger = new TransformLogger(false); |
| 121 Asset get primaryInput => _asset; | 128 Asset get primaryInput => _asset; |
| 122 | 129 |
| 123 _MockTransform(this._asset); | 130 _MockTransform(this._asset); |
| 124 Future<Asset> getInput(Asset id) { | 131 Future<Asset> getInput(AssetId id) { |
| 125 if (id == primaryInput.id) return new Future.value(primaryInput); | 132 if (id == primaryInput.id) return new Future.value(primaryInput); |
| 126 fail(); | 133 fail('_MockTransform fail'); |
| 127 } | 134 } |
| 128 | 135 |
| 129 void addOutput(Asset output) { | 136 void addOutput(Asset output) { |
| 130 outs.add(output); | 137 outs.add(output); |
| 131 } | 138 } |
| 139 |
| 140 readInput(id) => throw new UnimplementedError(); |
| 141 readInputAsString(id, {encoding}) => throw new UnimplementedError(); |
| 132 } | 142 } |
| 133 | 143 |
| 134 String _sampleObservable(String className, String fieldName) => ''' | 144 String _sampleObservable(String annotation) => ''' |
| 135 library ${className}_$fieldName; | 145 library A_foo; |
| 136 import 'package:observe/observe.dart'; | 146 import 'package:observe/observe.dart'; |
| 137 | 147 |
| 138 class $className extends ObservableBase { | 148 class A extends ObservableBase { |
| 139 @observable int $fieldName; | 149 @$annotation int foo; |
| 140 $className(this.$fieldName); | 150 A(this.foo); |
| 141 } | 151 } |
| 142 '''; | 152 '''; |
| 143 | 153 |
| 144 String _sampleObservableOutput(String className, String fieldName) => ''' | 154 String _sampleObservableOutput(String annotation) => |
| 145 library ${className}_$fieldName; | 155 "library A_foo;\n" |
| 146 import 'package:observe/observe.dart'; | 156 "import 'package:observe/observe.dart';\n\n" |
| 157 "class A extends ChangeNotifierBase {\n" |
| 158 " @$annotation int get foo => __\$foo; int __\$foo; " |
| 159 "${_makeSetter('int', 'foo')}\n" |
| 160 " A(foo) : __\$foo = foo;\n" |
| 161 "}\n"; |
| 147 | 162 |
| 148 class $className extends ChangeNotifierBase { | 163 _makeSetter(type, name) => 'set $name($type value) { ' |
| 149 int __\$$fieldName; | 164 '__\$$name = notifyPropertyChange(#$name, __\$$name, value); }'; |
| 150 int get $fieldName => __\$$fieldName; | 165 |
| 151 set $fieldName(int value) { | 166 String _complexObservable(String annotation) => ''' |
| 152 __\$$fieldName = notifyPropertyChange(const Symbol('$fieldName'), __\$$field
Name, value); | 167 class Foo extends ObservableBase { |
| 153 } | 168 @$annotation |
| 154 | 169 @otherMetadata |
| 155 $className($fieldName) : __\$$fieldName = $fieldName; | 170 Foo |
| 171 foo/*D*/= 1, bar =/*A*/2/*B*/, |
| 172 quux/*C*/; |
| 173 |
| 174 @$annotation var baz; |
| 156 } | 175 } |
| 157 '''; | 176 '''; |
| 177 |
| 178 String _complexObservableOutput(String annotation) => |
| 179 "class Foo extends ChangeNotifierBase {\n" |
| 180 " @$annotation\n" |
| 181 " @otherMetadata\n" |
| 182 " Foo\n" |
| 183 " get foo => __\$foo; Foo __\$foo/*D*/= 1; " |
| 184 "${_makeSetter('Foo', 'foo')} " |
| 185 "@$annotation @otherMetadata Foo get bar => __\$bar; " |
| 186 "Foo __\$bar =/*A*/2/*B*/; ${_makeSetter('Foo', 'bar')}\n" |
| 187 " @$annotation @otherMetadata Foo get quux => __\$quux; " |
| 188 "Foo __\$quux/*C*/; ${_makeSetter('Foo', 'quux')}\n\n" |
| 189 " @$annotation dynamic get baz => __\$baz; dynamic __\$baz; " |
| 190 "${_makeSetter('dynamic', 'baz')}\n" |
| 191 "}\n"; |
| OLD | NEW |