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

Side by Side Diff: tests/language/src/Arithmetic2Test.dart

Issue 9408001: Throw NoSuchMethod or IllegalArgument on bad operators or bad arguments to (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 10 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 | « tests/language/language-leg.status ('k') | tests/language/src/StringConcatTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 // Dart test program to test arithmetic operations.
5
6 class A {
7 static foo() => 499;
8 }
9
10 bool throwsNoSuchMethod(f) {
11 try {
12 f();
13 return false;
14 } catch(NoSuchMethodException e) {
15 return true;
16 }
17 return false;
18 }
19
20 bool throwsBecauseOfBadArgument(f) {
21 try {
22 f();
23 return false;
24 } catch(NoSuchMethodException e) {
25 return true;
26 } catch(IllegalArgumentException e) {
27 return true;
28 } catch(NullPointerException e) {
29 return true;
30 }
31 return false;
32 }
33
34 numberOpBadSecondArgument(f) {
35 Expect.isTrue(throwsBecauseOfBadArgument(() => f(true)));
36 Expect.isTrue(throwsBecauseOfBadArgument(() => f(new A())));
37 Expect.isTrue(throwsBecauseOfBadArgument(() => f("foo")));
38 Expect.isTrue(throwsBecauseOfBadArgument(() => f("5")));
39 Expect.isTrue(throwsBecauseOfBadArgument(() => f(() => 499)));
40 Expect.isTrue(throwsBecauseOfBadArgument(() => f(null)));
41 Expect.isTrue(throwsBecauseOfBadArgument(() => f(false)));
42 Expect.isTrue(throwsBecauseOfBadArgument(() => f([])));
43 Expect.isTrue(throwsBecauseOfBadArgument(() => f({})));
44 Expect.isTrue(throwsBecauseOfBadArgument(() => f(A.foo)));
45 }
46
47 badOperations(b) {
48 Expect.isTrue(throwsNoSuchMethod(() => b - 3));
49 Expect.isTrue(throwsNoSuchMethod(() => b * 3));
50 Expect.isTrue(throwsNoSuchMethod(() => b ~/ 3));
51 Expect.isTrue(throwsNoSuchMethod(() => b / 3));
52 Expect.isTrue(throwsNoSuchMethod(() => b % 3));
53 Expect.isTrue(throwsNoSuchMethod(() => b + 3));
54 Expect.isTrue(throwsNoSuchMethod(() => b[3]));
55 Expect.isTrue(throwsNoSuchMethod(() => ~b));
56 Expect.isTrue(throwsNoSuchMethod(() => -b));
57 }
58
59 main() {
60 numberOpBadSecondArgument((x) => 3 + x);
61 numberOpBadSecondArgument((x) => 3 - x);
62 numberOpBadSecondArgument((x) => 3 * x);
63 numberOpBadSecondArgument((x) => 3 / x);
64 numberOpBadSecondArgument((x) => 3 ~/ x);
65 numberOpBadSecondArgument((x) => 3 % x);
66 badOperations(true);
67 badOperations(false);
68 badOperations(() => 499);
69 badOperations(A.foo);
70 }
OLDNEW
« no previous file with comments | « tests/language/language-leg.status ('k') | tests/language/src/StringConcatTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698