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

Unified Diff: pkg/observe/test/path_observer_test.dart

Issue 211763002: Change path-observer to lookup properties aggressively and report errors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
Index: pkg/observe/test/path_observer_test.dart
diff --git a/pkg/observe/test/path_observer_test.dart b/pkg/observe/test/path_observer_test.dart
index 8d71680a39e0c3af1f3cfc1d27889e87c083db18..8395eb948b986657d0c20c947c830925ab38de2b 100644
--- a/pkg/observe/test/path_observer_test.dart
+++ b/pkg/observe/test/path_observer_test.dart
@@ -9,7 +9,6 @@ import 'observe_test_utils.dart';
// This file contains code ported from:
// https://github.com/rafaelw/ChangeSummary/blob/master/tests/test.js
-
main() => dirtyCheckZone().run(() {
group('PathObserver', observePathTests);
@@ -68,26 +67,32 @@ main() => dirtyCheckZone().run(() {
});
});
-
observePathTests() {
test('Degenerate Values', () {
expect(new PathObserver(null, '').value, null);
expect(new PathObserver(123, '').value, 123);
- expect(new PathObserver(123, 'foo.bar.baz').value, null);
-
- // shouldn't throw:
- new PathObserver(123, '')..open((_) {})..close();
- new PropertyPath('').setValueFrom(null, null);
- new PropertyPath('').setValueFrom(123, 42);
- new PropertyPath('foo.bar.baz').setValueFrom(123, 42);
-
- var foo = {};
- expect(new PathObserver(foo, '').value, foo);
-
- foo = new Object();
- expect(new PathObserver(foo, '').value, foo);
-
- expect(new PathObserver(foo, 'a/3!').value, null);
+ new Future(() {}).then((_) {
Jennifer Messerly 2014/03/25 22:32:44 return the Future? also does it work to start wit
Siggi Cherem (dart-lang) 2014/03/26 00:32:07 (obsolete)
+ // should throw:
+ return _asyncError('foo',
+ () => expect(new PathObserver(123, 'foo.bar.baz').value, null));
Jennifer Messerly 2014/03/25 22:32:44 as noted earlier, I'd expect this error to be sync
Siggi Cherem (dart-lang) 2014/03/26 00:32:07 Done.
+ }).then((_) {
+ // shouldn't throw:
+ new PathObserver(123, '')..open((_) {})..close();
+ new PropertyPath('').setValueFrom(null, null);
+ new PropertyPath('').setValueFrom(123, 42);
+
+ // should throw:
+ return _asyncError('foo',
Jennifer Messerly 2014/03/25 22:32:44 when i'm changing behavior w.r.t. JS I usually put
Siggi Cherem (dart-lang) 2014/03/26 00:32:07 Done (made the note on the source code too)
+ () => new PropertyPath('foo.bar.baz').setValueFrom(123, 42));
+ }).then((_) {
+ var foo = {};
+ expect(new PathObserver(foo, '').value, foo);
+
+ foo = new Object();
+ expect(new PathObserver(foo, '').value, foo);
+
+ expect(new PathObserver(foo, 'a/3!').value, null);
+ });
});
test('get value at path ObservableBox', () {
@@ -105,8 +110,9 @@ observePathTests() {
expect(new PathObserver(obj, 'value.value.value').value, 3);
obj.value = new ObservableBox(4);
- expect(new PathObserver(obj, 'value.value.value').value, null);
expect(new PathObserver(obj, 'value.value').value, 4);
+ return _asyncError('value',
+ () => expect(new PathObserver(obj, 'value.value.value').value, null));
});
@@ -125,8 +131,9 @@ observePathTests() {
expect(new PathObserver(obj, 'a.b.c').value, 3);
obj['a'] = toObservable({'b': 4});
- expect(new PathObserver(obj, 'a.b.c').value, null);
expect(new PathObserver(obj, 'a.b').value, 4);
+ return _asyncError('c',
+ () => expect(new PathObserver(obj, 'a.b.c').value, null));
});
test('set value at path', () {
@@ -138,8 +145,13 @@ observePathTests() {
new PropertyPath('bar').setValueFrom(obj, bar);
expect(obj['bar'], bar);
- new PropertyPath('bar.baz.bat').setValueFrom(obj, 'not here');
- expect(new PathObserver(obj, 'bar.baz.bat').value, null);
+ new Future(() {}).then((_) {
+ return _asyncError('bat=',
+ () => new PropertyPath('bar.baz.bat').setValueFrom(obj, 'not here'));
+ }).then((_) {
+ return _asyncError('bat',
+ () => expect(new PathObserver(obj, 'bar.baz.bat').value, null));
+ });
});
test('set value back to same', () {
@@ -239,7 +251,9 @@ observePathTests() {
var path = new PathObserver(model, 'a.b.c');
var lastValue = null;
- path.open((x) { lastValue = x; });
+ var errorSeen = false;
+ var future = _asyncError('c', () => path.open((x) { lastValue = x; }))
+ .then((_) { errorSeen = true; });
model.a.b.c = 'hello, mom';
@@ -257,7 +271,9 @@ observePathTests() {
expect(lastValue, 'hello, you');
model.a.b = 1;
- }).then(newMicrotask).then((_) {
+ expect(errorSeen, false); // update will be seen on next micro task
+ }).then((_) => future).then((_) {
+ expect(errorSeen, true);
expect(lastValue, null);
// Stop observing
@@ -300,11 +316,14 @@ observePathTests() {
var model = new ObjectWithErrors();
var observer = new PathObserver(model, 'foo');
- expect(() => observer.value, throws);
- expect(model.getFooCalled, 1);
-
- expect(() { observer.value = 123; }, throws);
- expect(model.setFooCalled, [123]);
+ new Future(() {}).then((_) {
+ return _asyncError('bar', () => observer.value);
+ }).then((_) {
+ expect(model.getFooCalled, 1);
+ return _asyncError('bar=', () { observer.value = 123; });
+ }).then((_) {
+ expect(model.setFooCalled, [123]);
+ });
});
test('object with noSuchMethod', () {
@@ -352,6 +371,24 @@ observePathTests() {
});
}
+_asyncError(String missingPropertyName, Function code) {
+ var completer = new Completer();
+ runZoned(() {
+ code();
+ return new Future(() {});
+ }, onError: (e) {
+ completer.complete(true);
+ expect(e, predicate((e) => e is NoSuchMethodError));
+
+ // Dart2js and VM error messages are a bit different, but they are both
+ // contain the missingPropertyName.
+ expect('$e', predicate((message) =>
+ message.contains("'$missingPropertyName'") || // VM error
+ message.contains('\'Symbol("$missingPropertyName")\''))); // dart2js error
+ });
+ return completer.future;
+}
+
class ObjectWithErrors {
int getFooCalled = 0;
List setFooCalled = [];
@@ -383,7 +420,7 @@ class NoSuchMethodModel {
}
}
-class IndexerModel {
+class IndexerModel implements StringIndexer {
var _foo = 42;
List log = [];

Powered by Google App Engine
This is Rietveld 408576698