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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// Copyright 2015 The Chromium Authors. 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:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Border constructor', () {
final Null $null = null;
expect(() => new Border(left: $null), throwsAssertionError);
expect(() => new Border(top: $null), throwsAssertionError);
expect(() => new Border(right: $null), throwsAssertionError);
expect(() => new Border(bottom: $null), throwsAssertionError);
});
test('Border.merge', () {
final BorderSide magenta3 = const BorderSide(color: const Color(0xFFFF00FF), width: 3.0);
final BorderSide magenta6 = const BorderSide(color: const Color(0xFFFF00FF), width: 6.0);
final BorderSide yellow2 = const BorderSide(color: const Color(0xFFFFFF00), width: 2.0);
final BorderSide yellowNone0 = const BorderSide(color: const Color(0xFFFFFF00), width: 0.0, style: BorderStyle.none);
expect(
Border.merge(
new Border(top: yellow2),
new Border(right: magenta3),
),
new Border(top: yellow2, right: magenta3),
);
expect(
Border.merge(
new Border(bottom: magenta3),
new Border(bottom: magenta3),
),
new Border(bottom: magenta6),
);
expect(
Border.merge(
new Border(left: magenta3, right: yellowNone0),
new Border(right: yellow2),
),
new Border(left: magenta3, right: yellow2),
);
expect(
Border.merge(const Border(), const Border()),
const Border(),
);
expect(
() => Border.merge(
new Border(left: magenta3),
new Border(left: yellow2),
),
throwsAssertionError,
);
});
test('Border.add', () {
final BorderSide magenta3 = const BorderSide(color: const Color(0xFFFF00FF), width: 3.0);
final BorderSide magenta6 = const BorderSide(color: const Color(0xFFFF00FF), width: 6.0);
final BorderSide yellow2 = const BorderSide(color: const Color(0xFFFFFF00), width: 2.0);
final BorderSide yellowNone0 = const BorderSide(color: const Color(0xFFFFFF00), width: 0.0, style: BorderStyle.none);
expect(
new Border(top: yellow2) + new Border(right: magenta3),
new Border(top: yellow2, right: magenta3),
);
expect(
new Border(bottom: magenta3) + new Border(bottom: magenta3),
new Border(bottom: magenta6),
);
expect(
new Border(left: magenta3, right: yellowNone0) + new Border(right: yellow2),
new Border(left: magenta3, right: yellow2),
);
expect(
const Border() + const Border(),
const Border(),
);
expect(
new Border(left: magenta3) + new Border(left: yellow2),
isNot(const isInstanceOf<Border>()), // see shape_border_test.dart for better tests of this case
);
final Border b3 = new Border(top: magenta3);
final Border b6 = new Border(top: magenta6);
expect(b3 + b3, b6);
final Border b0 = new Border(top: yellowNone0);
final Border bZ = const Border();
expect(b0 + b0, bZ);
expect(bZ + bZ, bZ);
expect(b0 + bZ, bZ);
expect(bZ + b0, bZ);
});
test('Border.scale', () {
final BorderSide magenta3 = const BorderSide(color: const Color(0xFFFF00FF), width: 3.0);
final BorderSide magenta6 = const BorderSide(color: const Color(0xFFFF00FF), width: 6.0);
final BorderSide yellow2 = const BorderSide(color: const Color(0xFFFFFF00), width: 2.0);
final BorderSide yellowNone0 = const BorderSide(color: const Color(0xFFFFFF00), width: 0.0, style: BorderStyle.none);
final Border b3 = new Border(left: magenta3);
final Border b6 = new Border(left: magenta6);
expect(b3.scale(2.0), b6);
final Border bY0 = new Border(top: yellowNone0);
expect(bY0.scale(3.0), bY0);
final Border bY2 = new Border(top: yellow2);
expect(bY2.scale(0.0), bY0);
});
test('Border.dimensions', () {
expect(
const Border(
left: const BorderSide(width: 2.0),
top: const BorderSide(width: 3.0),
bottom: const BorderSide(width: 5.0),
right: const BorderSide(width: 7.0),
).dimensions,
const EdgeInsets.fromLTRB(2.0, 3.0, 7.0, 5.0),
);
});
test('Border.isUniform', () {
expect(
const Border(
left: const BorderSide(width: 3.0),
top: const BorderSide(width: 3.0),
right: const BorderSide(width: 3.0),
bottom: const BorderSide(width: 3.1),
).isUniform,
false,
);
expect(
const Border(
left: const BorderSide(width: 3.0),
top: const BorderSide(width: 3.0),
right: const BorderSide(width: 3.0),
bottom: const BorderSide(width: 3.0),
).isUniform,
true,
);
expect(
const Border(
left: const BorderSide(color: const Color(0xFFFFFFFE)),
top: const BorderSide(color: const Color(0xFFFFFFFF)),
right: const BorderSide(color: const Color(0xFFFFFFFF)),
bottom: const BorderSide(color: const Color(0xFFFFFFFF)),
).isUniform,
false,
);
expect(
const Border(
left: const BorderSide(color: const Color(0xFFFFFFFF)),
top: const BorderSide(color: const Color(0xFFFFFFFF)),
right: const BorderSide(color: const Color(0xFFFFFFFF)),
bottom: const BorderSide(color: const Color(0xFFFFFFFF)),
).isUniform,
true,
);
expect(
const Border(
left: const BorderSide(style: BorderStyle.none),
top: const BorderSide(style: BorderStyle.none),
right: const BorderSide(style: BorderStyle.none),
bottom: const BorderSide(style: BorderStyle.solid, width: 0.0),
).isUniform,
false,
);
expect(
const Border(
left: const BorderSide(style: BorderStyle.none),
top: const BorderSide(style: BorderStyle.none),
right: const BorderSide(style: BorderStyle.none),
bottom: const BorderSide(style: BorderStyle.solid, width: 0.0),
).isUniform,
false,
);
expect(
const Border(
left: const BorderSide(style: BorderStyle.none),
top: const BorderSide(style: BorderStyle.none),
right: const BorderSide(style: BorderStyle.none),
bottom: BorderSide.none,
).isUniform,
false,
);
expect(
const Border(
left: const BorderSide(style: BorderStyle.none, width: 0.0),
top: const BorderSide(style: BorderStyle.none, width: 0.0),
right: const BorderSide(style: BorderStyle.none, width: 0.0),
bottom: BorderSide.none,
).isUniform,
true,
);
expect(
const Border().isUniform,
true,
);
});
test('Border.lerp', () {
final Border visualWithTop10 = const Border(top: const BorderSide(width: 10.0));
final Border atMinus100 = const Border(left: const BorderSide(width: 0.0), right: const BorderSide(width: 300.0));
final Border at0 = const Border(left: const BorderSide(width: 100.0), right: const BorderSide(width: 200.0));
final Border at25 = const Border(left: const BorderSide(width: 125.0), right: const BorderSide(width: 175.0));
final Border at75 = const Border(left: const BorderSide(width: 175.0), right: const BorderSide(width: 125.0));
final Border at100 = const Border(left: const BorderSide(width: 200.0), right: const BorderSide(width: 100.0));
final Border at200 = const Border(left: const BorderSide(width: 300.0), right: const BorderSide(width: 0.0));
expect(Border.lerp(null, null, -1.0), null);
expect(Border.lerp(visualWithTop10, null, -1.0), const Border(top: const BorderSide(width: 20.0)));
expect(Border.lerp(null, visualWithTop10, -1.0), const Border());
expect(Border.lerp(at0, at100, -1.0), atMinus100);
expect(Border.lerp(null, null, 0.0), null);
expect(Border.lerp(visualWithTop10, null, 0.0), const Border(top: const BorderSide(width: 10.0)));
expect(Border.lerp(null, visualWithTop10, 0.0), const Border());
expect(Border.lerp(at0, at100, 0.0), at0);
expect(Border.lerp(null, null, 0.25), null);
expect(Border.lerp(visualWithTop10, null, 0.25), const Border(top: const BorderSide(width: 7.5)));
expect(Border.lerp(null, visualWithTop10, 0.25), const Border(top: const BorderSide(width: 2.5)));
expect(Border.lerp(at0, at100, 0.25), at25);
expect(Border.lerp(null, null, 0.75), null);
expect(Border.lerp(visualWithTop10, null, 0.75), const Border(top: const BorderSide(width: 2.5)));
expect(Border.lerp(null, visualWithTop10, 0.75), const Border(top: const BorderSide(width: 7.5)));
expect(Border.lerp(at0, at100, 0.75), at75);
expect(Border.lerp(null, null, 1.0), null);
expect(Border.lerp(visualWithTop10, null, 1.0), const Border());
expect(Border.lerp(null, visualWithTop10, 1.0), const Border(top: const BorderSide(width: 10.0)));
expect(Border.lerp(at0, at100, 1.0), at100);
expect(Border.lerp(null, null, 2.0), null);
expect(Border.lerp(visualWithTop10, null, 2.0), const Border());
expect(Border.lerp(null, visualWithTop10, 2.0), const Border(top: const BorderSide(width: 20.0)));
expect(Border.lerp(at0, at100, 2.0), at200);
});
}