Skip to content

Commit daaf3af

Browse files
jacob314gspencergoog
authored andcommitted
Switch existings tests to use equalsIgnoringHashCodes and add more tests. (flutter#10954)
* Switch existings tests to use equalsIgnoringHashCodes and add more tests.
1 parent 1cc7761 commit daaf3af

16 files changed

+811
-61
lines changed

packages/flutter/lib/src/rendering/object.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
27552755
void debugFillDescription(List<String> description) {
27562756
if (debugCreator != null)
27572757
description.add('creator: $debugCreator');
2758-
description.add('parentData: $parentData${ _debugCanParentUseSize ? " (can use size)" : ""}');
2758+
description.add('parentData: $parentData${ _debugCanParentUseSize == true ? " (can use size)" : ""}');
27592759
description.add('constraints: $constraints');
27602760
if (_layer != null) // don't access it via the "layer" getter since that's only valid when we don't need paint
27612761
description.add('layer: $_layer');

packages/flutter/test/foundation/tree_diagnostics_mixin_test.dart

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'package:flutter/foundation.dart';
6-
import 'package:test/test.dart';
6+
import 'package:flutter_test/flutter_test.dart';
77

88
class TestTree extends Object with TreeDiagnosticsMixin {
99
TestTree({
@@ -40,20 +40,26 @@ void main() {
4040
],
4141
);
4242

43-
final String dump =
44-
tree.toStringDeep().replaceAll(new RegExp(r'#[0-9a-z]{5}'), '#000');
45-
expect(dump, equals('''TestTree#000
46-
├─child node A: TestTree#000
43+
// The final line in the tree is a problem as it contains nothing but
44+
// a vertical line character.
45+
expect(tree, isNot(hasAGoodToStringDeep));
46+
expect(
47+
tree.toStringDeep(),
48+
equalsIgnoringHashCodes(
49+
'''TestTree#00000
50+
├─child node A: TestTree#00000
4751
48-
├─child node B: TestTree#000
49-
│ ├─child node B1: TestTree#000
52+
├─child node B: TestTree#00000
53+
│ ├─child node B1: TestTree#00000
5054
│ │
51-
│ ├─child node B2: TestTree#000
55+
│ ├─child node B2: TestTree#00000
5256
│ │
53-
│ ├─child node B3: TestTree#000
57+
│ ├─child node B3: TestTree#00000
5458
│ │
55-
├─child node C: TestTree#000
59+
├─child node C: TestTree#00000
5660
57-
'''));
61+
''',
62+
),
63+
);
5864
});
5965
}

packages/flutter/test/rendering/box_test.dart

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'package:flutter/material.dart';
66
import 'package:flutter/rendering.dart';
7-
import 'package:test/test.dart';
7+
import 'package:flutter_test/flutter_test.dart';
88

99
import 'rendering_tester.dart';
1010

@@ -69,6 +69,17 @@ void main() {
6969
final RenderBox coloredBox = new RenderDecoratedBox(
7070
decoration: const BoxDecoration(),
7171
);
72+
73+
expect(coloredBox, hasAGoodToStringDeep);
74+
expect(coloredBox.toStringDeep(), equalsIgnoringHashCodes(
75+
'RenderDecoratedBox#00000 NEEDS-LAYOUT NEEDS-PAINT DETACHED\n'
76+
' parentData: null\n'
77+
' constraints: null\n'
78+
' size: MISSING\n'
79+
' decoration:\n'
80+
' <no decorations specified>\n'
81+
' configuration: ImageConfiguration()\n'));
82+
7283
final RenderBox paddingBox = new RenderPadding(
7384
padding: const EdgeInsets.all(10.0),
7485
child: coloredBox,
@@ -80,6 +91,20 @@ void main() {
8091
layout(root);
8192
expect(coloredBox.size.width, equals(780.0));
8293
expect(coloredBox.size.height, equals(580.0));
94+
95+
expect(coloredBox, hasAGoodToStringDeep);
96+
expect(
97+
coloredBox.toStringDeep(),
98+
equalsIgnoringHashCodes(
99+
'RenderDecoratedBox#00000 NEEDS-PAINT\n'
100+
' parentData: offset=Offset(10.0, 10.0) (can use size)\n'
101+
' constraints: BoxConstraints(w=780.0, h=580.0)\n'
102+
' size: Size(780.0, 580.0)\n'
103+
' decoration:\n'
104+
' <no decorations specified>\n'
105+
' configuration: ImageConfiguration()\n',
106+
),
107+
);
83108
});
84109

85110
test("reparenting should clear position", () {

packages/flutter/test/rendering/limited_box_test.dart

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'package:flutter/material.dart';
66
import 'package:flutter/rendering.dart';
7-
import 'package:test/test.dart';
7+
import 'package:flutter_test/flutter_test.dart';
88

99
import 'rendering_tester.dart';
1010

@@ -27,6 +27,35 @@ void main() {
2727
layout(parent);
2828
expect(child.size.width, 100.0);
2929
expect(child.size.height, 200.0);
30+
31+
expect(parent, hasAGoodToStringDeep);
32+
expect(
33+
parent.toStringDeep(),
34+
equalsIgnoringHashCodes(
35+
'RenderConstrainedOverflowBox#00000 NEEDS-PAINT\n'
36+
' │ parentData: <none>\n'
37+
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
38+
' │ size: Size(800.0, 600.0)\n'
39+
' │ alignment: FractionalOffset(0.5, 0.5)\n'
40+
' │ minWidth: 0.0\n'
41+
' │ maxWidth: Infinity\n'
42+
' │ minHeight: 0.0\n'
43+
' │ maxHeight: Infinity\n'
44+
' │\n'
45+
' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT\n'
46+
' │ parentData: offset=Offset(350.0, 200.0) (can use size)\n'
47+
' │ constraints: BoxConstraints(unconstrained)\n'
48+
' │ size: Size(100.0, 200.0)\n'
49+
' │ maxWidth: 100.0\n'
50+
' │ maxHeight: 200.0\n'
51+
' │\n'
52+
' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2 NEEDS-PAINT\n'
53+
' parentData: <none> (can use size)\n'
54+
' constraints: BoxConstraints(0.0<=w<=100.0, 0.0<=h<=200.0)\n'
55+
' size: Size(100.0, 200.0)\n'
56+
' additionalConstraints: BoxConstraints(w=300.0, h=400.0)\n',
57+
),
58+
);
3059
});
3160

3261
test('LimitedBox: parent maxWidth is unconstrained', () {
@@ -84,5 +113,65 @@ void main() {
84113
);
85114
layout(parent);
86115
expect(box.size, const Size(10.0, 0.0));
116+
117+
expect(parent, hasAGoodToStringDeep);
118+
expect(
119+
parent.toStringDeep(),
120+
equalsIgnoringHashCodes(
121+
'RenderConstrainedOverflowBox#00000 NEEDS-PAINT\n'
122+
' │ parentData: <none>\n'
123+
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
124+
' │ size: Size(800.0, 600.0)\n'
125+
' │ alignment: FractionalOffset(0.5, 0.5)\n'
126+
' │ minWidth: 10.0\n'
127+
' │ maxWidth: 500.0\n'
128+
' │ minHeight: 0.0\n'
129+
' │ maxHeight: Infinity\n'
130+
' │\n'
131+
' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT\n'
132+
' parentData: offset=Offset(395.0, 300.0) (can use size)\n'
133+
' constraints: BoxConstraints(10.0<=w<=500.0, 0.0<=h<=Infinity)\n'
134+
' size: Size(10.0, 0.0)\n'
135+
' maxWidth: 100.0\n'
136+
' maxHeight: 200.0\n',
137+
),
138+
);
87139
});
140+
141+
test('LimitedBox: no child use parent', () {
142+
RenderBox box;
143+
final RenderBox parent = new RenderConstrainedOverflowBox(
144+
minWidth: 10.0,
145+
child: box = new RenderLimitedBox(
146+
maxWidth: 100.0,
147+
maxHeight: 200.0,
148+
)
149+
);
150+
layout(parent);
151+
expect(box.size, const Size(10.0, 600.0));
152+
153+
expect(parent, hasAGoodToStringDeep);
154+
expect(
155+
parent.toStringDeep(),
156+
equalsIgnoringHashCodes(
157+
'RenderConstrainedOverflowBox#00000 NEEDS-PAINT\n'
158+
' │ parentData: <none>\n'
159+
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
160+
' │ size: Size(800.0, 600.0)\n'
161+
' │ alignment: FractionalOffset(0.5, 0.5)\n'
162+
' │ minWidth: 10.0\n'
163+
' │ maxWidth: use parent maxWidth constraint\n'
164+
' │ minHeight: use parent minHeight constraint\n'
165+
' │ maxHeight: use parent maxHeight constraint\n'
166+
' │\n'
167+
' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT\n'
168+
' parentData: offset=Offset(395.0, 0.0) (can use size)\n'
169+
' constraints: BoxConstraints(10.0<=w<=800.0, h=600.0)\n'
170+
' size: Size(10.0, 600.0)\n'
171+
' maxWidth: 100.0\n'
172+
' maxHeight: 200.0\n',
173+
),
174+
);
175+
});
176+
88177
}

packages/flutter/test/rendering/paragraph_test.dart

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'dart:ui' as ui show TextBox;
66

77
import 'package:flutter/rendering.dart';
88
import 'package:flutter/services.dart';
9-
import 'package:test/test.dart';
9+
import 'package:flutter_test/flutter_test.dart';
1010

1111
import 'rendering_tester.dart';
1212

@@ -149,7 +149,6 @@ void main() {
149149
expect(paragraph.debugHasOverflowShader, isFalse);
150150
});
151151

152-
153152
test('maxLines', () {
154153
final RenderParagraph paragraph = new RenderParagraph(
155154
const TextSpan(
@@ -177,5 +176,30 @@ void main() {
177176
layoutAt(3);
178177
expect(paragraph.size.height, 30.0);
179178
});
180-
}
181179

180+
test('toStringDeep', () {
181+
final RenderParagraph paragraph = new RenderParagraph(
182+
const TextSpan(text: _kText),
183+
);
184+
// TODO(jacobr): the toStringDeep method for RenderParagraph needs to be
185+
// fixed to not emit a spurious line of trailing whitespace and fixed so
186+
// that the \n within the TextSpan content does not interfere with the box
187+
// border.
188+
expect(paragraph, isNot(hasAGoodToStringDeep));
189+
expect(
190+
paragraph.toStringDeep(),
191+
equalsIgnoringHashCodes(
192+
'RenderParagraph#00000 NEEDS-LAYOUT NEEDS-PAINT DETACHED\n'
193+
' │ parentData: null\n'
194+
' │ constraints: null\n'
195+
' │ size: MISSING\n'
196+
' ╘═╦══ text ═══\n'
197+
' ║ TextSpan:\n'
198+
' ║ "I polished up that handle so carefullee\n'
199+
'That now I am the Ruler of the Queen\'s Navee!"\n'
200+
' ╚═══════════\n'
201+
'\n',
202+
),
203+
);
204+
});
205+
}

packages/flutter/test/rendering/table_test.dart

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'package:flutter/rendering.dart';
6-
import 'package:test/test.dart';
6+
import 'package:flutter_test/flutter_test.dart';
77

88
import 'rendering_tester.dart';
99

@@ -54,6 +54,71 @@ void main() {
5454
pumpFrame();
5555

5656
expect(table.size, equals(const Size(130.0, 230.0)));
57+
58+
expect(table, hasAGoodToStringDeep);
59+
expect(
60+
table.toStringDeep(),
61+
equalsIgnoringHashCodes(
62+
'RenderTable#00000 relayoutBoundary=up1 NEEDS-PAINT\n'
63+
' │ parentData: offset=Offset(335.0, 185.0) (can use size)\n'
64+
' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
65+
' │ size: Size(130.0, 230.0)\n'
66+
' │ default column width: IntrinsicColumnWidth\n'
67+
' │ table size: 5×5\n'
68+
' │ column offsets: [0.0, 10.0, 30.0, 130.0, 130.0]\n'
69+
' │ row offsets: [0.0, 30.0, 30.0, 30.0, 30.0, 230.0]\n'
70+
' │\n'
71+
' ├─child (0, 0): RenderConstrainedBox#00000 relayoutBoundary=up2 NEEDS-PAINT\n'
72+
' │ parentData: offset=Offset(0.0, 0.0); default vertical alignment\n'
73+
' │ (can use size)\n'
74+
' │ constraints: BoxConstraints(w=10.0, 0.0<=h<=Infinity)\n'
75+
' │ size: Size(10.0, 30.0)\n'
76+
' │ additionalConstraints: BoxConstraints(w=10.0, h=30.0)\n'
77+
' │\n'
78+
' ├─child (1, 0): RenderConstrainedBox#00000 relayoutBoundary=up2 NEEDS-PAINT\n'
79+
' │ parentData: offset=Offset(10.0, 0.0); default vertical alignment\n'
80+
' │ (can use size)\n'
81+
' │ constraints: BoxConstraints(w=20.0, 0.0<=h<=Infinity)\n'
82+
' │ size: Size(20.0, 20.0)\n'
83+
' │ additionalConstraints: BoxConstraints(w=20.0, h=20.0)\n'
84+
' │\n'
85+
' ├─child (2, 0): RenderConstrainedBox#00000 relayoutBoundary=up2 NEEDS-PAINT\n'
86+
' │ parentData: offset=Offset(30.0, 0.0); default vertical alignment\n'
87+
' │ (can use size)\n'
88+
' │ constraints: BoxConstraints(w=100.0, 0.0<=h<=Infinity)\n'
89+
' │ size: Size(100.0, 10.0)\n'
90+
' │ additionalConstraints: BoxConstraints(w=30.0, h=10.0)\n'
91+
' │\n'
92+
' ├─child (3, 0) is null\n'
93+
' ├─child (4, 0) is null\n'
94+
' ├─child (0, 1) is null\n'
95+
' ├─child (1, 1) is null\n'
96+
' ├─child (2, 1) is null\n'
97+
' ├─child (3, 1) is null\n'
98+
' ├─child (4, 1) is null\n'
99+
' ├─child (0, 2) is null\n'
100+
' ├─child (1, 2) is null\n'
101+
' ├─child (2, 2) is null\n'
102+
' ├─child (3, 2) is null\n'
103+
' ├─child (4, 2) is null\n'
104+
' ├─child (0, 3) is null\n'
105+
' ├─child (1, 3) is null\n'
106+
' ├─child (2, 3) is null\n'
107+
' ├─child (3, 3) is null\n'
108+
' ├─child (4, 3) is null\n'
109+
' ├─child (0, 4) is null\n'
110+
' ├─child (1, 4) is null\n'
111+
' ├─child (2, 4): RenderConstrainedBox#00000 relayoutBoundary=up2 NEEDS-PAINT\n'
112+
' │ parentData: offset=Offset(30.0, 30.0); default vertical alignment\n'
113+
' │ (can use size)\n'
114+
' │ constraints: BoxConstraints(w=100.0, 0.0<=h<=Infinity)\n'
115+
' │ size: Size(100.0, 200.0)\n'
116+
' │ additionalConstraints: BoxConstraints(w=100.0, h=200.0)\n'
117+
' │\n'
118+
' ├─child (3, 4) is null\n'
119+
' └─child (4, 4) is null\n',
120+
),
121+
);
57122
});
58123

59124
test('Table test: removing cells', () {

packages/flutter/test/widgets/animated_container_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,41 @@ void main() {
6565

6666
actualDecoration = box.decoration;
6767
expect(actualDecoration.color, equals(decorationB.color));
68+
69+
expect(box, hasAGoodToStringDeep);
70+
expect(
71+
box.toStringDeep(),
72+
equalsIgnoringHashCodes(
73+
'RenderDecoratedBox#00000\n'
74+
' │ creator: DecoratedBox ← Container ←\n'
75+
' │ AnimatedContainer-[GlobalKey#00000] ← [root]\n'
76+
' │ parentData: <none>\n'
77+
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
78+
' │ size: Size(800.0, 600.0)\n'
79+
' │ decoration:\n'
80+
' │ color: Color(0xff0000ff)\n'
81+
' │ configuration: ImageConfiguration(bundle:\n'
82+
' │ PlatformAssetBundle#00000(), devicePixelRatio: 1.0, platform:\n'
83+
' │ android)\n'
84+
' │\n'
85+
' └─child: RenderLimitedBox#00000\n'
86+
' │ creator: LimitedBox ← DecoratedBox ← Container ←\n'
87+
' │ AnimatedContainer-[GlobalKey#00000] ← [root]\n'
88+
' │ parentData: <none> (can use size)\n'
89+
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
90+
' │ size: Size(800.0, 600.0)\n'
91+
' │ maxWidth: 0.0\n'
92+
' │ maxHeight: 0.0\n'
93+
' │\n'
94+
' └─child: RenderConstrainedBox#00000\n'
95+
' creator: ConstrainedBox ← LimitedBox ← DecoratedBox ← Container ←\n'
96+
' AnimatedContainer-[GlobalKey#00000] ← [root]\n'
97+
' parentData: <none> (can use size)\n'
98+
' constraints: BoxConstraints(w=800.0, h=600.0)\n'
99+
' size: Size(800.0, 600.0)\n'
100+
' additionalConstraints: BoxConstraints(biggest)\n',
101+
),
102+
);
68103
});
69104

70105
testWidgets('AnimatedContainer overanimate test', (WidgetTester tester) async {

0 commit comments

Comments
 (0)