Skip to content

Commit

Permalink
🆕 [ut] Sections with mut
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-jusiak committed Dec 4, 2019
1 parent 9ecf247 commit c9d58de
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ int main() {

!expect(5_ul == std::size(v));

should("resize bigger") = [=]() mutable { // or "resize bigger"_test
v.resize(10);
should("resize bigger") = [v] { // or "resize bigger"_test
mut(v).resize(10);
expect(10_ul == std::size(v));
};

Expand Down Expand Up @@ -369,8 +369,8 @@ int main() {
std::vector<int> v(5);
!expect(5_ul == std::size(v));

when("I resize bigger") = [=]() mutable {
v.resize(10);
when("I resize bigger") = [=] {
mut(v).resize(10);

then("The size should increase") = [=] {
expect(10_ul == std::size(v));
Expand Down Expand Up @@ -527,6 +527,11 @@ skip | "don't run UDL"_test = [] {
};
```

```
All tests passed (1 asserts in 1 tests)
1 tests skipped
```

```cpp
test("run function") = [] {
expect(42_i == 42);
Expand Down Expand Up @@ -556,8 +561,8 @@ All tests passed (1 asserts in 1 tests)
!expect(5_ul == std::size(v));
should("resize bigger") = [=]() mutable { // or "resize bigger"_test
v.resize(10);
should("resize bigger") = [=] { // or "resize bigger"_test
mut(v).resize(10);
expect(10_ul == std::size(v));
};
Expand Down
6 changes: 3 additions & 3 deletions example/section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ int main() {

!expect(5_ul == std::size(v));

should("resize bigger") = [=]() mutable { // or "resize bigger"_test
v.resize(10);
should("resize bigger") = [v] { // or "resize bigger"_test
mut(v).resize(10);
expect(10_ul == std::size(v));
};

!expect(5_ul == std::size(v));

should("resize smaller") = [=]() mutable { // or "resize smaller"_test
should("resize smaller") = [=]() mutable { // or "resize smaller"_test
v.resize(0);
expect(0_ul == std::size(v));
};
Expand Down
5 changes: 5 additions & 0 deletions include/boost/ut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,11 @@ template <class TLhs, class TRhs>
return detail::le_{lhs, rhs};
}

template <class T>
[[nodiscard]] constexpr auto mut(const T& t) noexcept -> T& {
return const_cast<T&>(t);
}

using literals::operator""_test;
using literals::operator""_i;
using literals::operator""_s;
Expand Down
4 changes: 2 additions & 2 deletions test/ut/ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,8 +997,8 @@ int main() {

!expect(5_ul == std::size(v));

"resize bigger"_test = [=]() mutable {
v.resize(10);
"resize bigger"_test = [=] {
mut(v).resize(10);
expect(10_ul == std::size(v));
};

Expand Down

0 comments on commit c9d58de

Please sign in to comment.