| 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 library template_element_test; | 5 library template_element_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:html'; | 9 import 'dart:html'; |
| 10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 performMicrotaskCheckpoint(); | 139 performMicrotaskCheckpoint(); |
| 140 expect(div.nodes.length, 1); | 140 expect(div.nodes.length, 1); |
| 141 | 141 |
| 142 m[sym('bar')] = 1; | 142 m[sym('bar')] = 1; |
| 143 performMicrotaskCheckpoint(); | 143 performMicrotaskCheckpoint(); |
| 144 expect(div.nodes.length, 2); | 144 expect(div.nodes.length, 2); |
| 145 expect(div.lastChild.text, 'baz'); | 145 expect(div.lastChild.text, 'baz'); |
| 146 }); | 146 }); |
| 147 | 147 |
| 148 observeTest('Template If', () { | 148 observeTest('Template If', () { |
| 149 var div = createTestHtml('<template if="{{ foo }}">text</template>'); | 149 var div = createTestHtml('<template if="{{ foo }}">{{ value }}</template>'); |
| 150 // Note: changed this value from 0->null because zero is not falsey in Dart. | 150 // Note: changed this value from 0->null because zero is not falsey in Dart. |
| 151 // See https://code.google.com/p/dart/issues/detail?id=11956 | 151 // See https://code.google.com/p/dart/issues/detail?id=11956 |
| 152 var m = toSymbolMap({ 'foo': null }); | 152 var m = toSymbolMap({ 'foo': null, 'value': 'foo' }); |
| 153 recursivelySetTemplateModel(div, m); | 153 recursivelySetTemplateModel(div, m); |
| 154 performMicrotaskCheckpoint(); | 154 performMicrotaskCheckpoint(); |
| 155 expect(div.nodes.length, 1); | 155 expect(div.nodes.length, 1); |
| 156 | 156 |
| 157 m[sym('foo')] = 1; | 157 m[sym('foo')] = 1; |
| 158 performMicrotaskCheckpoint(); | 158 performMicrotaskCheckpoint(); |
| 159 expect(div.nodes.length, 2); | 159 expect(div.nodes.length, 2); |
| 160 expect(div.lastChild.text, 'text'); | 160 expect(div.lastChild.text, 'foo'); |
| 161 }); |
| 162 |
| 163 observeTest('Template Repeat If', () { |
| 164 var div = createTestHtml( |
| 165 '<template repeat="{{ foo }}" if="{{ bar }}">{{ }}</template>'); |
| 166 // Note: changed this value from 0->null because zero is not falsey in Dart. |
| 167 // See https://code.google.com/p/dart/issues/detail?id=11956 |
| 168 var m = toSymbolMap({ 'bar': null, 'foo': [1, 2, 3] }); |
| 169 recursivelySetTemplateModel(div, m); |
| 170 performMicrotaskCheckpoint(); |
| 171 expect(div.nodes.length, 1); |
| 172 |
| 173 m[sym('bar')] = 1; |
| 174 performMicrotaskCheckpoint(); |
| 175 expect(div.nodes.length, 4); |
| 176 expect(div.nodes[1].text, '1'); |
| 177 expect(div.nodes[2].text, '2'); |
| 178 expect(div.nodes[3].text, '3'); |
| 161 }); | 179 }); |
| 162 | 180 |
| 163 observeTest('TextTemplateWithNullStringBinding', () { | 181 observeTest('TextTemplateWithNullStringBinding', () { |
| 164 var div = createTestHtml('<template bind={{}}>a{{b}}c</template>'); | 182 var div = createTestHtml('<template bind={{}}>a{{b}}c</template>'); |
| 165 var model = toSymbolMap({'b': 'B'}); | 183 var model = toSymbolMap({'b': 'B'}); |
| 166 recursivelySetTemplateModel(div, model); | 184 recursivelySetTemplateModel(div, model); |
| 167 | 185 |
| 168 deliverChanges(model); | 186 deliverChanges(model); |
| 169 expect(div.nodes.length, 2); | 187 expect(div.nodes.length, 2); |
| 170 expect(div.nodes.last.text, 'aBc'); | 188 expect(div.nodes.last.text, 'aBc'); |
| (...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1754 k = k is String ? sym(k) : _deepToSymbol(k); | 1772 k = k is String ? sym(k) : _deepToSymbol(k); |
| 1755 result[k] = _deepToSymbol(v); | 1773 result[k] = _deepToSymbol(v); |
| 1756 }); | 1774 }); |
| 1757 return result; | 1775 return result; |
| 1758 } | 1776 } |
| 1759 if (value is Iterable) { | 1777 if (value is Iterable) { |
| 1760 return value.map(_deepToSymbol).toList(); | 1778 return value.map(_deepToSymbol).toList(); |
| 1761 } | 1779 } |
| 1762 return value; | 1780 return value; |
| 1763 } | 1781 } |
| OLD | NEW |