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

Side by Side Diff: tests/standalone/assert_test.dart

Issue 10915083: Change assert implementation to not depend on a top-level function called 'assert'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // VMOptions=--enable_asserts 4 // VMOptions=--enable_asserts
5 // 5 //
6 // Dart test program testing assert statements. 6 // Dart test program testing assert statements.
7 7
8 class AssertTest { 8 class AssertTest {
9 static test() { 9 static test() {
10 int i = 0; 10 int i = 0;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 return i; 43 return i;
44 } 44 }
45 45
46 static testMain() { 46 static testMain() {
47 Expect.equals(1, test()); 47 Expect.equals(1, test());
48 Expect.equals(1, testClosure()); 48 Expect.equals(1, testClosure());
49 } 49 }
50 } 50 }
51 51
52 // A function that accepts 0-2 arguments.
53 void poly([a, b]) {
54 polyCount++;
55 polyArg = a;
56 }
57 // First argument of most recent call to poly.
58 var polyArg = 0;
59 // Number of calls to poly.
60 var polyCount = 0;
61
62 class SuperGet {
63 get assert => poly;
64 }
65
66 class SuperMethod {
67 assert([a, b]) => poly(a, b);
68 }
69
70 class SuperField {
71 var assert;
72 SuperField() : assert = poly;
73 }
74
75 class SuperNon {
76 noSuchMethod(x, y) => poly.apply(y);
77 }
78
79 class SubGet extends SuperGet {
80 void getAssert() {
81 assert;
82 }
83 void assert0() {
84 assert();
85 }
86 void assert1(x) {
87 assert(x);
88 }
89 void assertExp1(x) {
90 var z = assert(x);
91 }
92 void assert2(x) {
93 assert(x, x);
94 }
95 }
96
97 class SubMethod extends SuperMethod {
98 void getAssert() {
99 assert;
100 }
101 void assert0() {
102 assert();
103 }
104 void assert1(x) {
105 assert(x);
106 }
107 void assertExp1(x) {
108 var z = assert(x);
109 }
110 void assert2(x) {
111 assert(x, x);
112 }
113 }
114
115 class SubField extends SuperField {
116 void getAssert() {
117 assert;
118 }
119 void assert0() {
120 assert();
121 }
122 void assert1(x) {
123 assert(x);
124 }
125 void assertExp(x) {
126 var z = assert(x);
127 }
128 void assert2(x) {
129 assert(x, x);
130 }
131 }
132
133 class SubNon extends SuperNon {
134 void getAssert() {
135 assert;
136 }
137 assert0() {
138 assert();
139 }
140 void assert1(x) {
141 assert(x);
142 }
143 void assertExp(x) {
144 var z = assert(x);
145 }
146 void assert2(x) {
147 assert(x, x);
148 }
149 }
150
151
152 testSuperAssert() {
153 var get = new SubGet();
154 var method = new SubMethod();
155 var field = new SubField();
156 var non = new SubNon();
157
158 function expectCallsPoly(code) {
159 int oldPolyCount = polyCount;
160 int newPolyArg = polyArg + 1;
161 code(newPolyArg);
162 Expect.equals(oldPolyCount + 1, polyCount);
163 Expect.equals(newPolyArg, polyArg);
164 }
165
166 expectAssert(code, [bool noArgument = false]) {
167 int oldPolyCount = polyCount;
168 try {
169 code(polyArg + 1);
170 Expect.fail();
171 } on AssertionError catch (e) {
172 }
173 Expect.equals(oldPolyCount, polyCount);
174 }
175
176 void testAssert(object) {
177 object.getAssert(); // Doesn't fail.
178 expectCallsPoly(object.assert0(), true); // Not an assert.
179 expectAssert(object.assert1); // Is real assert.
180 expectCallsPoly(object.assertExp); // Not an assert in expression position.
181 expectCallsPoly(object.assert2); // Not an assert with two arguments.
182 }
183
184 testAssert(get);
185 testAssert(method);
186 testAssert(field);
187 testAssert(non);
Johnni Winther 2012/09/05 09:07:05 I see no tests for when an assert method is in lex
Lasse Reichstein Nielsen 2012/09/05 12:51:20 True, let's add that too. I'll add a lexicalAssert
188 }
189
52 main() { 190 main() {
53 AssertTest.testMain(); 191 AssertTest.testMain();
54 } 192 }
OLDNEW
« lib/compiler/implementation/scanner/keyword.dart ('K') | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698