Add support for bitwise xor to the decomposer

This commit is contained in:
Martin Hořeňovský 2020-04-21 19:27:12 +02:00
parent f4fc2dab2c
commit 5c9f09e94a
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
7 changed files with 42 additions and 5 deletions

View File

@ -208,6 +208,10 @@ namespace Catch {
auto operator & (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const { auto operator & (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
return { static_cast<bool>(m_lhs & rhs), m_lhs, "&", rhs }; return { static_cast<bool>(m_lhs & rhs), m_lhs, "&", rhs };
} }
template <typename RhsT>
auto operator ^ (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
return { static_cast<bool>(m_lhs ^ rhs), m_lhs, "^", rhs };
}
template<typename RhsT> template<typename RhsT>
auto operator && ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const { auto operator && ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const {

View File

@ -247,6 +247,8 @@ Matchers.tests.cpp:<line number>: passed: "This wouldn't pass", !Predicate<std::
Compilation.tests.cpp:<line number>: passed: lhs | rhs for: Val: 1 | Val: 2 Compilation.tests.cpp:<line number>: passed: lhs | rhs for: Val: 1 | Val: 2
Compilation.tests.cpp:<line number>: passed: !(lhs & rhs) for: !(Val: 1 & Val: 2) Compilation.tests.cpp:<line number>: passed: !(lhs & rhs) for: !(Val: 1 & Val: 2)
Compilation.tests.cpp:<line number>: passed: HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val: 1 Compilation.tests.cpp:<line number>: passed: HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val: 1
Compilation.tests.cpp:<line number>: passed: lhs ^ rhs for: Val: 1 ^ Val: 2
Compilation.tests.cpp:<line number>: passed: !(lhs ^ lhs) for: !(Val: 1 ^ Val: 1)
Tricky.tests.cpp:<line number>: passed: true Tricky.tests.cpp:<line number>: passed: true
Tricky.tests.cpp:<line number>: passed: true Tricky.tests.cpp:<line number>: passed: true
Tricky.tests.cpp:<line number>: passed: true Tricky.tests.cpp:<line number>: passed: true

View File

@ -1381,5 +1381,5 @@ due to unexpected exception with message:
=============================================================================== ===============================================================================
test cases: 310 | 236 passed | 70 failed | 4 failed as expected 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

View File

@ -1955,6 +1955,16 @@ Compilation.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
Val: 1 & Val: 1 Val: 1 & Val: 1
Compilation.tests.cpp:<line number>: PASSED:
REQUIRE( lhs ^ rhs )
with expansion:
Val: 1 ^ Val: 2
Compilation.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( lhs ^ lhs )
with expansion:
!(Val: 1 ^ Val: 1)
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Assertions then sections Assertions then sections
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -13564,5 +13574,5 @@ Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 310 | 220 passed | 86 failed | 4 failed as expected 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

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <testsuitesloose text artifact
> >
<testsuite name="<exe-name>" errors="17" failures="132" tests="1717" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="17" failures="132" tests="1719" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties> <properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>

View File

@ -2202,6 +2202,22 @@ Nor would this
Val: 1 &amp; Val: 1 Val: 1 &amp; Val: 1
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
<Original>
lhs ^ rhs
</Original>
<Expanded>
Val: 1 ^ Val: 2
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_FALSE" filename="projects/<exe-name>/UsageTests/Compilation.tests.cpp" >
<Original>
!(lhs ^ lhs)
</Original>
<Expanded>
!(Val: 1 ^ Val: 1)
</Expanded>
</Expression>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="Assertions then sections" tags="[Tricky]" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" > <TestCase name="Assertions then sections" tags="[Tricky]" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
@ -16239,7 +16255,7 @@ loose text artifact
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="1547" failures="149" expectedFailures="21"/> <OverallResults successes="1549" failures="149" expectedFailures="21"/>
</Group> </Group>
<OverallResults successes="1547" failures="148" expectedFailures="21"/> <OverallResults successes="1549" failures="148" expectedFailures="21"/>
</Catch> </Catch>

View File

@ -244,6 +244,9 @@ namespace {
friend HasBitOperators operator& (HasBitOperators lhs, HasBitOperators rhs) { friend HasBitOperators operator& (HasBitOperators lhs, HasBitOperators rhs) {
return { lhs.value & rhs.value }; return { lhs.value & rhs.value };
} }
friend HasBitOperators operator^ (HasBitOperators lhs, HasBitOperators rhs) {
return { lhs.value ^ rhs.value };
}
explicit operator bool() const { explicit operator bool() const {
return !!value; return !!value;
} }
@ -260,5 +263,7 @@ TEST_CASE("Assertion macros support bit operators and bool conversions", "[compi
REQUIRE(lhs | rhs); REQUIRE(lhs | rhs);
REQUIRE_FALSE(lhs & rhs); REQUIRE_FALSE(lhs & rhs);
REQUIRE(HasBitOperators{ 1 } & HasBitOperators{ 1 }); REQUIRE(HasBitOperators{ 1 } & HasBitOperators{ 1 });
REQUIRE(lhs ^ rhs);
REQUIRE_FALSE(lhs ^ lhs);
} }