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
b5eac042
Unverified
Commit
b5eac042
authored
Dec 19, 2017
by
Yegor
Committed by
GitHub
Dec 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use different delimiter for generated code; print generated code into mismatch description (#13667)
parent
e6f20eb9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
34 deletions
+58
-34
semantics_tester.dart
packages/flutter/test/widgets/semantics_tester.dart
+53
-29
semantics_tester_generateTestSemanticsExpressionForCurrentSemanticsTree_test.dart
...eTestSemanticsExpressionForCurrentSemanticsTree_test.dart
+5
-5
No files found.
packages/flutter/test/widgets/semantics_tester.dart
View file @
b5eac042
...
...
@@ -274,25 +274,35 @@ class TestSemantics {
String
toString
([
int
indentAmount
=
0
])
{
final
String
indent
=
' '
*
indentAmount
;
final
StringBuffer
buf
=
new
StringBuffer
();
buf
.
writeln
(
'
$
indent$runtimeType
{
'
);
buf
.
writeln
(
'
$
{indent}
new
$runtimeType
(
'
);
if
(
id
!=
null
)
buf
.
writeln
(
'
$indent
id:
$id
'
);
buf
.
writeln
(
'
$indent
flags:
$flags
'
);
buf
.
writeln
(
'
$indent
actions:
$actions
'
);
if
(
label
!=
null
)
buf
.
writeln
(
'
$indent
label: "
$label
"'
);
buf
.
writeln
(
'
$indent
id:
$id
,'
);
if
(
flags
is
int
&&
flags
!=
0
||
flags
is
List
<
SemanticsFlags
>
&&
flags
.
isNotEmpty
)
buf
.
writeln
(
'
$indent
flags:
${SemanticsTester._flagsToSemanticsFlagsExpression(flags)}
,'
);
if
(
actions
is
int
&&
actions
!=
0
||
actions
is
List
<
SemanticsAction
>
&&
actions
.
isNotEmpty
)
buf
.
writeln
(
'
$indent
actions:
${SemanticsTester._actionsToSemanticsActionExpression(actions)}
,'
);
if
(
label
!=
null
&&
label
!=
''
)
buf
.
writeln
(
'
$indent
label:
\'
$label
\'
,'
);
if
(
value
!=
null
&&
value
!=
''
)
buf
.
writeln
(
'
$indent
value:
\'
$value
\'
,'
);
if
(
increasedValue
!=
null
&&
increasedValue
!=
''
)
buf
.
writeln
(
'
$indent
increasedValue:
\'
$increasedValue
\'
,'
);
if
(
decreasedValue
!=
null
&&
decreasedValue
!=
''
)
buf
.
writeln
(
'
$indent
decreasedValue:
\'
$decreasedValue
\'
,'
);
if
(
hint
!=
null
&&
hint
!=
''
)
buf
.
writeln
(
'
$indent
hint:
\'
$hint
\'
,'
);
if
(
textDirection
!=
null
)
buf
.
writeln
(
'
$indent
textDirection:
$textDirection
'
);
buf
.
writeln
(
'
$indent
textDirection:
$textDirection
,
'
);
if
(
rect
!=
null
)
buf
.
writeln
(
'
$indent
rect:
$rect
'
);
buf
.
writeln
(
'
$indent
rect:
$rect
,
'
);
if
(
transform
!=
null
)
buf
.
writeln
(
'
$indent
transform:
\n
${transform.toString().trim().split('\n').map((String line) => '$indent $line').join('\n')}
'
);
buf
.
writeln
(
'
$indent
children: ['
);
buf
.
writeln
(
'
$indent
transform:
\n
${transform.toString().trim().split('\n').map((String line) => '$indent $line').join('\n')}
,
'
);
buf
.
writeln
(
'
$indent
children:
<TestSemantics>
['
);
for
(
TestSemantics
child
in
children
)
{
buf
.
writeln
(
child
.
toString
(
indentAmount
+
2
)
);
buf
.
writeln
(
'
${child.toString(indentAmount + 2)}
,'
);
}
buf
.
writeln
(
'
$indent
]'
);
buf
.
write
(
'
$indent
}
'
);
buf
.
writeln
(
'
$indent
]
,
'
);
buf
.
write
(
'
$indent
)
'
);
return
buf
.
toString
();
}
}
...
...
@@ -418,29 +428,39 @@ class SemanticsTester {
return
_generateSemanticsTestForNode
(
node
,
0
);
}
String
_flagsToSemanticsFlagsExpression
(
int
bitmap
)
{
return
SemanticsFlags
.
values
.
values
.
where
((
SemanticsFlags
flag
)
=>
(
flag
.
index
&
bitmap
)
!=
0
)
.
join
(
', '
);
static
String
_flagsToSemanticsFlagsExpression
(
dynamic
flags
)
{
Iterable
<
SemanticsFlags
>
list
;
if
(
flags
is
int
)
{
list
=
SemanticsFlags
.
values
.
values
.
where
((
SemanticsFlags
flag
)
=>
(
flag
.
index
&
flags
)
!=
0
);
}
else
{
list
=
flags
;
}
return
'<SemanticsFlags>[
${list.join(', ')}
]'
;
}
String
_actionsToSemanticsActionExpression
(
int
bitmap
)
{
return
SemanticsAction
.
values
.
values
.
where
((
SemanticsAction
action
)
=>
(
action
.
index
&
bitmap
)
!=
0
)
.
join
(
', '
);
static
String
_actionsToSemanticsActionExpression
(
dynamic
actions
)
{
Iterable
<
SemanticsAction
>
list
;
if
(
actions
is
int
)
{
list
=
SemanticsAction
.
values
.
values
.
where
((
SemanticsAction
action
)
=>
(
action
.
index
&
actions
)
!=
0
);
}
else
{
list
=
actions
;
}
return
'<SemanticsAction>[
${list.join(', ')}
]'
;
}
/// Recursively generates [TestSemantics] code for [node] and its children,
/// indenting the expression by `indentAmount`.
String
_generateSemanticsTestForNode
(
SemanticsNode
node
,
int
indentAmount
)
{
static
String
_generateSemanticsTestForNode
(
SemanticsNode
node
,
int
indentAmount
)
{
final
String
indent
=
' '
*
indentAmount
;
final
StringBuffer
buf
=
new
StringBuffer
();
final
SemanticsData
nodeData
=
node
.
getSemanticsData
();
buf
.
writeln
(
'new TestSemantics('
);
if
(
nodeData
.
flags
!=
0
)
buf
.
writeln
(
' flags:
<SemanticsFlags>[
${_flagsToSemanticsFlagsExpression(nodeData.flags)}
]
,'
);
buf
.
writeln
(
' flags:
${_flagsToSemanticsFlagsExpression(nodeData.flags)}
,'
);
if
(
nodeData
.
actions
!=
0
)
buf
.
writeln
(
' actions:
<SemanticsAction>[
${_actionsToSemanticsActionExpression(nodeData.actions)}
]
,'
);
buf
.
writeln
(
' actions:
${_actionsToSemanticsActionExpression(nodeData.actions)}
,'
);
if
(
node
.
label
!=
null
&&
node
.
label
.
isNotEmpty
)
buf
.
writeln
(
' label: r
\'
${node.label}
\'
,'
);
if
(
node
.
value
!=
null
&&
node
.
value
.
isNotEmpty
)
...
...
@@ -480,7 +500,11 @@ class _HasSemantics extends Matcher {
@override
bool
matches
(
covariant
SemanticsTester
item
,
Map
<
dynamic
,
dynamic
>
matchState
)
{
return
_semantics
.
_matches
(
item
.
tester
.
binding
.
pipelineOwner
.
semanticsOwner
.
rootSemanticsNode
,
matchState
,
ignoreTransform:
ignoreTransform
,
ignoreRect:
ignoreRect
,
ignoreId:
ignoreId
);
final
bool
doesMatch
=
_semantics
.
_matches
(
item
.
tester
.
binding
.
pipelineOwner
.
semanticsOwner
.
rootSemanticsNode
,
matchState
,
ignoreTransform:
ignoreTransform
,
ignoreRect:
ignoreRect
,
ignoreId:
ignoreId
);
if
(!
doesMatch
)
{
matchState
[
'would-match'
]
=
item
.
generateTestSemanticsExpressionForCurrentSemanticsTree
();
}
return
doesMatch
;
}
@override
...
...
@@ -492,10 +516,10 @@ class _HasSemantics extends Matcher {
Description
describeMismatch
(
dynamic
item
,
Description
mismatchDescription
,
Map
<
dynamic
,
dynamic
>
matchState
,
bool
verbose
)
{
return
mismatchDescription
.
add
(
'
${matchState[TestSemantics]}
\n
'
)
.
add
(
'Current SemanticsNode tree:
\n
'
)
.
add
(
RendererBinding
.
instance
?.
renderView
?.
debugSemantics
?.
toStringDeep
(
childOrder:
DebugSemanticsDumpOrder
.
inverseHitTest
)
);
.
add
(
'Current SemanticsNode tree:
\n
'
)
.
add
(
RendererBinding
.
instance
?.
renderView
?.
debugSemantics
?.
toStringDeep
(
childOrder:
DebugSemanticsDumpOrder
.
inverseHitTest
))
.
add
(
'The semantics tree would have matched the following configuration:
\n
'
)
.
add
(
matchState
[
'would-match'
]
);
}
}
...
...
packages/flutter/test/widgets/semantics_tester_generateTestSemanticsExpressionForCurrentSemanticsTree_test.dart
View file @
b5eac042
...
...
@@ -79,8 +79,8 @@ void _tests() {
expect
(
thisTestFile
,
isNotNull
);
String
expectedCode
=
thisTestFile
.
readAsStringSync
();
expectedCode
=
expectedCode
.
substring
(
expectedCode
.
indexOf
(
'
>
'
*
12
)
+
12
,
expectedCode
.
indexOf
(
'
<
'
*
12
)
-
3
,
expectedCode
.
indexOf
(
'
v
'
*
12
)
+
12
,
expectedCode
.
indexOf
(
'
^
'
*
12
)
-
3
,
)
.
split
(
'
\n
'
)
.
map
((
String
line
)
=>
line
.
trim
())
...
...
@@ -96,12 +96,12 @@ void _tests() {
expect
(
semantics
,
hasSemantics
(
// The code below delimited by
> and <
characters is generated by
// The code below delimited by
"v" and "^"
characters is generated by
// generateTestSemanticsExpressionForCurrentSemanticsTree function.
// You must update it when changing the output generated by
// generateTestSemanticsExpressionForCurrentSemanticsTree. Otherwise,
// the test 'generates code', defined above, will fail.
//
>>>>>>>>>>>>
//
vvvvvvvvvvvv
new
TestSemantics
(
children:
<
TestSemantics
>[
new
TestSemantics
(
...
...
@@ -128,7 +128,7 @@ void _tests() {
),
],
),
//
<<<<<<<<<<<<
//
^^^^^^^^^^^^
ignoreRect:
true
,
ignoreTransform:
true
,
ignoreId:
true
,
...
...
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