Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a map matcher. #1112

Merged
merged 1 commit into from
Jan 6, 2024
Merged

Add a map matcher. #1112

merged 1 commit into from
Jan 6, 2024

Conversation

younata
Copy link
Member

@younata younata commented Jan 6, 2024

map allows you to transform the expression to another value, and then run that new value against another matcher.

I find map to be most useful when combined with satisfyAllOf, as a kind of "fuzzy equals" matcher. Or, when you only care about some parts of a value matching but not other.

In fact, without composing map with satisfyAllOf, I don't really see the point of map at all. After all expect(foo.property).to(equal(1)) is much more readable and succinct than expect(foo).to(map(\.property, equal(1)))).

I also added some guidance for when to use map. In my view, map sits in a weird case where you want to check multiple multiple properties of a value at the same time (perhaps as part of a toEventually-style matcher), but don't want the value to conform to Equatable, nor do you check that value enough to write a custom matcher for it.

Some trivia: Originally, this matcher was named lens, from the functional programming concept. However, I changed it to map which is both closer to how it's actually used/written, and much more idiomatic to swift.

Checklist - While not every PR needs it, new features should consider this list:

  • Does this have tests?
  • Does this have documentation?
  • Does this break the public API (Requires major version bump)?
  • Is this a new feature (Requires minor version bump)?

…cher against the return value of that function
@younata younata merged commit 1b75ed0 into main Jan 6, 2024
15 checks passed
@younata younata deleted the map_matcher branch January 6, 2024 22:01
cgrindel-self-hosted-renovate bot referenced this pull request in cgrindel/rules_swift_package_manager Jan 18, 2024
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [Quick/Nimble](https://togithub.com/Quick/Nimble) | minor | `from:
"13.1.2"` -> `from: "13.2.0"` |

---

### Release Notes

<details>
<summary>Quick/Nimble (Quick/Nimble)</summary>

### [`v13.2.0`](https://togithub.com/Quick/Nimble/releases/tag/v13.2.0):
- visionOS, map matcher.

[Compare
Source](https://togithub.com/Quick/Nimble/compare/v13.1.2...v13.2.0)

### Highlights

- Nimble now supports visionOS! Thanks
[@&#8203;stonko1994](https://togithub.com/stonko1994)!
- Adds a new `map` matcher. `map` allows you to transform the expression
to another value, and pass that value to another matcher.
- For example, if you wanted to match the first element in a tuple
easily, you could write: `expect(myTuple).to(map(\.0,
equal(expectedValue)))`.
- See [the docs for more
suggestions](https://togithub.com/Quick/Nimble/tree/v13.2.0#mapping-a-value-to-another-value)!

### Autogenerated Release Notes

#### What's Changed

- Add a `map` matcher. by
[@&#8203;younata](https://togithub.com/younata) in
[https://github.com/Quick/Nimble/pull/1112](https://togithub.com/Quick/Nimble/pull/1112)
- Build the carthage frameworks in a github action by
[@&#8203;younata](https://togithub.com/younata) in
[https://github.com/Quick/Nimble/pull/1107](https://togithub.com/Quick/Nimble/pull/1107)
- Bump cocoapods from 1.14.2 to 1.14.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/Quick/Nimble/pull/1100](https://togithub.com/Quick/Nimble/pull/1100)
- Add a privacy manifest by
[@&#8203;younata](https://togithub.com/younata) in
[https://github.com/Quick/Nimble/pull/1113](https://togithub.com/Quick/Nimble/pull/1113)
- Add visionOS support by
[@&#8203;stonko1994](https://togithub.com/stonko1994) in
[https://github.com/Quick/Nimble/pull/1098](https://togithub.com/Quick/Nimble/pull/1098)

#### New Contributors

- [@&#8203;stonko1994](https://togithub.com/stonko1994) made their first
contribution in
[https://github.com/Quick/Nimble/pull/1098](https://togithub.com/Quick/Nimble/pull/1098)

**Full Changelog**:
Quick/Nimble@v13.1.2...v13.2.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjEwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant