Skip to content

Commit f6a43e5

Browse files
author
Dart CI
committed
Version 2.15.0-293.0.dev
Merge commit '217367abd1b674e425cdf9333f2d3aefa891f5b5' into 'dev'
2 parents 5ccf755 + 217367a commit f6a43e5

File tree

14 files changed

+192
-13
lines changed

14 files changed

+192
-13
lines changed

pkg/analysis_server/test/domain_completion_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
2121
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
2222
import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
2323
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
24+
import 'package:analyzer_utilities/check/check.dart';
2425
import 'package:test/test.dart';
2526
import 'package:test_reflective_loader/test_reflective_loader.dart';
2627

@@ -1599,7 +1600,7 @@ void f() {
15991600

16001601
RequestWithFutureResponse _sendTestCompletionRequest(String id, int offset) {
16011602
var request = CompletionGetSuggestions2Params(
1602-
testFilePath,
1603+
testFilePathPlatform,
16031604
0,
16041605
1 << 10,
16051606
).toRequest(id);
@@ -2794,7 +2795,7 @@ class SuggestionsValidator {
27942795
}
27952796

27962797
void assertEmpty() {
2797-
expect(suggestions, isEmpty);
2798+
check(suggestions).isEmpty;
27982799
}
27992800

28002801
void assertLength(Object matcher) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_utilities/check/check.dart';
6+
7+
extension BoolExtension on CheckTarget<bool> {
8+
void get isTrue {
9+
if (!value) {
10+
fail('is not true');
11+
}
12+
}
13+
14+
void get isFalse {
15+
if (value) {
16+
fail('is not false');
17+
}
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_utilities/check/check_target.dart';
6+
import 'package:meta/meta.dart';
7+
8+
export 'package:analyzer_utilities/check/check_target.dart';
9+
export 'package:analyzer_utilities/check/equality.dart';
10+
export 'package:analyzer_utilities/check/int.dart';
11+
export 'package:analyzer_utilities/check/iterable.dart';
12+
export 'package:analyzer_utilities/check/string.dart';
13+
export 'package:analyzer_utilities/check/type.dart';
14+
15+
@useResult
16+
CheckTarget<T> check<T>(T value) {
17+
return CheckTarget(value, 0, () => '$value');
18+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:test/test.dart' as test_package;
6+
7+
class CheckTarget<T> {
8+
final T value;
9+
final int _depth;
10+
11+
/// The function that return the description of the value, and of the
12+
/// chain how we arrived to this value.
13+
final String Function() _describe;
14+
15+
CheckTarget(this.value, this._depth, this._describe);
16+
17+
String get _indent => ' ' * (_depth + 1);
18+
19+
String valueStr(value) {
20+
if (value is String) {
21+
return "'$value'";
22+
}
23+
return '$value';
24+
}
25+
26+
Never fail(String message) {
27+
test_package.fail(_describe() + '\n' + _indent + message);
28+
}
29+
30+
/// Chains to the given [value]; if a subsequent check fails, [describe]
31+
/// will be invoked to describe the [value].
32+
CheckTarget<U> nest<U>(
33+
U value,
34+
String Function(U value) describe,
35+
) {
36+
return CheckTarget(value, _depth + 1, () {
37+
return _describe() + '\n' + _indent + describe(value);
38+
});
39+
}
40+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_utilities/check/check.dart';
6+
7+
extension EqualityExtension<T> on CheckTarget<T> {
8+
void isEqualTo(Object? other) {
9+
if (value != other) {
10+
fail('is not equal to $other');
11+
}
12+
}
13+
14+
void isNotEqualTo(Object? other) {
15+
if (value == other) {
16+
fail('is equal to $other');
17+
}
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_utilities/check/check.dart';
6+
7+
extension IntExtension on CheckTarget<int> {
8+
void get isZero {
9+
if (value != 0) {
10+
fail('is not zero');
11+
}
12+
}
13+
14+
void isGreaterThan(int other) {
15+
if (!(value > other)) {
16+
fail('is not greater than $other');
17+
}
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_utilities/check/check.dart';
6+
7+
extension IterableExtension<T> on CheckTarget<Iterable<T>> {
8+
void get isEmpty {
9+
if (value.isNotEmpty) {
10+
fail('is not empty');
11+
}
12+
}
13+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_utilities/check/check.dart';
6+
import 'package:meta/meta.dart';
7+
8+
extension StringExtension on CheckTarget<String> {
9+
void contains(Pattern other) {
10+
if (!value.contains(other)) {
11+
fail('does not contain ${valueStr(other)}');
12+
}
13+
}
14+
15+
void startsWith(Pattern other) {
16+
if (!value.startsWith(other)) {
17+
fail('does not start with ${valueStr(other)}');
18+
}
19+
}
20+
21+
@useResult
22+
CheckTarget<int> hasLength() {
23+
return nest(
24+
value.length,
25+
(length) => 'has length $length',
26+
);
27+
}
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_utilities/check/check.dart';
6+
7+
extension IsExtension<T> on CheckTarget<T> {
8+
CheckTarget<U> isA<U extends T>() {
9+
final value = this.value;
10+
if (value is U) {
11+
return nest(value, (_) => 'is of type $U');
12+
} else {
13+
fail('is not of type $U');
14+
}
15+
}
16+
}

pkg/analyzer_utilities/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ dependencies:
99
analyzer:
1010
path: ../analyzer
1111
html: any
12+
meta:
13+
path: ../meta
1214
path: any
1315
test: any

0 commit comments

Comments
 (0)