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 binding_syntax_test; | 5 library binding_syntax_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 'package:mdv_observe/mdv_observe.dart'; | 10 import 'package:mdv_observe/mdv_observe.dart'; |
11 import 'package:unittest/html_config.dart'; | 11 import 'package:unittest/html_config.dart'; |
12 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
13 import 'mdv_observe_utils.dart'; | 13 import 'mdv_observe_utils.dart'; |
14 | 14 |
15 // Note: this file ported from | 15 // Note: this file ported from |
16 // https://github.com/toolkitchen/mdv/blob/master/tests/syntax.js | 16 // https://github.com/toolkitchen/mdv/blob/master/tests/syntax.js |
17 | 17 |
18 main() { | 18 main() { |
19 useHtmlConfiguration(); | 19 useHtmlConfiguration(); |
20 group('Syntax', syntaxTests); | 20 group('Syntax', syntaxTests); |
21 } | 21 } |
22 | 22 |
23 syntaxTests() { | 23 syntaxTests() { |
24 var testDiv; | 24 var testDiv; |
25 | 25 |
26 setUp(() { | 26 setUp(() { |
27 document.body.nodes.add(testDiv = new DivElement()); | 27 document.body.append(testDiv = new DivElement()); |
28 }); | 28 }); |
29 | 29 |
30 tearDown(() { | 30 tearDown(() { |
31 testDiv.remove(); | 31 testDiv.remove(); |
32 testDiv = null; | 32 testDiv = null; |
33 }); | 33 }); |
34 | 34 |
35 createTestHtml(s) { | 35 createTestHtml(s) { |
36 var div = new DivElement(); | 36 var div = new DivElement(); |
37 div.innerHtml = s; | 37 div.innerHtml = s; |
38 testDiv.nodes.add(div); | 38 testDiv.append(div); |
39 | 39 |
40 for (var node in div.queryAll('*')) { | 40 for (var node in div.queryAll('*')) { |
41 if (node.isTemplate) TemplateElement.decorate(node); | 41 if (node.isTemplate) TemplateElement.decorate(node); |
42 } | 42 } |
43 | 43 |
44 return div; | 44 return div; |
45 } | 45 } |
46 | 46 |
47 recursivelySetTemplateModel(element, model) { | 47 recursivelySetTemplateModel(element, model) { |
48 for (var node in element.queryAll('*')) { | 48 for (var node in element.queryAll('*')) { |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 class TimesTwoSyntax extends CustomBindingSyntax { | 253 class TimesTwoSyntax extends CustomBindingSyntax { |
254 getBinding(model, path, name, node) { | 254 getBinding(model, path, name, node) { |
255 path = path.trim(); | 255 path = path.trim(); |
256 if (!path.startsWith('2x:')) return null; | 256 if (!path.startsWith('2x:')) return null; |
257 | 257 |
258 path = path.substring(3); | 258 path = path.substring(3); |
259 return new CompoundBinding((values) => values['value'] * 2) | 259 return new CompoundBinding((values) => values['value'] * 2) |
260 ..bind('value', model, path); | 260 ..bind('value', model, path); |
261 } | 261 } |
262 } | 262 } |
OLD | NEW |