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

Side by Side Diff: tests/language_strong/assert_with_message_test.dart

Issue 2990773002: Migrate language/arithmetic2_test ... language/async_await_syntax_test. (Closed)
Patch Set: Update migrated tests and statuses to Dart 2.0. Created 3 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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
5 import "package:expect/expect.dart";
6
7 main() {
8 var assertsEnabled = false;
9 assert((assertsEnabled = true));
10 if (!assertsEnabled) return;
11
12 // TODO(rnystrom): Test cases where the first argument to assert() is a
13 // function.
14
15 testAssertFails();
16 testAssertDoesNotFail();
17 testNullMessage();
18 testDoesNotEvaluateMessageIfAssertSucceeds();
19 testMessageExpressionThatThrows();
20 testCallsToStringOnMessageLazily();
21 }
22
23 /// A class with a custom toString() that tracks when it is called.
24 class ToString {
25 bool calledToString = false;
26
27 String toString() {
28 calledToString = true;
29 return "toString!";
30 }
31 }
32
33 testAssertFails() {
34 try {
35 assert(false, "Oops");
36 Expect.fail("Assert should throw.");
37 } catch (e) {
38 Expect.isTrue(e.toString().contains("Oops"));
39 }
40 }
41
42 testAssertDoesNotFail() {
43 try {
44 assert(true, "Oops");
45 } catch (e) {
46 Expect.fail("Assert should not throw.");
47 }
48 }
49
50 testNullMessage() {
51 try {
52 assert(false, null);
53 Expect.fail("Assert should throw.");
54 } catch (e) {
55 Expect.isTrue(e.toString().contains("is not true"));
56 }
57 }
58
59 testDoesNotEvaluateMessageIfAssertSucceeds() {
60 try {
61 var evaluated = false;
62 assert(true, evaluated = true);
63 Expect.isFalse(evaluated);
64 } catch (e) {
65 Expect.fail("Assert should not throw.");
66 }
67 }
68
69 testMessageExpressionThatThrows() {
70 try {
71 assert(false, throw "dang");
72 Expect.fail("Should throw");
73 } catch (e) {
74 Expect.equals(e, "dang");
75 }
76 }
77
78 testCallsToStringOnMessageLazily() {
79 var toString = new ToString();
80 try {
81 assert(false, toString);
82 Expect.fail("Assert should throw.");
83 } catch (e) {
84 Expect.isFalse(toString.calledToString);
85 Expect.isTrue(e.toString().contains("Instance of 'ToString'"));
86 Expect.isFalse(toString.calledToString);
87 }
88 }
OLDNEW
« no previous file with comments | « tests/language_strong/assert_assignable_type_test.dart ('k') | tests/language_strong/assert_with_type_test_or_cast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698