OLD | NEW |
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 | 4 |
5 // VMOptions=--assert_initializer | 5 // VMOptions=--assert_initializer |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 bool assertsEnabled = false; | 8 bool assertsEnabled = false; |
9 | 9 |
10 main() { | 10 main() { |
11 assert((assertsEnabled = true)); | 11 assert((assertsEnabled = true)); |
12 runtimeAsserts(); /// none: ok | 12 runtimeAsserts(); // /// none: ok |
13 | 13 |
14 // Passing const expressions. | 14 // Passing const expressions. |
15 const c00 = const AssertArgument.constFirst(true, 0, 1); | 15 const c00 = const AssertArgument.constFirst(true, 0, 1); |
16 const c01 = const AssertArgument.constLast(true, 0, 1); | 16 const c01 = const AssertArgument.constLast(true, 0, 1); |
17 const c02 = const AssertArgument.constMiddle(true, 0, 1); | 17 const c02 = const AssertArgument.constMiddle(true, 0, 1); |
18 const c03 = const AssertArgument.constMulti(true, 0, 1); | 18 const c03 = const AssertArgument.constMulti(true, 0, 1); |
19 const c04 = const AssertArgument.constFirstSuper(true, 0, 1); | 19 const c04 = const AssertArgument.constFirstSuper(true, 0, 1); |
20 const c05 = const AssertArgument.constLastSuper(true, 0, 1); | 20 const c05 = const AssertArgument.constLastSuper(true, 0, 1); |
21 const c06 = const AssertArgument.constMiddleSuper(true, 0, 1); | 21 const c06 = const AssertArgument.constMiddleSuper(true, 0, 1); |
22 const c07 = const AssertArgument.constMultiSuper(true, 0, 1); | 22 const c07 = const AssertArgument.constMultiSuper(true, 0, 1); |
23 | 23 |
24 const c08 = const AssertCompare.constFirst(1, 2); | 24 const c08 = const AssertCompare.constFirst(1, 2); |
25 const c09 = const AssertCompare.constLast(1, 2); | 25 const c09 = const AssertCompare.constLast(1, 2); |
26 const c10 = const AssertCompare.constMiddle(1, 2); | 26 const c10 = const AssertCompare.constMiddle(1, 2); |
27 const c11 = const AssertCompare.constMulti(1, 2); | 27 const c11 = const AssertCompare.constMulti(1, 2); |
28 const c12 = const AssertCompare.constFirstSuper(1, 2); | 28 const c12 = const AssertCompare.constFirstSuper(1, 2); |
29 const c13 = const AssertCompare.constLastSuper(1, 2); | 29 const c13 = const AssertCompare.constLastSuper(1, 2); |
30 const c14 = const AssertCompare.constMiddleSuper(1, 2); | 30 const c14 = const AssertCompare.constMiddleSuper(1, 2); |
31 const c15 = const AssertCompare.constMultiSuper(1, 2); | 31 const c15 = const AssertCompare.constMultiSuper(1, 2); |
32 | 32 |
33 // Failing const expressions | 33 // Failing const expressions |
34 | 34 |
35 const c = const AssertArgument.constFirst(false, 0, 1); /// 01: compile-
time error | 35 const c = const AssertArgument.constFirst(false, 0, 1); // /// 01: compil
e-time error |
36 const c = const AssertArgument.constLast(false, 0, 1); /// 02: compile-
time error | 36 const c = const AssertArgument.constLast(false, 0, 1); // /// 02: compil
e-time error |
37 const c = const AssertArgument.constMiddle(false, 0, 1); /// 03: compile-
time error | 37 const c = const AssertArgument.constMiddle(false, 0, 1); // /// 03: compil
e-time error |
38 const c = const AssertArgument.constMulti(false, 0, 1); /// 04: compile-
time error | 38 const c = const AssertArgument.constMulti(false, 0, 1); // /// 04: compil
e-time error |
39 const c = const AssertArgument.constFirstSuper(false, 0, 1); /// 05: compile-
time error | 39 const c = const AssertArgument.constFirstSuper(false, 0, 1); // /// 05: compil
e-time error |
40 const c = const AssertArgument.constLastSuper(false, 0, 1); /// 06: compile-
time error | 40 const c = const AssertArgument.constLastSuper(false, 0, 1); // /// 06: compil
e-time error |
41 const c = const AssertArgument.constMiddleSuper(false, 0, 1); /// 07: compile-
time error | 41 const c = const AssertArgument.constMiddleSuper(false, 0, 1); /// 07: compile-
time error |
42 const c = const AssertArgument.constMultiSuper(false, 0, 1); /// 08: compile-
time error | 42 const c = const AssertArgument.constMultiSuper(false, 0, 1); // /// 08: compil
e-time error |
43 | 43 |
44 const c = const AssertArgument.constFirst("str", 0, 1); /// 11: compile-
time error | 44 const c = const AssertArgument.constFirst("str", 0, 1); // /// 11: compil
e-time error |
45 const c = const AssertArgument.constLast("str", 0, 1); /// 12: compile-
time error | 45 const c = const AssertArgument.constLast("str", 0, 1); // /// 12: compil
e-time error |
46 const c = const AssertArgument.constMiddle("str", 0, 1); /// 13: compile-
time error | 46 const c = const AssertArgument.constMiddle("str", 0, 1); // /// 13: compil
e-time error |
47 const c = const AssertArgument.constMulti("str", 0, 1); /// 14: compile-
time error | 47 const c = const AssertArgument.constMulti("str", 0, 1); // /// 14: compil
e-time error |
48 const c = const AssertArgument.constFirstSuper("str", 0, 1); /// 15: compile-
time error | 48 const c = const AssertArgument.constFirstSuper("str", 0, 1); // /// 15: compil
e-time error |
49 const c = const AssertArgument.constLastSuper("str", 0, 1); /// 16: compile-
time error | 49 const c = const AssertArgument.constLastSuper("str", 0, 1); // /// 16: compil
e-time error |
50 const c = const AssertArgument.constMiddleSuper("str", 0, 1); /// 17: compile-
time error | 50 const c = const AssertArgument.constMiddleSuper("str", 0, 1); /// 17: compile-
time error |
51 const c = const AssertArgument.constMultiSuper("str", 0, 1); /// 18: compile-
time error | 51 const c = const AssertArgument.constMultiSuper("str", 0, 1); // /// 18: compil
e-time error |
52 | 52 |
53 const c = const AssertCompare.constFirst(3, 2); /// 21: compile-
time error | 53 const c = const AssertCompare.constFirst(3, 2); // /// 21: compil
e-time error |
54 const c = const AssertCompare.constLast(3, 2); /// 22: compile-
time error | 54 const c = const AssertCompare.constLast(3, 2); // /// 22: compil
e-time error |
55 const c = const AssertCompare.constMiddle(3, 2); /// 23: compile-
time error | 55 const c = const AssertCompare.constMiddle(3, 2); // /// 23: compil
e-time error |
56 const c = const AssertCompare.constMulti(3, 2); /// 24: compile-
time error | 56 const c = const AssertCompare.constMulti(3, 2); // /// 24: compil
e-time error |
57 const c = const AssertCompare.constFirstSuper(3, 2); /// 25: compile-
time error | 57 const c = const AssertCompare.constFirstSuper(3, 2); // /// 25: compil
e-time error |
58 const c = const AssertCompare.constLastSuper(3, 2); /// 26: compile-
time error | 58 const c = const AssertCompare.constLastSuper(3, 2); // /// 26: compil
e-time error |
59 const c = const AssertCompare.constMiddleSuper(3, 2); /// 27: compile-
time error | 59 const c = const AssertCompare.constMiddleSuper(3, 2); // /// 27: compil
e-time error |
60 const c = const AssertCompare.constMultiSuper(3, 2); /// 28: compile-
time error | 60 const c = const AssertCompare.constMultiSuper(3, 2); // /// 28: compil
e-time error |
61 | 61 |
62 // Functions not allowed in asserts in const execution. | 62 // Functions not allowed in asserts in const execution. |
63 const c = const AssertArgument.constFirst(kTrue, 0, 1); /// 31: compile-
time error | 63 const c = const AssertArgument.constFirst(kTrue, 0, 1); // /// 31: compil
e-time error |
64 const c = const AssertArgument.constLast(kTrue, 0, 1); /// 32: compile-
time error | 64 const c = const AssertArgument.constLast(kTrue, 0, 1); // /// 32: compil
e-time error |
65 const c = const AssertArgument.constMiddle(kTrue, 0, 1); /// 33: compile-
time error | 65 const c = const AssertArgument.constMiddle(kTrue, 0, 1); // /// 33: compil
e-time error |
66 const c = const AssertArgument.constMulti(kTrue, 0, 1); /// 34: compile-
time error | 66 const c = const AssertArgument.constMulti(kTrue, 0, 1); // /// 34: compil
e-time error |
67 const c = const AssertArgument.constFirstSuper(kTrue, 0, 1); /// 35: compile-
time error | 67 const c = const AssertArgument.constFirstSuper(kTrue, 0, 1); // /// 35: compil
e-time error |
68 const c = const AssertArgument.constLastSuper(kTrue, 0, 1); /// 36: compile-
time error | 68 const c = const AssertArgument.constLastSuper(kTrue, 0, 1); // /// 36: compil
e-time error |
69 const c = const AssertArgument.constMiddleSuper(kTrue, 0, 1); /// 37: compile-
time error | 69 const c = const AssertArgument.constMiddleSuper(kTrue, 0, 1); /// 37: compile-
time error |
70 const c = const AssertArgument.constMultiSuper(kTrue, 0, 1); /// 38: compile-
time error | 70 const c = const AssertArgument.constMultiSuper(kTrue, 0, 1); // /// 38: compil
e-time error |
71 | 71 |
72 const cTrue = const TrickCompare(true); | 72 const cTrue = const TrickCompare(true); |
73 // Value must be integer for potential-const expression to be actually const. | 73 // Value must be integer for potential-const expression to be actually const. |
74 const c = const AssertCompare.constFirst(cTrue, 2); /// 41: compile-
time error | 74 const c = const AssertCompare.constFirst(cTrue, 2); // /// 41: compil
e-time error |
75 const c = const AssertCompare.constLast(cTrue, 2); /// 42: compile-
time error | 75 const c = const AssertCompare.constLast(cTrue, 2); // /// 42: compil
e-time error |
76 const c = const AssertCompare.constMiddle(cTrue, 2); /// 43: compile-
time error | 76 const c = const AssertCompare.constMiddle(cTrue, 2); // /// 43: compil
e-time error |
77 const c = const AssertCompare.constMulti(cTrue, 2); /// 44: compile-
time error | 77 const c = const AssertCompare.constMulti(cTrue, 2); // /// 44: compil
e-time error |
78 const c = const AssertCompare.constFirstSuper(cTrue, 2); /// 45: compile-
time error | 78 const c = const AssertCompare.constFirstSuper(cTrue, 2); // /// 45: compil
e-time error |
79 const c = const AssertCompare.constLastSuper(cTrue, 2); /// 46: compile-
time error | 79 const c = const AssertCompare.constLastSuper(cTrue, 2); // /// 46: compil
e-time error |
80 const c = const AssertCompare.constMiddleSuper(cTrue, 2); /// 47: compile-
time error | 80 const c = const AssertCompare.constMiddleSuper(cTrue, 2); // /// 47: compil
e-time error |
81 const c = const AssertCompare.constMultiSuper(cTrue, 2); /// 48: compile-
time error | 81 const c = const AssertCompare.constMultiSuper(cTrue, 2); // /// 48: compil
e-time error |
82 } | 82 } |
83 | 83 |
84 | 84 |
85 void runtimeAsserts() { | 85 void runtimeAsserts() { |
86 | 86 |
87 testAssertArgumentCombinations(value, test, [testConst]) { | 87 testAssertArgumentCombinations(value, test, [testConst]) { |
88 test(() => new AssertArgument.first(value, 0, 1)); | 88 test(() => new AssertArgument.first(value, 0, 1)); |
89 test(() => new AssertArgument.last(value, 0, 1)); | 89 test(() => new AssertArgument.last(value, 0, 1)); |
90 test(() => new AssertArgument.middle(value, 0, 1)); | 90 test(() => new AssertArgument.middle(value, 0, 1)); |
91 test(() => new AssertArgument.multi(value, 0, 1)); | 91 test(() => new AssertArgument.multi(value, 0, 1)); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 : y = y, assert(y < z), z = z, super(); | 219 : y = y, assert(y < z), z = z, super(); |
220 const AssertCompare.constMultiSuper(y, z) | 220 const AssertCompare.constMultiSuper(y, z) |
221 : assert(y < z), y = y, assert(y < z), z = z, assert(y < z), super(); | 221 : assert(y < z), y = y, assert(y < z), z = z, assert(y < z), super(); |
222 } | 222 } |
223 | 223 |
224 class TrickCompare { | 224 class TrickCompare { |
225 final result; | 225 final result; |
226 const TrickCompare(this.result); | 226 const TrickCompare(this.result); |
227 operator<(other) => result; // Nyah-nyah! | 227 operator<(other) => result; // Nyah-nyah! |
228 } | 228 } |
OLD | NEW |