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

Unified Diff: tests/corelib/expando_test.dart

Issue 10534089: Add experimental expando support. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test case. Created 8 years, 6 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 | « tests/corelib/corelib.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/expando_test.dart
diff --git a/tests/corelib/expando_test.dart b/tests/corelib/expando_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0217bdab6f271fd77593e56ec1f70101c1c54085
--- /dev/null
+++ b/tests/corelib/expando_test.dart
@@ -0,0 +1,61 @@
+// Copyright (c) 2012, 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.
+
+main() {
+ var legal = [ new Object(),
+ new List(), [1,2,3], const [1,2,3],
+ new Map(), {'x':1,'y':2}, const {'x':1,'y':2},
+ new Expando(), new Expando('horse') ];
+ for (var object in legal) {
+ testNamedExpando(object);
+ testUnnamedExpando(object);
+ }
Ivan Posva 2012/06/11 12:08:08 Currently you are only testing adding a specific e
kasperl 2012/06/11 12:44:39 Done.
+ testIllegal();
+}
+
+testNamedExpando(object) {
+ Expando<int> expando = new Expando<int>('myexpando');
+ Expect.equals('myexpando', expando.name);
+ Expect.isTrue(expando.toString().startsWith('Expando:myexpando'));
+ testExpando(expando, object);
+}
+
+testUnnamedExpando(object) {
+ Expando<int> expando = new Expando<int>();
+ Expect.isNull(expando.name);
+ Expect.isTrue(expando.toString().startsWith('Expando:'));
+ testExpando(expando, object);
+}
+
+testExpando(Expando<int> expando, object) {
+ Expect.isNull(expando[object]);
+ expando[object] = 42;
+ Expect.equals(42, expando[object]);
+ expando[object] = null;
+ Expect.isNull(expando[object]);
+
+ Expando<int> alternative = new Expando('myexpando');
Ivan Posva 2012/06/11 12:08:08 You might also want to do this while having the or
kasperl 2012/06/11 12:44:39 Done.
+ Expect.isNull(alternative[object]);
+ alternative[object] = 87;
+ Expect.isNull(expando[object]);
+ Expect.equals(87, alternative[object]);
+}
+
+testIllegal() {
+ Expando<int> expando = new Expando<int>();
+ Expect.throws(() => expando[null], (exception)
+ => exception is NullPointerException);
+ Expect.throws(() => expando['string'], (exception)
+ => exception is IllegalArgumentException);
+ Expect.throws(() => expando['string'], (exception)
+ => exception is IllegalArgumentException);
+ Expect.throws(() => expando[42], (exception)
+ => exception is IllegalArgumentException);
+ Expect.throws(() => expando[42.87], (exception)
+ => exception is IllegalArgumentException);
+ Expect.throws(() => expando[true], (exception)
+ => exception is IllegalArgumentException);
+ Expect.throws(() => expando[false], (exception)
+ => exception is IllegalArgumentException);
+}
« no previous file with comments | « tests/corelib/corelib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698