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

Side by Side Diff: tests/corelib/expando_test.dart

Issue 10909209: Eliminate the const constructor from the Expando class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/expando_patch.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 const Expando<int> visits = const Expando<int>('visits'); 5 class ExpandoTest {
6 static Expando<int> visits;
6 7
7 main() { 8 static testMain() {
8 var legal = [ new Object(), 9 visits = new Expando<int>('visits');
9 new List(), [1,2,3], const [1,2,3], 10 var legal = [ new Object(),
10 new Map(), {'x':1,'y':2}, const {'x':1,'y':2}, 11 new List(), [1,2,3], const [1,2,3],
11 new Expando(), new Expando('horse') ]; 12 new Map(), {'x':1,'y':2}, const {'x':1,'y':2},
12 for (var object in legal) { 13 new Expando(), new Expando('horse') ];
13 testNamedExpando(object); 14 for (var object in legal) {
14 testUnnamedExpando(object); 15 testNamedExpando(object);
15 testConstExpando(object); 16 testUnnamedExpando(object);
17 }
18 for (var object in legal) {
19 Expect.equals(2, visits[object]);
20 }
21 testIllegal();
16 } 22 }
17 for (var object in legal) { 23
18 Expect.equals(3, visits[object]); 24 static visit(object) {
25 int count = visits[object];
26 count = (count === null) ? 1 : count + 1;
27 visits[object] = count;
19 } 28 }
20 testIllegal(); 29
30 static testNamedExpando(object) {
31 Expando<int> expando = new Expando<int>('myexpando');
32 Expect.equals('myexpando', expando.name);
33 Expect.isTrue(expando.toString().startsWith('Expando:myexpando'));
34 testExpando(expando, object);
35 }
36
37 static testUnnamedExpando(object) {
38 Expando<int> expando = new Expando<int>();
39 Expect.isNull(expando.name);
40 Expect.isTrue(expando.toString().startsWith('Expando:'));
41 testExpando(expando, object);
42 }
43
44 static testExpando(Expando<int> expando, object) {
45 visit(object);
46
47 Expect.isNull(expando[object]);
48 expando[object] = 42;
49 Expect.equals(42, expando[object]);
50 expando[object] = null;
51 Expect.isNull(expando[object]);
52
53 Expando<int> alternative = new Expando('myexpando');
54 Expect.isNull(alternative[object]);
55 alternative[object] = 87;
56 Expect.isNull(expando[object]);
57 expando[object] = 99;
58 Expect.equals(99, expando[object]);
59 Expect.equals(87, alternative[object]);
60 }
61
62 static testIllegal() {
63 Expando<int> expando = new Expando<int>();
64 Expect.throws(() => expando[null], (exception)
65 => exception is NullPointerException);
66 Expect.throws(() => expando['string'], (exception)
67 => exception is IllegalArgumentException);
68 Expect.throws(() => expando['string'], (exception)
69 => exception is IllegalArgumentException);
70 Expect.throws(() => expando[42], (exception)
71 => exception is IllegalArgumentException);
72 Expect.throws(() => expando[42.87], (exception)
73 => exception is IllegalArgumentException);
74 Expect.throws(() => expando[true], (exception)
75 => exception is IllegalArgumentException);
76 Expect.throws(() => expando[false], (exception)
77 => exception is IllegalArgumentException);
78 }
21 } 79 }
22 80
23 visit(object) { 81 main() => ExpandoTest.testMain();
24 int count = visits[object];
25 count = (count === null) ? 1 : count + 1;
26 visits[object] = count;
27 }
28
29 testNamedExpando(object) {
30 Expando<int> expando = new Expando<int>('myexpando');
31 Expect.equals('myexpando', expando.name);
32 Expect.isTrue(expando.toString().startsWith('Expando:myexpando'));
33 testExpando(expando, object);
34 }
35
36 testUnnamedExpando(object) {
37 Expando<int> expando = new Expando<int>();
38 Expect.isNull(expando.name);
39 Expect.isTrue(expando.toString().startsWith('Expando:'));
40 testExpando(expando, object);
41 }
42
43 testExpando(Expando<int> expando, object) {
44 visit(object);
45
46 Expect.isNull(expando[object]);
47 expando[object] = 42;
48 Expect.equals(42, expando[object]);
49 expando[object] = null;
50 Expect.isNull(expando[object]);
51
52 Expando<int> alternative = new Expando('myexpando');
53 Expect.isNull(alternative[object]);
54 alternative[object] = 87;
55 Expect.isNull(expando[object]);
56 expando[object] = 99;
57 Expect.equals(99, expando[object]);
58 Expect.equals(87, alternative[object]);
59 }
60
61 testConstExpando(object) {
62 visit(object);
63
64 var e0 = const Expando<int>('horse');
65 var e1 = const Expando<int>('horse');
66 var e2 = new Expando<int>('horse');
67 var e3 = new Expando<int>('horse');
68
69 e0[object] = 0;
70 Expect.equals(0, e0[object]);
71
72 e1[object] = 1;
73 Expect.equals(1, e0[object]);
74 Expect.equals(1, e1[object]);
75
76 e2[object] = 2;
77 Expect.equals(1, e0[object]);
78 Expect.equals(1, e1[object]);
79 Expect.equals(2, e2[object]);
80
81 e3[object] = 3;
82 Expect.equals(1, e0[object]);
83 Expect.equals(1, e1[object]);
84 Expect.equals(2, e2[object]);
85 Expect.equals(3, e3[object]);
86
87 e0[object] = null;
88 Expect.isNull(e0[object]);
89 Expect.isNull(e1[object]);
90 Expect.equals(2, e2[object]);
91 Expect.equals(3, e3[object]);
92 }
93
94 testIllegal() {
95 Expando<int> expando = new Expando<int>();
96 Expect.throws(() => expando[null], (exception)
97 => exception is NullPointerException);
98 Expect.throws(() => expando['string'], (exception)
99 => exception is IllegalArgumentException);
100 Expect.throws(() => expando['string'], (exception)
101 => exception is IllegalArgumentException);
102 Expect.throws(() => expando[42], (exception)
103 => exception is IllegalArgumentException);
104 Expect.throws(() => expando[42.87], (exception)
105 => exception is IllegalArgumentException);
106 Expect.throws(() => expando[true], (exception)
107 => exception is IllegalArgumentException);
108 Expect.throws(() => expando[false], (exception)
109 => exception is IllegalArgumentException);
110 }
OLDNEW
« no previous file with comments | « runtime/lib/expando_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698