Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
37bc48f2
Unverified
Commit
37bc48f2
authored
Apr 22, 2019
by
Dan Field
Committed by
GitHub
Apr 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rectMoreOrLess equals, prep for 64bit rects (#30942)
* rectMoreOrLess equals, prep for 64bit rects
parent
783d80d7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
8 deletions
+44
-8
floating_action_button_location_test.dart
...r/test/material/floating_action_button_location_test.dart
+4
-4
scaffold_test.dart
packages/flutter/test/material/scaffold_test.dart
+4
-4
matchers.dart
packages/flutter_test/lib/src/matchers.dart
+19
-0
matchers_test.dart
packages/flutter_test/test/matchers_test.dart
+17
-0
No files found.
packages/flutter/test/material/floating_action_button_location_test.dart
View file @
37bc48f2
...
@@ -326,7 +326,7 @@ void main() {
...
@@ -326,7 +326,7 @@ void main() {
),
),
),
),
);
);
expect
(
tester
.
getRect
(
find
.
byType
(
FloatingActionButton
)),
Rect
.
fromLTWH
(
16.0
,
28.0
,
56.0
,
56.0
));
expect
(
tester
.
getRect
(
find
.
byType
(
FloatingActionButton
)),
rectMoreOrLessEquals
(
Rect
.
fromLTWH
(
16.0
,
28.0
,
56.0
,
56.0
)
));
});
});
testWidgets
(
'End-top floating action button location RTL'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'End-top floating action button location RTL'
,
(
WidgetTester
tester
)
async
{
...
@@ -342,7 +342,7 @@ void main() {
...
@@ -342,7 +342,7 @@ void main() {
),
),
),
),
);
);
expect
(
tester
.
getRect
(
find
.
byType
(
FloatingActionButton
)),
Rect
.
fromLTWH
(
16.0
,
28.0
,
56.0
,
56.0
));
expect
(
tester
.
getRect
(
find
.
byType
(
FloatingActionButton
)),
rectMoreOrLessEquals
(
Rect
.
fromLTWH
(
16.0
,
28.0
,
56.0
,
56.0
)
));
});
});
testWidgets
(
'Start-top floating action button location RTL'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Start-top floating action button location RTL'
,
(
WidgetTester
tester
)
async
{
...
@@ -358,7 +358,7 @@ void main() {
...
@@ -358,7 +358,7 @@ void main() {
),
),
),
),
);
);
expect
(
tester
.
getRect
(
find
.
byType
(
FloatingActionButton
)),
Rect
.
fromLTWH
(
800.0
-
56.0
-
16.0
,
28.0
,
56.0
,
56.0
));
expect
(
tester
.
getRect
(
find
.
byType
(
FloatingActionButton
)),
rectMoreOrLessEquals
(
Rect
.
fromLTWH
(
800.0
-
56.0
-
16.0
,
28.0
,
56.0
,
56.0
)
));
});
});
testWidgets
(
'End-top floating action button location LTR'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'End-top floating action button location LTR'
,
(
WidgetTester
tester
)
async
{
...
@@ -371,7 +371,7 @@ void main() {
...
@@ -371,7 +371,7 @@ void main() {
),
),
),
),
);
);
expect
(
tester
.
getRect
(
find
.
byType
(
FloatingActionButton
)),
Rect
.
fromLTWH
(
800.0
-
56.0
-
16.0
,
28.0
,
56.0
,
56.0
));
expect
(
tester
.
getRect
(
find
.
byType
(
FloatingActionButton
)),
rectMoreOrLessEquals
(
Rect
.
fromLTWH
(
800.0
-
56.0
-
16.0
,
28.0
,
56.0
,
56.0
)
));
});
});
}
}
...
...
packages/flutter/test/material/scaffold_test.dart
View file @
37bc48f2
...
@@ -762,13 +762,13 @@ void main() {
...
@@ -762,13 +762,13 @@ void main() {
expect
(
tester
.
getRect
(
find
.
byKey
(
appBar
)),
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
43.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
appBar
)),
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
43.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
body
)),
Rect
.
fromLTRB
(
0.0
,
43.0
,
800.0
,
348.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
body
)),
Rect
.
fromLTRB
(
0.0
,
43.0
,
800.0
,
348.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)),
Rect
.
fromLTRB
(
36.0
,
255.0
,
113.0
,
332.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)),
rectMoreOrLessEquals
(
Rect
.
fromLTRB
(
36.0
,
255.0
,
113.0
,
332.0
)
));
expect
(
tester
.
getRect
(
find
.
byKey
(
persistentFooterButton
)),
Rect
.
fromLTRB
(
28.0
,
357.0
,
128.0
,
447.0
));
// Note: has 8px each top/bottom padding.
expect
(
tester
.
getRect
(
find
.
byKey
(
persistentFooterButton
)),
Rect
.
fromLTRB
(
28.0
,
357.0
,
128.0
,
447.0
));
// Note: has 8px each top/bottom padding.
expect
(
tester
.
getRect
(
find
.
byKey
(
drawer
)),
Rect
.
fromLTRB
(
596.0
,
0.0
,
800.0
,
600.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
drawer
)),
Rect
.
fromLTRB
(
596.0
,
0.0
,
800.0
,
600.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
bottomNavigationBar
)),
Rect
.
fromLTRB
(
0.0
,
515.0
,
800.0
,
600.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
bottomNavigationBar
)),
Rect
.
fromLTRB
(
0.0
,
515.0
,
800.0
,
600.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideAppBar
)),
Rect
.
fromLTRB
(
20.0
,
30.0
,
750.0
,
43.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideAppBar
)),
Rect
.
fromLTRB
(
20.0
,
30.0
,
750.0
,
43.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideBody
)),
Rect
.
fromLTRB
(
20.0
,
43.0
,
750.0
,
348.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideBody
)),
Rect
.
fromLTRB
(
20.0
,
43.0
,
750.0
,
348.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideFloatingActionButton
)),
Rect
.
fromLTRB
(
36.0
,
255.0
,
113.0
,
332.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideFloatingActionButton
)),
rectMoreOrLessEquals
(
Rect
.
fromLTRB
(
36.0
,
255.0
,
113.0
,
332.0
)
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insidePersistentFooterButton
)),
Rect
.
fromLTRB
(
28.0
,
357.0
,
128.0
,
447.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insidePersistentFooterButton
)),
Rect
.
fromLTRB
(
28.0
,
357.0
,
128.0
,
447.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideDrawer
)),
Rect
.
fromLTRB
(
596.0
,
30.0
,
750.0
,
540.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideDrawer
)),
Rect
.
fromLTRB
(
596.0
,
30.0
,
750.0
,
540.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideBottomNavigationBar
)),
Rect
.
fromLTRB
(
20.0
,
515.0
,
750.0
,
540.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideBottomNavigationBar
)),
Rect
.
fromLTRB
(
20.0
,
515.0
,
750.0
,
540.0
));
...
@@ -857,12 +857,12 @@ void main() {
...
@@ -857,12 +857,12 @@ void main() {
expect
(
tester
.
getRect
(
find
.
byKey
(
appBar
)),
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
43.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
appBar
)),
Rect
.
fromLTRB
(
0.0
,
0.0
,
800.0
,
43.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
body
)),
Rect
.
fromLTRB
(
0.0
,
43.0
,
800.0
,
400.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
body
)),
Rect
.
fromLTRB
(
0.0
,
43.0
,
800.0
,
400.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)),
Rect
.
fromLTRB
(
36.0
,
307.0
,
113.0
,
384.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
floatingActionButton
)),
rectMoreOrLessEquals
(
Rect
.
fromLTRB
(
36.0
,
307.0
,
113.0
,
384.0
)
));
expect
(
tester
.
getRect
(
find
.
byKey
(
persistentFooterButton
)),
Rect
.
fromLTRB
(
28.0
,
442.0
,
128.0
,
532.0
));
// Note: has 8px each top/bottom padding.
expect
(
tester
.
getRect
(
find
.
byKey
(
persistentFooterButton
)),
Rect
.
fromLTRB
(
28.0
,
442.0
,
128.0
,
532.0
));
// Note: has 8px each top/bottom padding.
expect
(
tester
.
getRect
(
find
.
byKey
(
drawer
)),
Rect
.
fromLTRB
(
596.0
,
0.0
,
800.0
,
600.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
drawer
)),
Rect
.
fromLTRB
(
596.0
,
0.0
,
800.0
,
600.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideAppBar
)),
Rect
.
fromLTRB
(
20.0
,
30.0
,
750.0
,
43.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideAppBar
)),
Rect
.
fromLTRB
(
20.0
,
30.0
,
750.0
,
43.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideBody
)),
Rect
.
fromLTRB
(
20.0
,
43.0
,
750.0
,
400.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideBody
)),
Rect
.
fromLTRB
(
20.0
,
43.0
,
750.0
,
400.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideFloatingActionButton
)),
Rect
.
fromLTRB
(
36.0
,
307.0
,
113.0
,
384.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideFloatingActionButton
)),
rectMoreOrLessEquals
(
Rect
.
fromLTRB
(
36.0
,
307.0
,
113.0
,
384.0
)
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insidePersistentFooterButton
)),
Rect
.
fromLTRB
(
28.0
,
442.0
,
128.0
,
532.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insidePersistentFooterButton
)),
Rect
.
fromLTRB
(
28.0
,
442.0
,
128.0
,
532.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideDrawer
)),
Rect
.
fromLTRB
(
596.0
,
30.0
,
750.0
,
540.0
));
expect
(
tester
.
getRect
(
find
.
byKey
(
insideDrawer
)),
Rect
.
fromLTRB
(
596.0
,
30.0
,
750.0
,
540.0
));
});
});
...
...
packages/flutter_test/lib/src/matchers.dart
View file @
37bc48f2
...
@@ -222,6 +222,23 @@ Matcher moreOrLessEquals(double value, { double epsilon = 1e-10 }) {
...
@@ -222,6 +222,23 @@ Matcher moreOrLessEquals(double value, { double epsilon = 1e-10 }) {
return
_MoreOrLessEquals
(
value
,
epsilon
);
return
_MoreOrLessEquals
(
value
,
epsilon
);
}
}
/// Asserts that two [Rect]s are equal, within some tolerated error.
///
/// Two values are considered equal if the difference between them is within
/// 1e-10 of the larger one. This is an arbitrary value which can be adjusted
/// using the `epsilon` argument. This matcher is intended to compare floating
/// point numbers that are the result of different sequences of operations, such
/// that they may have accumulated slightly different errors.
///
/// See also:
///
/// * [moreOrLessEquals], which is for [double]s.
/// * [within], which offers a generic version of this functionality that can
/// be used to match [Rect]s as well as other types.
Matcher
rectMoreOrLessEquals
(
Rect
value
,
{
double
epsilon
=
1
e
-
10
})
{
return
_IsWithinDistance
<
Rect
>(
_rectDistance
,
value
,
epsilon
);
}
/// Asserts that two [String]s are equal after normalizing likely hash codes.
/// Asserts that two [String]s are equal after normalizing likely hash codes.
///
///
/// A `#` followed by 5 hexadecimal digits is assumed to be a short hash code
/// A `#` followed by 5 hexadecimal digits is assumed to be a short hash code
...
@@ -1004,6 +1021,8 @@ double _sizeDistance(Size a, Size b) {
...
@@ -1004,6 +1021,8 @@ double _sizeDistance(Size a, Size b) {
///
///
/// * [moreOrLessEquals], which is similar to this function, but specializes in
/// * [moreOrLessEquals], which is similar to this function, but specializes in
/// [double]s and has an optional `epsilon` parameter.
/// [double]s and has an optional `epsilon` parameter.
/// * [rectMoreOrLessEquals], which is similar to this function, but
/// specializes in [Rect]s and has an optional `epsilon` parameter.
/// * [closeTo], which specializes in numbers only.
/// * [closeTo], which specializes in numbers only.
Matcher
within
<
T
>({
Matcher
within
<
T
>({
@required
num
distance
,
@required
num
distance
,
...
...
packages/flutter_test/test/matchers_test.dart
View file @
37bc48f2
...
@@ -185,6 +185,23 @@ void main() {
...
@@ -185,6 +185,23 @@ void main() {
expect
(-
11.0
,
moreOrLessEquals
(
11.0
,
epsilon:
100.0
));
expect
(-
11.0
,
moreOrLessEquals
(
11.0
,
epsilon:
100.0
));
});
});
test
(
'rectMoreOrLessEquals'
,
()
{
expect
(
Rect
.
fromLTRB
(
0.0
,
0.0
,
10.0
,
10.0
),
rectMoreOrLessEquals
(
Rect
.
fromLTRB
(
1
e
-
11
,
0.0
,
10.0
,
10.0000000001
)),
);
expect
(
Rect
.
fromLTRB
(
11.0
,
11.0
,
20.0
,
20.0
),
isNot
(
rectMoreOrLessEquals
(
Rect
.
fromLTRB
(-
11.0
,
-
11.0
,
20.0
,
20.0
),
epsilon:
1.0
)),
);
expect
(
Rect
.
fromLTRB
(
11.0
,
11.0
,
20.0
,
20.0
),
rectMoreOrLessEquals
(
Rect
.
fromLTRB
(-
11.0
,
-
11.0
,
20.0
,
20.0
),
epsilon:
100.0
),
);
});
test
(
'within'
,
()
{
test
(
'within'
,
()
{
expect
(
0.0
,
within
<
double
>(
distance:
0.1
,
from:
0.05
));
expect
(
0.0
,
within
<
double
>(
distance:
0.1
,
from:
0.05
));
expect
(
0.0
,
isNot
(
within
<
double
>(
distance:
0.1
,
from:
0.2
)));
expect
(
0.0
,
isNot
(
within
<
double
>(
distance:
0.1
,
from:
0.2
)));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment