OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 201, 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 // VMOptions=--assert_initializer |
| 5 // |
| 6 // Dart test program testing assert statements. |
| 7 |
| 8 import "package:expect/expect.dart"; |
| 9 |
| 10 class C { |
| 11 static bool check(x, y) => x < y; |
| 12 static bool staticTrue() => true; |
| 13 final int x; |
| 14 const C(this.x); |
| 15 |
| 16 C.c01(this.x, y) : assert(x < y); |
| 17 C.c02(x, y) : x = x, assert(x < y); |
| 18 C.c03(x, y) : assert(x < y), x = x; |
| 19 C.c04(this.x, y) : super(), assert(x < y); |
| 20 C.c05(this.x, y) : assert(x < y), super(); |
| 21 C.c06(x, y) : x = x, super(), assert(x < y); |
| 22 C.c07(x, y) : assert(x < y), super(), x = x; |
| 23 C.c08(x, y) : assert(x < y), super(), x = x, assert(y > x); |
| 24 C.c09(this.x, y) : assert(x < y, "$x < $y"); |
| 25 C.c10(this.x, y) : assert(x < y,); |
| 26 C.c11(this.x, y) : assert(x < y, "$x < $y",); |
| 27 |
| 28 const C.cc01(this.x, y) : assert(x < y); |
| 29 const C.cc02(x, y) : x = x, assert(x < y); |
| 30 const C.cc03(x, y) : assert(x < y), x = x; |
| 31 const C.cc04(this.x, y) : super(), assert(x < y); |
| 32 const C.cc05(this.x, y) : assert(x < y), super(); |
| 33 const C.cc06(x, y) : x = x, super(), assert(x < y); |
| 34 const C.cc07(x, y) : assert(x < y), super(), x = x; |
| 35 const C.cc08(x, y) : assert(x < y), super(), x = x, assert(y > x); |
| 36 const C.cc09(this.x, y) : assert(x < y, "$x < $y"); |
| 37 const C.cc10(this.x, y) : assert(x < y,); |
| 38 const C.cc11(this.x, y) : assert(x < y, "$x < $y",); |
| 39 |
| 40 C.nc01(this.x, y) : assert(check(x, y)); |
| 41 C.nc02(x, y) : x = x, assert(check(x, y)); |
| 42 C.nc03(x, y) : assert(check(x, y)), x = x; |
| 43 C.nc04(this.x, y) : super(), assert(check(x, y)); |
| 44 C.nc05(this.x, y) : assert(check(x, y)), super(); |
| 45 C.nc06(x, y) : x = x, super(), assert(check(x, y)); |
| 46 C.nc07(x, y) : assert(check(x, y)), super(), x = x; |
| 47 C.nc08(x, y) : assert(check(x, y)), super(), x = x, assert(y > x); |
| 48 C.nc09(this.x, y) : assert(check(x, y), "$x < $y"); |
| 49 C.nc10(this.x, y) : assert(check(x, y),); |
| 50 C.nc11(this.x, y) : assert(check(x, y), "$x < $y",); |
| 51 |
| 52 C.fc01(this.x, y) : assert(() => x < y); |
| 53 C.fc02(x, y) : x = x, assert(() => x < y); |
| 54 C.fc03(x, y) : assert(() => x < y), x = x; |
| 55 C.fc04(this.x, y) : super(), assert(() => x < y); |
| 56 C.fc05(this.x, y) : assert(() => x < y), super(); |
| 57 C.fc06(x, y) : x = x, super(), assert(() => x < y); |
| 58 C.fc07(x, y) : assert(() => x < y), super(), x = x; |
| 59 C.fc08(x, y) : assert(() => x < y), super(), x = x, assert(y > x); |
| 60 C.fc09(this.x, y) : assert(() => x < y, "$x < $y"); |
| 61 C.fc10(this.x, y) : assert(() => x < y,); |
| 62 C.fc11(this.x, y) : assert(() => x < y, "$x < $y",); |
| 63 } |
| 64 |
| 65 |
| 66 main() { |
| 67 // Test all constructors with both succeeding and failing asserts. |
| 68 test(1, 2); |
| 69 test(2, 1); |
| 70 |
| 71 const c1 = const C(1); |
| 72 |
| 73 // Asserts do not affect canonization. |
| 74 Expect.identical(c1, const C.cc01(1, 2)); |
| 75 Expect.identical(c1, const C.cc02(1, 2)); |
| 76 Expect.identical(c1, const C.cc03(1, 2)); |
| 77 Expect.identical(c1, const C.cc04(1, 2)); |
| 78 Expect.identical(c1, const C.cc05(1, 2)); |
| 79 Expect.identical(c1, const C.cc06(1, 2)); |
| 80 Expect.identical(c1, const C.cc07(1, 2)); |
| 81 Expect.identical(c1, const C.cc08(1, 2)); |
| 82 Expect.identical(c1, const C.cc09(1, 2)); |
| 83 Expect.identical(c1, const C.cc10(1, 2)); |
| 84 Expect.identical(c1, const C.cc11(1, 2)); |
| 85 } |
| 86 |
| 87 void test(int x, int y) { |
| 88 bool checkedMode = false; |
| 89 assert(checkedMode = true); |
| 90 |
| 91 bool Function(C Function()) doTest = (checkedMode && x >= y) |
| 92 ? (f) { Expect.throws(f, (e) => e is AssertionError); } |
| 93 : (f) { Expect.equals(x, f().x); }; |
| 94 |
| 95 doTest(() => new C.c01(x, y)); |
| 96 doTest(() => new C.c02(x, y)); |
| 97 doTest(() => new C.c03(x, y)); |
| 98 doTest(() => new C.c04(x, y)); |
| 99 doTest(() => new C.c05(x, y)); |
| 100 doTest(() => new C.c06(x, y)); |
| 101 doTest(() => new C.c07(x, y)); |
| 102 doTest(() => new C.c08(x, y)); |
| 103 doTest(() => new C.c09(x, y)); |
| 104 doTest(() => new C.c10(x, y)); |
| 105 doTest(() => new C.c11(x, y)); |
| 106 doTest(() => new C.cc01(x, y)); |
| 107 doTest(() => new C.cc02(x, y)); |
| 108 doTest(() => new C.cc03(x, y)); |
| 109 doTest(() => new C.cc04(x, y)); |
| 110 doTest(() => new C.cc05(x, y)); |
| 111 doTest(() => new C.cc06(x, y)); |
| 112 doTest(() => new C.cc07(x, y)); |
| 113 doTest(() => new C.cc08(x, y)); |
| 114 doTest(() => new C.cc09(x, y)); |
| 115 doTest(() => new C.cc10(x, y)); |
| 116 doTest(() => new C.cc11(x, y)); |
| 117 doTest(() => new C.nc01(x, y)); |
| 118 doTest(() => new C.nc02(x, y)); |
| 119 doTest(() => new C.nc03(x, y)); |
| 120 doTest(() => new C.nc04(x, y)); |
| 121 doTest(() => new C.nc05(x, y)); |
| 122 doTest(() => new C.nc06(x, y)); |
| 123 doTest(() => new C.nc07(x, y)); |
| 124 doTest(() => new C.nc08(x, y)); |
| 125 doTest(() => new C.nc09(x, y)); |
| 126 doTest(() => new C.nc10(x, y)); |
| 127 doTest(() => new C.nc11(x, y)); |
| 128 doTest(() => new C.fc01(x, y)); |
| 129 doTest(() => new C.fc02(x, y)); |
| 130 doTest(() => new C.fc03(x, y)); |
| 131 doTest(() => new C.fc04(x, y)); |
| 132 doTest(() => new C.fc05(x, y)); |
| 133 doTest(() => new C.fc06(x, y)); |
| 134 doTest(() => new C.fc07(x, y)); |
| 135 doTest(() => new C.fc08(x, y)); |
| 136 doTest(() => new C.fc09(x, y)); |
| 137 doTest(() => new C.fc10(x, y)); |
| 138 doTest(() => new C.fc11(x, y)); |
| 139 } |
| 140 |
OLD | NEW |