Skip to content

Commit

Permalink
expectDifference/expectNoDifference rename cleanups (#129)
Browse files Browse the repository at this point in the history
While upgrading I noticed some of the docs / existing tests still use the old naming, so took a few moments to update.
  • Loading branch information
freak4pc authored Aug 21, 2024
1 parent 82645ec commit 4c7b915
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 231 deletions.
2 changes: 1 addition & 1 deletion Sources/CustomDump/Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
///
/// This can be a great tool to use for building debug tools for applications and libraries. For
/// example, this library uses ``diff(_:_:format:)`` to implement
/// ``XCTAssertNoDifference(_:_:_:file:line:)``, which asserts that two values are equal, and
/// ``expectNoDifference(_:_:_:file:line:)``, which asserts that two values are equal, and
/// if they are not the failure message is a nicely formatted diff showing exactly what part of the
/// values are not equal.
///
Expand Down
18 changes: 9 additions & 9 deletions Sources/CustomDump/Documentation.docc/CustomDump.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ application to print the before and after state when favoriting a landmark:
  ]
```

### XCTAssertNoDifference
### expectNoDifference

The `XCTAssertEqual` function from `XCTest` allows you to assert that two values are equal, and if
they are not the test suite will fail with a message:
Expand All @@ -265,15 +265,15 @@ few moments of hunting through the message to see that the only difference is th
at the end of the name. The problem gets worse if the type is more complex, consisting of nested
structures and large collections.

This library also ships with an ``XCTAssertNoDifference(_:_:_:file:line:)`` function to mitigate
This library also ships with an ``expectNoDifference(_:_:_:file:line:)`` function to mitigate
these problems. It works like `XCTAssertEqual` except the failure message uses a nicely formatted
diff to show exactly what is different between the two values:

```swift
XCTAssertNoDifference(user, other)
expectNoDifference(user, other)
```
```diff
XCTAssertNoDifference failed: …
expectNoDifference failed: …

  User(
  favoriteNumbers: […],
Expand All @@ -285,10 +285,10 @@ XCTAssertNoDifference failed: …
(First: -, Second: +)
```

### XCTAssertDifference
### expectDifference

``XCTAssertDifference(_:_:operation:changes:file:line:)-8xfxw`` provides the inverse of
`XCTAssertNoDifference`: it asserts that a value has a set of changes by evaluating a given
``expectDifference(_:_:operation:changes:file:line:)-8xfxw`` provides the inverse of
`expectNoDifference`: it asserts that a value has a set of changes by evaluating a given
expression before and after a given operation and then comparing the results.

For example, given a very simple counter structure, we can write a test against its incrementing
Expand All @@ -305,7 +305,7 @@ struct Counter {
}

var counter = Counter()
XCTAssertDifference(counter) {
expectDifference(counter) {
counter.increment()
} changes: {
$0.count = 1
Expand All @@ -320,7 +320,7 @@ just the fields you want to assert against in the `changes` closure:

```swift
counter.increment()
XCTAssertDifference(counter) {
expectDifference(counter) {
$0.count = 1
// Don't need to further describe how `isOdd` has changed
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/CustomDump/ExpectNoDifference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import IssueReporting
/// XCTAssertEqual failed: ("User(id: 42, name: "Blob")") is not equal to ("User(id: 42, name: "Blob, Esq.")")
/// ```
///
/// `XCTAssertNoDifference` uses the output of ``diff(_:_:format:)`` to display a failure message,
/// `expectNoDifference` uses the output of ``diff(_:_:format:)`` to display a failure message,
/// which helps highlight the differences between the given values:
///
/// ```swift
/// XCTAssertNoDifference(user1, user2)
/// expectNoDifference(user1, user2)
/// ```
/// ```text
/// XCTAssertNoDifference failed: …
/// expectNoDifference failed: …
///
/// User(
/// id: 42,
Expand Down
Loading

0 comments on commit 4c7b915

Please sign in to comment.