google / google/googletest-rust

Improve documentation for `subset_of()`

Open
#685 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
432
Forks
36
Avg merge
7d 17h
Merged PRs (30d)
2

Description

I was working through the examples in [rust-advanced-testing-workshop/collections](https://github.com/mainmatter/rust-advanced-testing-workshop/blob/fa4710abdae52676cf345297a5c59bdd184051e0/exercises/01_better_assertions/06_collections/src/lib.rs), and got stuck at this exercise:

```rust
#[googletest::gtest]
fn failed_subset_of() {
let x = btreeset![1, 2, 3];
let y = btreeset![3, 4];
assert!(y.is_subset(&x));
}
```

I gave it a solid 30 minutes of trying in various ways, but I couldn't figure out how to write this particular test. This is the closest I'd gotten:

```rust
assert_that!(y, subset_of(x.iter().collect::>()));
```

I don't think this is a good way to do this, but I can't figure out how to massage `x` into an acceptable form.

It would be helpful if the examples in the docs for `subset_of()` showed usage from variables (of different collection types), rather than just arrays. The test module in `subset_of.rs` is similarly unhelpful. There isn't a large body of code using `googletest-rust`, so searching online also led nowhere.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.