Skip to content

Commit d2858ba

Browse files
authored
Rename checkThat to check (#1880)
Save 4 characters of typing millions of types. The line will not read as nicely in many situations, but it doesn't make a significant difference. The shorter name, with no capital letters, also draws the least possible attention to this name, which carries the least information of any part of the expression.
1 parent a60b655 commit d2858ba

20 files changed

+298
-307
lines changed

pkgs/checks/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# 0.1.1-dev
1+
# 0.2.0
22

3+
- **Breaking** `checkThat` renamed to `check`.
34
- Added an example.
45
- Include a stack trace in the failure description for unexpected errors from
56
Futures or Streams.

pkgs/checks/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Checking expectations with `checks`
22

3-
Expectations start with `checkThat`. This utility returns a `Subject`, and
3+
Expectations start with `check`. This utility returns a `Subject`, and
44
expectations can be checked against the subject. Expectations are defined as
55
extension methods, and different expectations will be available for subjects
66
with different value types.
77

88
```dart
9-
checkThat(someValue).equals(expectedValue);
10-
checkThat(someList).deepEquals(expectedList);
11-
checkThat(someString).contains('expected pattern');
9+
check(someValue).equals(expectedValue);
10+
check(someList).deepEquals(expectedList);
11+
check(someString).contains('expected pattern');
1212
```
1313

1414
Multiple expectations can be checked against the same value using cascade
1515
syntax. When multiple expectations are checked against a single value, a failure
1616
will included descriptions of the expectations that already passed.
1717

1818
```dart
19-
checkThat(someString)
19+
check(someString)
2020
..startsWith('a')
2121
..endsWith('z')
2222
..contains('lmno');
@@ -26,15 +26,15 @@ Some expectations return a `Subject` for another value derived from the original
2626
value - for instance reading a field or awaiting the result of a Future.
2727

2828
```dart
29-
checkThat(someString).length.equals(expectedLength);
30-
(await checkThat(someFuture).completes()).equals(expectedCompletion);
29+
check(someString).length.equals(expectedLength);
30+
(await check(someFuture).completes()).equals(expectedCompletion);
3131
```
3232

3333
Fields can be extracted from objects for checking further properties with the
3434
`has` utility.
3535

3636
```dart
37-
checkThat(someValue)
37+
check(someValue)
3838
.has((value) => value.property, 'property')
3939
.equals(expectedPropertyValue);
4040
```
@@ -47,22 +47,22 @@ value as a subject will be recorded and replayed when it is applied as a
4747
condition. The `it()` utility returns a `ConditionSubject`.
4848

4949
```dart
50-
checkThat(someList).any(it()..isGreaterThan(0));
50+
check(someList).any(it()..isGreaterThan(0));
5151
```
5252

5353
Some complicated checks may be difficult to write with parenthesized awaited
5454
expressions, or impossible to write with cascade syntax. There are `which`
5555
utilities for both use cases which take a `Condition`.
5656

5757
```dart
58-
checkThat(someString)
58+
check(someString)
5959
..startsWith('a')
6060
// A cascade would not be possible on `length`
6161
..length.which(it()
6262
..isGreatherThan(10)
6363
..isLessThan(100));
6464
65-
await checkThat(someFuture)
65+
await check(someFuture)
6666
.completes()
6767
.which(it()..equals(expectedCompletion));
6868
```
@@ -126,7 +126,7 @@ extension CustomChecks on Subject<CustomType> {
126126

127127
# Migrating from Matchers
128128

129-
Replace calls to `expect` with a call to `checkThat` passing the first argument.
129+
Replace calls to `expect` with a call to `check` passing the first argument.
130130
When a direct replacement is available, change the second argument from calling
131131
a function returning a Matcher, to calling the extension method on the
132132
`Subject`.
@@ -137,9 +137,9 @@ correct replacement in `package:checks`.
137137

138138
```dart
139139
expect(actual, expected);
140-
checkThat(actual).equals(expected);
140+
check(actual).equals(expected);
141141
// or maybe
142-
checkThat(actual).deepEquals(expected);
142+
check(actual).deepEquals(expected);
143143
```
144144

145145
## Differences in behavior from matcher

pkgs/checks/example/example.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import 'package:test/scaffolding.dart';
88
void main() {
99
test('sample test', () {
1010
final someValue = 5;
11-
checkThat(someValue).equals(5);
11+
check(someValue).equals(5);
1212

1313
final someList = [1, 2, 3, 4, 5];
14-
checkThat(someList).deepEquals([1, 2, 3, 4, 5]);
14+
check(someList).deepEquals([1, 2, 3, 4, 5]);
1515

1616
final someString = 'abcdefghijklmnopqrstuvwxyz';
1717

18-
checkThat(someString)
18+
check(someString)
1919
..startsWith('a')
2020
..endsWith('z')
2121
..contains('lmno');

pkgs/checks/lib/checks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
export 'src/checks.dart' show checkThat, Subject, Skip, it;
5+
export 'src/checks.dart' show check, Subject, Skip, it;
66
export 'src/extensions/async.dart'
77
show ChainAsync, FutureChecks, StreamChecks, StreamQueueWrap;
88
export 'src/extensions/core.dart'

pkgs/checks/lib/src/checks.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension Skip<T> on Subject<T> {
3333
/// failure.
3434
///
3535
/// ```dart
36-
/// checkThat(actual)
36+
/// check(actual)
3737
/// ..stillChecked()
3838
/// ..skip('reason the expectation is temporarily not met').notChecked();
3939
/// ```
@@ -57,11 +57,10 @@ extension Skip<T> on Subject<T> {
5757
/// messages.
5858
///
5959
/// ```dart
60-
/// checkThat(actual).equals(expected);
60+
/// check(actual).equals(expected);
6161
/// ```
6262
@meta.useResult
63-
Subject<T> checkThat<T>(T value, {String? because}) =>
64-
Subject._(_TestContext._root(
63+
Subject<T> check<T>(T value, {String? because}) => Subject._(_TestContext._root(
6564
value: _Present(value),
6665
// TODO - switch between "a" and "an"
6766
label: 'a $T',
@@ -239,7 +238,7 @@ abstract class Context<T> {
239238
///
240239
/// May not be used from the context for a [Subject] created by [softCheck] or
241240
/// [softCheckAsync]. The only useful effect of a late rejection is to throw a
242-
/// [TestFailure] when used with a [checkThat] subject. Most conditions should
241+
/// [TestFailure] when used with a [check] subject. Most conditions should
243242
/// prefer to use [expect] or [expectAsync].
244243
void expectUnawaited(Iterable<String> Function() clause,
245244
void Function(T, void Function(Rejection)) predicate);
@@ -597,7 +596,7 @@ class CheckFailure {
597596
///
598597
/// A subject may have some number of succeeding expectations, and the failure may
599598
/// be for an expectation against a property derived from the value at the root
600-
/// of the subject. For example, in `checkThat([]).length.equals(1)` the
599+
/// of the subject. For example, in `check([]).length.equals(1)` the
601600
/// specific value that gets rejected is `0` from the length of the list, and
602601
/// the subject that sees the rejection is nested with the label "has length".
603602
class FailureDetail {

pkgs/checks/lib/src/extensions/async.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ extension StreamChecks<T> on Subject<StreamQueue<T>> {
205205
/// conditions.
206206
///
207207
/// ```dart
208-
/// await checkThat(StreamQueue(someStream)).inOrder([
208+
/// await check(StreamQueue(someStream)).inOrder([
209209
/// it()..emits().that(it()..equals(0)),
210210
/// it()..emits().that(it()..equals(1)),
211211
// ]);
@@ -445,9 +445,9 @@ extension ChainAsync<T> on Future<Subject<T>> {
445445
/// expression that would need parenthesis.
446446
///
447447
/// ```dart
448-
/// await checkThat(someFuture).completes().which(it()..equals('expected'));
448+
/// await check(someFuture).completes().which(it()..equals('expected'));
449449
/// // or, with the intermediate `await`:
450-
/// (await checkThat(someFuture).completes()).equals('expected');
450+
/// (await check(someFuture).completes()).equals('expected');
451451
/// ```
452452
Future<void> which(Condition<T> condition) async {
453453
await condition.applyAsync(await this);

pkgs/checks/lib/src/extensions/core.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension CoreChecks<T> on Subject<T> {
2727
/// in a way that would conflict.
2828
///
2929
/// ```
30-
/// checkThat(something)
30+
/// check(something)
3131
/// ..has((s) => s.foo, 'foo').equals(expectedFoo)
3232
/// ..has((s) => s.bar, 'bar').which(it()
3333
/// ..isLessThan(10)

pkgs/checks/lib/src/extensions/iterable.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension IterableChecks<T> on Subject<Iterable<T>> {
4747
/// For example, the following will succeed:
4848
///
4949
/// ```dart
50-
/// checkThat([1, 0, 2, 0, 3]).containsInOrder([1, 2, 3]);
50+
/// check([1, 0, 2, 0, 3]).containsInOrder([1, 2, 3]);
5151
/// ```
5252
///
5353
/// Values in [elements] may be a `T`, a `Condition<T>`, or a
@@ -57,7 +57,7 @@ extension IterableChecks<T> on Subject<Iterable<T>> {
5757
/// equality operator.
5858
///
5959
/// ```dart
60-
/// checkThat([1, 0, 2, 0, 3])
60+
/// check([1, 0, 2, 0, 3])
6161
/// .containsInOrder([1, it<int>()..isGreaterThan(1), 3]);
6262
/// ```
6363
void containsInOrder(Iterable<Object?> elements) {

pkgs/checks/lib/src/extensions/string.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extension StringChecks on Subject<String> {
7373
///
7474
/// For example, the following will succeed:
7575
///
76-
/// checkThat('abcdefg').containsInOrder(['a','e']);
76+
/// check('abcdefg').containsInOrder(['a','e']);
7777
void containsInOrder(Iterable<String> expected) {
7878
context.expect(() => prefixFirst('contains, in order: ', literal(expected)),
7979
(actual) {
@@ -118,12 +118,12 @@ extension StringChecks on Subject<String> {
118118
///
119119
/// For example the following will succeed:
120120
///
121-
/// checkThat(' hello world ').equalsIgnoringWhitespace('hello world');
121+
/// check(' hello world ').equalsIgnoringWhitespace('hello world');
122122
///
123123
/// While the following will fail:
124124
///
125-
/// checkThat('helloworld').equalsIgnoringWhitespace('hello world');
126-
/// checkThat('he llo world').equalsIgnoringWhitespace('hello world');
125+
/// check('helloworld').equalsIgnoringWhitespace('hello world');
126+
/// check('he llo world').equalsIgnoringWhitespace('hello world');
127127
void equalsIgnoringWhitespace(String expected) {
128128
context.expect(
129129
() => prefixFirst('equals ignoring whitespace ', literal(expected)),

pkgs/checks/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: checks
2-
version: 0.1.1-dev
2+
version: 0.2.0
33
description: >-
44
A framework for checking values against expectations and building custom
55
expectations.

0 commit comments

Comments
 (0)