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

Unified Diff: pkg/polymer_expressions/test/eval_test.dart

Issue 310903003: Don’t throw on assignments to non-assignable expressions. Allow non-literal indices in assignable e… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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_expressions/lib/polymer_expressions.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer_expressions/test/eval_test.dart
diff --git a/pkg/polymer_expressions/test/eval_test.dart b/pkg/polymer_expressions/test/eval_test.dart
index 83a43f57495633833d934178f438063971014726..a73e037f7c4f57eff231caf4787acc6f363fb661 100644
--- a/pkg/polymer_expressions/test/eval_test.dart
+++ b/pkg/polymer_expressions/test/eval_test.dart
@@ -244,6 +244,15 @@ main() {
var foo = new Foo(items: [1, 2, 3]);
assign(parse('items[0]'), 4, new Scope(model: foo));
expect(foo.items[0], 4);
+ assign(parse('items[a]'), 5, new Scope(model: foo, variables: {'a': 0}));
+ expect(foo.items[0], 5);
+ });
+
+ test('should assign with a function call subexpression', () {
+ var child = new Foo();
+ var foo = new Foo(items: [1, 2, 3], child: child);
+ assign(parse('getChild().name'), 'child', new Scope(model: foo));
+ expect(child.name, 'child');
});
test('should assign through transformers', () {
@@ -260,10 +269,36 @@ main() {
expect(foo.name, '19');
});
- test('should throw on assignments to properties on null', () {
+ test('should not throw on assignments to properties on null', () {
assign(parse('name'), 'b', new Scope(model: null));
});
+ test('should throw on assignments to non-assignable expressions', () {
+ var foo = new Foo(name: 'a');
+ var scope = new Scope(model: foo);
+ expect(() => assign(parse('name + 1'), 1, scope),
+ throwsA(new isInstanceOf<EvalException>()));
+ expect(() => assign(parse('toString()'), 1, scope),
+ throwsA(new isInstanceOf<EvalException>()));
+ expect(() => assign(parse('name | filter'), 1, scope),
+ throwsA(new isInstanceOf<EvalException>()));
+ });
+
+ test('should not throw on assignments to non-assignable expressions if '
+ 'checkAssignability is false', () {
+ var foo = new Foo(name: 'a');
+ var scope = new Scope(model: foo);
+ expect(
+ assign(parse('name + 1'), 1, scope, checkAssignability: false),
+ null);
+ expect(
+ assign(parse('toString()'), 1, scope, checkAssignability: false),
+ null);
+ expect(
+ assign(parse('name | filter'), 1, scope, checkAssignability: false),
+ null);
+ });
+
});
group('scope', () {
@@ -350,6 +385,10 @@ class Foo extends ChangeNotifier {
Foo({name, this.age, this.child, this.items}) : _name = name;
int x() => age * age;
+
+ getChild() => child;
+
+ filter(i) => i;
}
@reflectable
« no previous file with comments | « pkg/polymer_expressions/lib/polymer_expressions.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698