Skip to content

Commit d9f117a

Browse files
committed
docs: add assert_string_matches_format and assert_have_been_called_nth_with
1 parent a457dd3 commit d9f117a

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
## Unreleased
44

55
### Added
6-
- Add `assert_have_been_called_nth_with` assertion for verifying arguments on the Nth invocation of a spy (Issue #172)
7-
- Add `assert_string_matches_format` and `assert_string_not_matches_format` assertions with PHPUnit-style format placeholders (`%d`, `%s`, `%f`, `%i`, `%x`, `%e`, `%%`) (Issue #177)
6+
- Add `assert_have_been_called_nth_with` for verifying arguments on the Nth invocation of a spy
7+
- Add `assert_string_matches_format` and `assert_string_not_matches_format` with format placeholders (`%d`, `%s`, `%f`, `%i`, `%x`, `%e`, `%%`)
88

99
### Changed
1010
- Split Windows CI test jobs into parallel chunks to avoid timeouts

docs/assertions.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,36 @@ function test_failure() {
221221
```
222222
:::
223223

224+
## assert_string_matches_format
225+
> `assert_string_matches_format "format" "value"`
226+
227+
Reports an error if `value` does not match the `format` string. The format string uses PHPUnit-style placeholders:
228+
229+
| Placeholder | Matches |
230+
|-------------|---------|
231+
| `%d` | One or more digits |
232+
| `%i` | Signed integer (e.g. `+1`, `-42`) |
233+
| `%f` | Floating point number (e.g. `3.14`) |
234+
| `%s` | One or more non-whitespace characters |
235+
| `%x` | Hexadecimal (e.g. `ff00ab`) |
236+
| `%e` | Scientific notation (e.g. `1.5e10`) |
237+
| `%%` | Literal `%` character |
238+
239+
- [assert_string_not_matches_format](#assert-string-not-matches-format) is the inverse of this assertion and takes the same arguments.
240+
241+
::: code-group
242+
```bash [Example]
243+
function test_success() {
244+
assert_string_matches_format "%d items found" "42 items found"
245+
assert_string_matches_format "%s has %d items at %f each" "cart has 5 items at 9.99 each"
246+
}
247+
248+
function test_failure() {
249+
assert_string_matches_format "%d items" "hello world"
250+
}
251+
```
252+
:::
253+
224254
## assert_line_count
225255
> `assert_line_count "count" "haystack"`
226256

@@ -957,6 +987,25 @@ function test_failure() {
957987
```
958988
:::
959989
990+
## assert_string_not_matches_format
991+
> `assert_string_not_matches_format "format" "value"`
992+
993+
Reports an error if `value` matches the `format` string. See [assert_string_matches_format](#assert-string-matches-format) for supported placeholders.
994+
995+
- [assert_string_matches_format](#assert-string-matches-format) is the inverse of this assertion and takes the same arguments.
996+
997+
::: code-group
998+
```bash [Example]
999+
function test_success() {
1000+
assert_string_not_matches_format "%d items" "hello world"
1001+
}
1002+
1003+
function test_failure() {
1004+
assert_string_not_matches_format "%d items" "42 items"
1005+
}
1006+
```
1007+
:::
1008+
9601009
## assert_array_not_contains
9611010
> `assert_array_not_contains "needle" "haystack"`
9621011

docs/test-doubles.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,35 @@ function test_failure() {
174174
:::
175175

176176

177+
## assert_have_been_called_nth_with
178+
> `assert_have_been_called_nth_with "nth" "spy" "expected"`
179+
180+
Reports an error if the `nth` invocation of `spy` was not called with `expected`. The index starts at 1. Reports an error if `spy` was called fewer than `nth` times.
181+
182+
::: code-group
183+
```bash [Example]
184+
function test_success() {
185+
bashunit::spy ps
186+
187+
ps first
188+
ps second
189+
ps third
190+
191+
assert_have_been_called_nth_with 1 ps "first"
192+
assert_have_been_called_nth_with 2 ps "second"
193+
assert_have_been_called_nth_with 3 ps "third"
194+
}
195+
196+
function test_failure() {
197+
bashunit::spy ps
198+
199+
ps first
200+
201+
assert_have_been_called_nth_with 1 ps "wrong"
202+
}
203+
```
204+
:::
205+
177206
## assert_have_been_called_times
178207
> assert_have_been_called_times "expected" "spy"
179208

0 commit comments

Comments
 (0)