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

Unified Diff: pkg/polymer/test/computed_properties_test.dart

Issue 420673002: Roll polymer packages to version 0.3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/polymer/test/build/script_compactor_test.dart ('k') | pkg/polymer/test/computed_properties_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/test/computed_properties_test.dart
diff --git a/pkg/polymer/test/computed_properties_test.dart b/pkg/polymer/test/computed_properties_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..df7e535c6dac11aac4dda02d2794c4565e539d85
--- /dev/null
+++ b/pkg/polymer/test/computed_properties_test.dart
@@ -0,0 +1,84 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:html';
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
+import 'package:polymer/polymer.dart';
+
+// Test ported from:
+// https://github.com/Polymer/polymer-dev/blob/0.3.4/test/html/computedProperties.html
+@CustomTag('x-foo')
+class XFoo extends PolymerElement {
+ XFoo.created(): super.created();
+
+ // Left like this to illustrate the old-style @published pattern next to the
+ // new style below.
+ @published int count;
+
+ @published
+ String get foo => readValue(#foo);
+ set foo(String v) => writeValue(#foo, v);
+
+ @published
+ String get bar => readValue(#bar);
+ set bar(String v) => writeValue(#bar, v);
+
+ @ComputedProperty('repeat(fooBar, count)')
+ String get fooBarCounted => readValue(#fooBarCounted);
+
+ @ComputedProperty('foo + "-" + bar')
+ String get fooBar => readValue(#fooBar);
+
+ @ComputedProperty('this.foo')
+ String get foo2 => readValue(#foo2);
+ set foo2(v) => writeValue(#foo2, v);
+
+ @ComputedProperty('bar + ""')
+ String get bar2 => readValue(#bar2);
+ set bar2(v) => writeValue(#bar2, v);
+
+ repeat(String s, int count) {
+ var sb = new StringBuffer();
+ for (var i = 0; i < count; i++) {
+ if (i > 0) sb.write(' ');
+ sb.write(s);
+ sb.write('($i)');
+ }
+ return sb.toString();
+ }
+}
+
+main() => initPolymer().run(() {
+ useHtmlConfiguration();
+
+ setUp(() => Polymer.onReady);
+
+ test('computed properties basic', () {
+ var xFoo = querySelector('x-foo');
+ var html = xFoo.shadowRoot.innerHtml;
+ expect(html, 'mee-too:mee-too(0) mee-too(1) mee-too(2)');
+ expect(xFoo.fooBar, 'mee-too');
+ });
+
+ // Dart note: the following tests were not in the original JS test.
+ test('computed properties can be updated', () {
+ var xFoo = querySelector('x-foo');
+ expect(xFoo.foo, 'mee');
+ expect(xFoo.foo2, 'mee');
+ xFoo.foo2 = 'hi';
+ expect(xFoo.foo, 'hi');
+ expect(xFoo.foo2, 'hi');
+ });
+
+ test('only assignable expressions can be updated', () {
+ var xFoo = querySelector('x-foo');
+ expect(xFoo.bar, 'too');
+ expect(xFoo.bar2, 'too');
+ xFoo.bar2 = 'hi';
+ expect(xFoo.bar, 'too');
+ expect(xFoo.bar2, 'too');
+ });
+});
« no previous file with comments | « pkg/polymer/test/build/script_compactor_test.dart ('k') | pkg/polymer/test/computed_properties_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698