Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: pkg/mdv/test/binding_syntax_test.dart

Issue 18162004: [package:mdv] port createInstance change (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix copyright line Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/mdv.dart' as mdv; 10 import 'package:mdv/mdv.dart' as mdv;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 [template, model[0]], 108 [template, model[0]],
109 [template, model[1]], 109 [template, model[1]],
110 [template, model[2]], 110 [template, model[2]],
111 ]); 111 ]);
112 112
113 } finally { 113 } finally {
114 TemplateElement.syntax.remove('Test'); 114 TemplateElement.syntax.remove('Test');
115 } 115 }
116 }); 116 });
117 117
118 // Note: this test was original, not a port of an existing test.
119 test('getInstanceFragment', () {
120 var model = toSymbolMap({'foo': 'bar'});
121
122 var testSyntax = new WhitespaceRemover();
123 TemplateElement.syntax['Test'] = testSyntax;
124 try {
125 var div = createTestHtml(
126 '''<template bind syntax="Test">
127 {{ foo }}
128 <template bind>
129 {{ foo }}
130 </template>
131 </template>''');
132
133 recursivelySetTemplateModel(div, model);
134 deliverChangeRecords();
135
136 expect(testSyntax.trimmed, 2);
137 expect(testSyntax.removed, 1);
138
139 expect(div.nodes.length, 4);
140 expect(div.nodes.last.text, 'bar');
141 expect(div.nodes[2].tagName, 'TEMPLATE');
142 expect(div.nodes[2].attributes['syntax'], 'Test');
143
144 } finally {
145 TemplateElement.syntax.remove('Test');
146 }
147 });
148
149 test('Basic', () { 118 test('Basic', () {
150 var model = toSymbolMap({'foo': 2, 'bar': 4}); 119 var model = toSymbolMap({'foo': 2, 'bar': 4});
151 120
152 TemplateElement.syntax['2x'] = new TimesTwoSyntax(); 121 TemplateElement.syntax['2x'] = new TimesTwoSyntax();
153 122
154 var div = createTestHtml( 123 var div = createTestHtml(
155 '<template bind syntax="2x">' 124 '<template bind syntax="2x">'
156 '{{ foo }} + {{ 2x: bar }} + {{ 4x: bar }}</template>'); 125 '{{ foo }} + {{ 2x: bar }} + {{ 4x: bar }}</template>');
157 recursivelySetTemplateModel(div, model); 126 recursivelySetTemplateModel(div, model);
158 deliverChangeRecords(); 127 deliverChangeRecords();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 class TimesTwoSyntax extends CustomBindingSyntax { 224 class TimesTwoSyntax extends CustomBindingSyntax {
256 getBinding(model, path, name, node) { 225 getBinding(model, path, name, node) {
257 path = path.trim(); 226 path = path.trim();
258 if (!path.startsWith('2x:')) return null; 227 if (!path.startsWith('2x:')) return null;
259 228
260 path = path.substring(3); 229 path = path.substring(3);
261 return new CompoundBinding((values) => values['value'] * 2) 230 return new CompoundBinding((values) => values['value'] * 2)
262 ..bind('value', model, path); 231 ..bind('value', model, path);
263 } 232 }
264 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698