Improve matcher descriptions that match against objects, and thus fix a bug

in mocking library. 

See https://code.google.com/p/dart/issues/detail?id=7039
Review URL: https://codereview.chromium.org//12207123

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@18386 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
gram@google.com 2013-02-12 17:22:19 +00:00
parent 3520e88c04
commit dad3b5ae60
2 changed files with 18 additions and 0 deletions

View file

@ -47,6 +47,12 @@ class StringDescription implements Description {
String description = (value == null) ? "null" : value.toString();
if (description.startsWith('<') && description.endsWith('>')) {
add(description);
} else if (description.startsWith("Instance of")) {
add('<');
add(description);
add(':');
add(value.hashCode.toString());
add('>');
} else {
add('<');
add(description);

View file

@ -649,4 +649,16 @@ main() {
m3.clearLogs();
expect(log.logs, hasLength(0));
});
test("Mocking: instances", () {
var alice = new Object();
var bob = new Object();
var m = new Mock();
m.when(callsTo("foo", alice)).alwaysReturn(true);
m.when(callsTo("foo", bob)).alwaysReturn(false);
expect(m.foo(alice), true);
expect(m.foo(bob), false);
expect(m.foo(alice), true);
expect(m.foo(bob), false);
});
}