[driver] fix match state hand-off in matcher_util.dart (#3103)
Fixes https://github.com/flutter/flutter/issues/3094
This commit is contained in:
@@ -6,11 +6,12 @@ import 'package:matcher/matcher.dart';
|
||||
|
||||
/// Matches [value] against the [matcher].
|
||||
MatchResult match(dynamic value, Matcher matcher) {
|
||||
if (matcher.matches(value, {})) {
|
||||
Map<dynamic, dynamic> matchState = {};
|
||||
if (matcher.matches(value, matchState)) {
|
||||
return new MatchResult._matched();
|
||||
} else {
|
||||
Description description =
|
||||
matcher.describeMismatch(value, new _TextDescription(), {}, false);
|
||||
matcher.describeMismatch(value, new _TextDescription(), matchState, false);
|
||||
return new MatchResult._mismatched(description.toString());
|
||||
}
|
||||
}
|
||||
|
||||
53
packages/flutter_driver/test/src/matcher_util_test.dart
Normal file
53
packages/flutter_driver/test/src/matcher_util_test.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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:test/test.dart';
|
||||
import 'package:flutter_driver/src/matcher_util.dart';
|
||||
|
||||
void main() {
|
||||
group('match', () {
|
||||
test('matches', () {
|
||||
_TestMatcher matcher = new _TestMatcher(1);
|
||||
MatchResult ok = match(1, matcher);
|
||||
expect(ok.hasMatched, isTrue);
|
||||
expect(ok.mismatchDescription, isNull);
|
||||
expect(matcher.matchState1 is Map<dynamic, dynamic>, isTrue);
|
||||
expect(matcher.matchState2, isNull);
|
||||
});
|
||||
|
||||
test('mismatches', () {
|
||||
_TestMatcher matcher = new _TestMatcher(2);
|
||||
MatchResult fail = match(1, matcher);
|
||||
expect(fail.hasMatched, isFalse);
|
||||
expect(fail.mismatchDescription, 'mismatch!');
|
||||
expect(matcher.matchState1, matcher.matchState2);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class _TestMatcher extends Matcher {
|
||||
int expected;
|
||||
Map<dynamic, dynamic> matchState1;
|
||||
Map<dynamic, dynamic> matchState2;
|
||||
|
||||
_TestMatcher(this.expected);
|
||||
|
||||
@override
|
||||
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
|
||||
matchState1 = matchState;
|
||||
return item == expected;
|
||||
}
|
||||
|
||||
@override
|
||||
Description describeMismatch(dynamic item, Description mismatchDescription, Map<dynamic, dynamic> matchState, bool verbose) {
|
||||
matchState2 = matchState;
|
||||
mismatchDescription.add('mismatch!');
|
||||
return mismatchDescription;
|
||||
}
|
||||
|
||||
@override
|
||||
Description describe(Description description) {
|
||||
throw 'not implemented';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user