-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy patherrors_test.dart
160 lines (150 loc) · 5 KB
/
errors_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Test that error constructors do what they are documented as doing.
main() {
Expect.equals("Invalid argument(s)", new ArgumentError().toString());
Expect.equals(
"Invalid argument(s): message",
new ArgumentError("message").toString(),
);
Expect.equals(
"Invalid argument: null",
new ArgumentError.value(null).toString(),
);
Expect.equals("Invalid argument: 42", new ArgumentError.value(42).toString());
Expect.equals(
"Invalid argument: \"bad\"",
new ArgumentError.value("bad").toString(),
);
Expect.equals(
"Invalid argument (foo): null",
new ArgumentError.value(null, "foo").toString(),
);
Expect.equals(
"Invalid argument (foo): 42",
new ArgumentError.value(42, "foo").toString(),
);
Expect.equals(
"Invalid argument (foo): message: 42",
new ArgumentError.value(42, "foo", "message").toString(),
);
Expect.equals(
"Invalid argument: message: 42",
new ArgumentError.value(42, null, "message").toString(),
);
Expect.equals(
"Invalid argument(s): Must not be null",
new ArgumentError.notNull().toString(),
);
Expect.equals(
"Invalid argument(s) (foo): Must not be null",
new ArgumentError.notNull("foo").toString(),
);
Expect.equals("RangeError", new RangeError(null).toString());
Expect.equals("RangeError: message", new RangeError("message").toString());
Expect.equals(
"RangeError: Value not in range: 42",
new RangeError.value(42).toString(),
);
Expect.equals(
"RangeError (foo): Value not in range: 42",
new RangeError.value(42, "foo").toString(),
);
Expect.equals(
"RangeError (foo): message: 42",
new RangeError.value(42, "foo", "message").toString(),
);
Expect.equals(
"RangeError: message: 42",
new RangeError.value(42, null, "message").toString(),
);
Expect.equals(
"RangeError: Invalid value: Not in inclusive range 2..9: 42",
new RangeError.range(42, 2, 9).toString(),
);
Expect.equals(
"RangeError (foo): Invalid value: Not in inclusive range 2..9: 42",
new RangeError.range(42, 2, 9, "foo").toString(),
);
Expect.equals(
"RangeError (foo): message: Not in inclusive range 2..9: 42",
new RangeError.range(42, 2, 9, "foo", "message").toString(),
);
Expect.equals(
"RangeError: message: Not in inclusive range 2..9: 42",
new RangeError.range(42, 2, 9, null, "message").toString(),
);
Expect.equals(
"RangeError: Index out of range: "
"index should be less than 3: 42",
new IndexError.withLength(42, 3, indexable: [1, 2, 3]).toString(),
);
Expect.equals(
"RangeError (foo): Index out of range: "
"index should be less than 3: 42",
new IndexError.withLength(
42,
3,
indexable: [1, 2, 3],
name: "foo",
).toString(),
);
Expect.equals(
"RangeError (foo): message: "
"index should be less than 3: 42",
new IndexError.withLength(
42,
3,
indexable: [1, 2, 3],
name: "foo",
message: "message",
).toString(),
);
Expect.equals(
"RangeError: message: "
"index should be less than 3: 42",
new IndexError.withLength(
42,
3,
indexable: [1, 2, 3],
message: "message",
).toString(),
);
Expect.equals(
"RangeError (foo): message: "
"index should be less than 2: 42",
new IndexError.withLength(
42,
2,
indexable: [1, 2, 3],
name: "foo",
message: "message",
).toString(),
);
Expect.equals(
"RangeError: Index out of range: "
"index must not be negative: -5",
new IndexError.withLength(-5, 3, indexable: [1, 2, 3]).toString(),
);
Expect.equals(42, ArgumentError.checkNotNull(42));
Expect.equals(42, ArgumentError.checkNotNull(42, "name"));
Expect.throwsArgumentError(() => ArgumentError.checkNotNull(null));
Expect.equals(1, RangeError.checkNotNegative(1));
Expect.equals(0, RangeError.checkNotNegative(0));
Expect.throwsRangeError(() => RangeError.checkNotNegative(-1));
Expect.equals(1, RangeError.checkValueInInterval(1, 0, 2));
Expect.equals(1, RangeError.checkValueInInterval(1, 1, 2));
Expect.equals(1, RangeError.checkValueInInterval(1, 0, 1));
Expect.equals(1, RangeError.checkValueInInterval(1, 1, 1));
Expect.throwsRangeError(() => RangeError.checkValueInInterval(1, 2, 3));
Expect.throwsRangeError(() => RangeError.checkValueInInterval(1, 1, 0));
Expect.throwsRangeError(() => RangeError.checkValueInInterval(0, 1, 0));
Expect.equals(1, IndexError.check(1, 2, indexable: [1, 2]));
Expect.equals(1, IndexError.check(1, 2));
Expect.throwsRangeError(() => IndexError.check(1, 0, indexable: []));
Expect.throwsRangeError(() => IndexError.check(1, 1));
Expect.throwsRangeError(() => IndexError.check(-1, 3, indexable: [1, 2, 3]));
Expect.throwsRangeError(() => IndexError.check(-1, 3));
}