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
// Copyright 2016 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/widgets.dart';
import '../flutter_test_alternative.dart';
void main() {
test('TextSpan equals', () {
const TextSpan a1 = TextSpan(text: 'a');
const TextSpan a2 = TextSpan(text: 'a');
const TextSpan b1 = TextSpan(children: <TextSpan>[ a1 ]);
const TextSpan b2 = TextSpan(children: <TextSpan>[ a2 ]);
const TextSpan c1 = TextSpan(text: null);
const TextSpan c2 = TextSpan(text: null);
expect(a1 == a2, isTrue);
expect(b1 == b2, isTrue);
expect(c1 == c2, isTrue);
expect(a1 == b2, isFalse);
expect(b1 == c2, isFalse);
expect(c1 == a2, isFalse);
expect(a1 == c2, isFalse);
expect(b1 == a2, isFalse);
expect(c1 == b2, isFalse);
});
test('TextSpan toStringDeep', () {
const TextSpan test = TextSpan(
text: 'a',
style: TextStyle(
fontSize: 10.0,
),
children: <TextSpan>[
TextSpan(
text: 'b',
children: <TextSpan>[
TextSpan(),
],
),
null,
TextSpan(
text: 'c',
),
],
);
expect(test.toStringDeep(), equals(
'TextSpan:\n'
' inherit: true\n'
' size: 10.0\n'
' "a"\n'
' TextSpan:\n'
' "b"\n'
' TextSpan:\n'
' (empty)\n'
' <null child>\n'
' TextSpan:\n'
' "c"\n'
));
});
test('TextSpan toPlainText', () {
const TextSpan textSpan = TextSpan(
text: 'a',
children: <TextSpan>[
TextSpan(text: 'b'),
TextSpan(text: 'c'),
],
);
expect(textSpan.toPlainText(), 'abc');
});
test('WidgetSpan toPlainText', () {
const TextSpan textSpan = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(child: SizedBox(width: 10, height: 10)),
TextSpan(text: 'c'),
],
);
expect(textSpan.toPlainText(), 'ab\uFFFCc');
});
test('TextSpan toPlainText with semanticsLabel', () {
const TextSpan textSpan = TextSpan(
text: 'a',
children: <TextSpan>[
TextSpan(text: 'b', semanticsLabel: 'foo'),
TextSpan(text: 'c'),
],
);
expect(textSpan.toPlainText(), 'afooc');
expect(textSpan.toPlainText(includeSemanticsLabels: false), 'abc');
});
test('TextSpan widget change test', () {
const TextSpan textSpan1 = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(child: SizedBox(width: 10, height: 10)),
TextSpan(text: 'c'),
],
);
const TextSpan textSpan2 = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(child: SizedBox(width: 10, height: 10)),
TextSpan(text: 'c'),
],
);
const TextSpan textSpan3 = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(child: SizedBox(width: 11, height: 10)),
TextSpan(text: 'c'),
],
);
const TextSpan textSpan4 = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(child: Text('test')),
TextSpan(text: 'c'),
],
);
const TextSpan textSpan5 = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(child: Text('different!')),
TextSpan(text: 'c'),
],
);
const TextSpan textSpan6 = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(
child: SizedBox(width: 10, height: 10),
alignment: PlaceholderAlignment.top,
),
TextSpan(text: 'c'),
],
);
expect(textSpan1.compareTo(textSpan3), RenderComparison.layout);
expect(textSpan1.compareTo(textSpan4), RenderComparison.layout);
expect(textSpan1.compareTo(textSpan1), RenderComparison.identical);
expect(textSpan2.compareTo(textSpan2), RenderComparison.identical);
expect(textSpan3.compareTo(textSpan3), RenderComparison.identical);
expect(textSpan2.compareTo(textSpan3), RenderComparison.layout);
expect(textSpan4.compareTo(textSpan5), RenderComparison.layout);
expect(textSpan3.compareTo(textSpan5), RenderComparison.layout);
expect(textSpan2.compareTo(textSpan5), RenderComparison.layout);
expect(textSpan1.compareTo(textSpan5), RenderComparison.layout);
expect(textSpan1.compareTo(textSpan6), RenderComparison.layout);
});
test('TextSpan nested widget change test', () {
const TextSpan textSpan1 = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(
child: Text.rich(
TextSpan(
children: <InlineSpan>[
WidgetSpan(child: SizedBox(width: 10, height: 10)),
TextSpan(text: 'The sky is falling :)')
],
)
),
),
TextSpan(text: 'c'),
],
);
const TextSpan textSpan2 = TextSpan(
text: 'a',
children: <InlineSpan>[
TextSpan(text: 'b'),
WidgetSpan(
child: Text.rich(
TextSpan(
children: <InlineSpan>[
WidgetSpan(child: SizedBox(width: 10, height: 11)),
TextSpan(text: 'The sky is falling :)')
],
)
),
),
TextSpan(text: 'c'),
],
);
expect(textSpan1.compareTo(textSpan2), RenderComparison.layout);
expect(textSpan1.compareTo(textSpan1), RenderComparison.identical);
expect(textSpan2.compareTo(textSpan2), RenderComparison.identical);
});
}