From 5c9f09e94a32ab47f16bf8353a708e226fccf645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 21 Apr 2020 19:27:12 +0200 Subject: [PATCH] Add support for bitwise xor to the decomposer --- include/internal/catch_decomposer.h | 4 ++++ .../Baselines/compact.sw.approved.txt | 2 ++ .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 12 ++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 2 +- .../SelfTest/Baselines/xml.sw.approved.txt | 20 +++++++++++++++++-- .../SelfTest/UsageTests/Compilation.tests.cpp | 5 +++++ 7 files changed, 42 insertions(+), 5 deletions(-) diff --git a/include/internal/catch_decomposer.h b/include/internal/catch_decomposer.h index af1cbcfb..9320c4dd 100644 --- a/include/internal/catch_decomposer.h +++ b/include/internal/catch_decomposer.h @@ -208,6 +208,10 @@ namespace Catch { auto operator & (RhsT const& rhs) -> BinaryExpr const { return { static_cast(m_lhs & rhs), m_lhs, "&", rhs }; } + template + auto operator ^ (RhsT const& rhs) -> BinaryExpr const { + return { static_cast(m_lhs ^ rhs), m_lhs, "^", rhs }; + } template auto operator && ( RhsT const& ) -> BinaryExpr const { diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 08390525..3ac244ee 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -247,6 +247,8 @@ Matchers.tests.cpp:: passed: "This wouldn't pass", !Predicate: passed: lhs | rhs for: Val: 1 | Val: 2 Compilation.tests.cpp:: passed: !(lhs & rhs) for: !(Val: 1 & Val: 2) Compilation.tests.cpp:: passed: HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val: 1 +Compilation.tests.cpp:: passed: lhs ^ rhs for: Val: 1 ^ Val: 2 +Compilation.tests.cpp:: passed: !(lhs ^ lhs) for: !(Val: 1 ^ Val: 1) Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 0b403c42..1cb3970e 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 310 | 236 passed | 70 failed | 4 failed as expected -assertions: 1699 | 1547 passed | 131 failed | 21 failed as expected +assertions: 1701 | 1549 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index bcf66625..9ac146f9 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -1955,6 +1955,16 @@ Compilation.tests.cpp:: PASSED: with expansion: Val: 1 & Val: 1 +Compilation.tests.cpp:: PASSED: + REQUIRE( lhs ^ rhs ) +with expansion: + Val: 1 ^ Val: 2 + +Compilation.tests.cpp:: PASSED: + REQUIRE_FALSE( lhs ^ lhs ) +with expansion: + !(Val: 1 ^ Val: 1) + ------------------------------------------------------------------------------- Assertions then sections ------------------------------------------------------------------------------- @@ -13564,5 +13574,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 310 | 220 passed | 86 failed | 4 failed as expected -assertions: 1716 | 1547 passed | 148 failed | 21 failed as expected +assertions: 1718 | 1549 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 47341280..603e4d0b 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index a2eb1eed..ddbdb595 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -2202,6 +2202,22 @@ Nor would this Val: 1 & Val: 1 + + + lhs ^ rhs + + + Val: 1 ^ Val: 2 + + + + + !(lhs ^ lhs) + + + !(Val: 1 ^ Val: 1) + + @@ -16239,7 +16255,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/UsageTests/Compilation.tests.cpp b/projects/SelfTest/UsageTests/Compilation.tests.cpp index 7ec17448..850d5f9b 100644 --- a/projects/SelfTest/UsageTests/Compilation.tests.cpp +++ b/projects/SelfTest/UsageTests/Compilation.tests.cpp @@ -244,6 +244,9 @@ namespace { friend HasBitOperators operator& (HasBitOperators lhs, HasBitOperators rhs) { return { lhs.value & rhs.value }; } + friend HasBitOperators operator^ (HasBitOperators lhs, HasBitOperators rhs) { + return { lhs.value ^ rhs.value }; + } explicit operator bool() const { return !!value; } @@ -260,5 +263,7 @@ TEST_CASE("Assertion macros support bit operators and bool conversions", "[compi REQUIRE(lhs | rhs); REQUIRE_FALSE(lhs & rhs); REQUIRE(HasBitOperators{ 1 } & HasBitOperators{ 1 }); + REQUIRE(lhs ^ rhs); + REQUIRE_FALSE(lhs ^ lhs); }