OLD | NEW |
(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 library polymer.test.transform.script_compactor_test; |
| 6 |
| 7 import 'package:polymer/src/transform.dart'; |
| 8 import 'package:unittest/compact_vm_config.dart'; |
| 9 |
| 10 import 'common.dart'; |
| 11 |
| 12 void main() { |
| 13 useCompactVMConfiguration(); |
| 14 |
| 15 testPhases('no changes', phases, { |
| 16 'a|web/test.html': '<!DOCTYPE html><html></html>', |
| 17 }, { |
| 18 'a|web/test.html': '<!DOCTYPE html><html></html>', |
| 19 }); |
| 20 |
| 21 testPhases('observable changes', phases, { |
| 22 'a|web/test.dart': _sampleObservable('A', 'foo'), |
| 23 'a|web/test2.dart': _sampleObservableOutput('B', 'bar'), |
| 24 }, { |
| 25 'a|web/test.dart': _sampleObservableOutput('A', 'foo'), |
| 26 'a|web/test2.dart': _sampleObservableOutput('B', 'bar'), |
| 27 }); |
| 28 |
| 29 testPhases('single script', phases, { |
| 30 'a|web/test.html': |
| 31 '<!DOCTYPE html><html><head>' |
| 32 '<script type="application/dart" src="a.dart"></script>', |
| 33 'a|web/test.dart': _sampleObservable('A', 'foo'), |
| 34 }, { |
| 35 'a|web/test.html': |
| 36 '<!DOCTYPE html><html><head></head><body>' |
| 37 '<script type="application/dart" ' |
| 38 'src="test.html_bootstrap.dart"></script>' |
| 39 '<script type="text/javascript" ' |
| 40 'src="packages/browser/dart.js"></script>' |
| 41 '</body></html>', |
| 42 |
| 43 'a|web/test.html_bootstrap.dart': |
| 44 '''library app_bootstrap; |
| 45 |
| 46 import 'package:polymer/polymer.dart'; |
| 47 import 'dart:mirrors' show currentMirrorSystem; |
| 48 |
| 49 import 'a.dart' as i0; |
| 50 |
| 51 void main() { |
| 52 initPolymer([ |
| 53 'a.dart', |
| 54 ], currentMirrorSystem().isolate.rootLibrary.uri.toString()); |
| 55 } |
| 56 '''.replaceAll('\n ', '\n'), |
| 57 'a|web/test.dart': _sampleObservableOutput('A', 'foo'), |
| 58 }); |
| 59 |
| 60 testPhases('single inline script', phases, { |
| 61 'a|web/test.html': |
| 62 '<!DOCTYPE html><html><head>' |
| 63 '<script type="application/dart">' |
| 64 '${_sampleObservable("B", "bar")}</script>', |
| 65 }, { |
| 66 'a|web/test.html': |
| 67 '<!DOCTYPE html><html><head></head><body>' |
| 68 '<script type="application/dart" ' |
| 69 'src="test.html_bootstrap.dart"></script>' |
| 70 '<script type="text/javascript" ' |
| 71 'src="packages/browser/dart.js"></script>' |
| 72 '</body></html>', |
| 73 |
| 74 'a|web/test.html_bootstrap.dart': |
| 75 '''library app_bootstrap; |
| 76 |
| 77 import 'package:polymer/polymer.dart'; |
| 78 import 'dart:mirrors' show currentMirrorSystem; |
| 79 |
| 80 import 'test.html.0.dart' as i0; |
| 81 |
| 82 void main() { |
| 83 initPolymer([ |
| 84 'test.html.0.dart', |
| 85 ], currentMirrorSystem().isolate.rootLibrary.uri.toString()); |
| 86 } |
| 87 '''.replaceAll('\n ', '\n'), |
| 88 'a|web/test.html.0.dart': _sampleObservableOutput("B", "bar"), |
| 89 }); |
| 90 |
| 91 testPhases('several scripts', phases, { |
| 92 'a|web/test.html': |
| 93 '<!DOCTYPE html><html><head>' |
| 94 '<script type="application/dart" src="a.dart"></script>' |
| 95 '<script type="application/dart">' |
| 96 '${_sampleObservable("B", "bar")}</script>' |
| 97 '</head><body><div>' |
| 98 '<script type="application/dart">' |
| 99 '${_sampleObservable("C", "car")}</script>' |
| 100 '</div>' |
| 101 '<script type="application/dart" src="d.dart"></script>', |
| 102 'a|web/a.dart': _sampleObservable('A', 'foo'), |
| 103 }, { |
| 104 'a|web/test.html': |
| 105 '<!DOCTYPE html><html><head></head><body><div></div>' |
| 106 '<script type="application/dart" ' |
| 107 'src="test.html_bootstrap.dart"></script>' |
| 108 '<script type="text/javascript" ' |
| 109 'src="packages/browser/dart.js"></script>' |
| 110 '</body></html>', |
| 111 |
| 112 'a|web/test.html_bootstrap.dart': |
| 113 '''library app_bootstrap; |
| 114 |
| 115 import 'package:polymer/polymer.dart'; |
| 116 import 'dart:mirrors' show currentMirrorSystem; |
| 117 |
| 118 import 'a.dart' as i0; |
| 119 import 'test.html.0.dart' as i1; |
| 120 import 'test.html.1.dart' as i2; |
| 121 import 'd.dart' as i3; |
| 122 |
| 123 void main() { |
| 124 initPolymer([ |
| 125 'a.dart', |
| 126 'test.html.0.dart', |
| 127 'test.html.1.dart', |
| 128 'd.dart', |
| 129 ], currentMirrorSystem().isolate.rootLibrary.uri.toString()); |
| 130 } |
| 131 '''.replaceAll('\n ', '\n'), |
| 132 'a|web/a.dart': _sampleObservableOutput('A', 'foo'), |
| 133 'a|web/test.html.0.dart': _sampleObservableOutput("B", "bar"), |
| 134 'a|web/test.html.1.dart': _sampleObservableOutput("C", "car"), |
| 135 }); |
| 136 |
| 137 testPhases('with imports', phases, { |
| 138 'a|web/index.html': |
| 139 '<!DOCTYPE html><html><head>' |
| 140 '<link rel="import" href="test2.html">' |
| 141 '</head><body>' |
| 142 '<script type="application/dart" src="b.dart"></script>' |
| 143 '<script type="application/dart">' |
| 144 '${_sampleObservable("C", "car")}</script>', |
| 145 'a|web/b.dart': _sampleObservable('B', 'bar'), |
| 146 'a|web/test2.html': |
| 147 '<!DOCTYPE html><html><head>' |
| 148 '</head><body><polymer-element>1' |
| 149 '<script type="application/dart">' |
| 150 '${_sampleObservable("A", "foo")}</script>' |
| 151 '</polymer-element></html>', |
| 152 }, { |
| 153 'a|web/index.html': |
| 154 '<!DOCTYPE html><html><head></head><body>' |
| 155 '<polymer-element>1</polymer-element>' |
| 156 '<script type="application/dart" ' |
| 157 'src="index.html_bootstrap.dart"></script>' |
| 158 '<script type="text/javascript" ' |
| 159 'src="packages/browser/dart.js"></script>' |
| 160 '</body></html>', |
| 161 'a|web/index.html_bootstrap.dart': |
| 162 '''library app_bootstrap; |
| 163 |
| 164 import 'package:polymer/polymer.dart'; |
| 165 import 'dart:mirrors' show currentMirrorSystem; |
| 166 |
| 167 import 'test2.html.0.dart' as i0; |
| 168 import 'b.dart' as i1; |
| 169 import 'index.html.0.dart' as i2; |
| 170 |
| 171 void main() { |
| 172 initPolymer([ |
| 173 'test2.html.0.dart', |
| 174 'b.dart', |
| 175 'index.html.0.dart', |
| 176 ], currentMirrorSystem().isolate.rootLibrary.uri.toString()); |
| 177 } |
| 178 '''.replaceAll('\n ', '\n'), |
| 179 'a|web/test2.html.0.dart': _sampleObservableOutput("A", "foo"), |
| 180 'a|web/b.dart': _sampleObservableOutput('B', 'bar'), |
| 181 'a|web/index.html.0.dart': _sampleObservableOutput("C", "car"), |
| 182 }); |
| 183 } |
| 184 |
| 185 String _sampleObservable(String className, String fieldName) => ''' |
| 186 import 'package:observe/observe.dart'; |
| 187 |
| 188 class $className extends ObservableBase { |
| 189 @observable int $fieldName; |
| 190 $className(this.$fieldName); |
| 191 } |
| 192 '''; |
| 193 |
| 194 String _sampleObservableOutput(String className, String fieldName) => ''' |
| 195 import 'package:observe/observe.dart'; |
| 196 |
| 197 class $className extends ChangeNotifierBase { |
| 198 int __\$$fieldName; |
| 199 int get $fieldName => __\$$fieldName; |
| 200 set $fieldName(int value) { |
| 201 __\$$fieldName = notifyPropertyChange(const Symbol('$fieldName'), __\$$field
Name, value); |
| 202 } |
| 203 |
| 204 $className($fieldName) : __\$$fieldName = $fieldName; |
| 205 } |
| 206 '''; |
OLD | NEW |