Add string comparison tests

This commit is contained in:
David Tolnay 2020-11-29 22:37:43 -08:00
parent ff86dce342
commit c0674ccbab
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -6,6 +6,7 @@
#include <numeric>
#include <stdexcept>
#include <string>
#include <tuple>
extern "C" void cxx_test_suite_set_correct() noexcept;
extern "C" tests::R *cxx_test_suite_get_box() noexcept;
@ -656,6 +657,24 @@ extern "C" const char *cxx_run_test() noexcept {
ASSERT(Shared{1} == Shared{1});
ASSERT(Shared{1} != Shared{2});
rust::String first = "first", second = "second", sec = "sec";
bool (rust::String::*cmp)(const rust::String &) const;
bool first_first, first_second, sec_second, second_sec;
for (auto test : (std::tuple<decltype(cmp), bool, bool, bool, bool>[]) {
{&rust::String::operator==, true, false, false, false},
{&rust::String::operator!=, false, true, true, true},
{&rust::String::operator<, false, true, true, false},
{&rust::String::operator<=, true, true, true, false},
{&rust::String::operator>, false, false, false, true},
{&rust::String::operator>=, true, false, false, true},
}) {
std::tie(cmp, first_first, first_second, sec_second, second_sec) = test;
ASSERT((first.*cmp)(first) == first_first);
ASSERT((first.*cmp)(second) == first_second);
ASSERT((sec.*cmp)(second) == sec_second);
ASSERT((second.*cmp)(sec) == second_sec);
}
cxx_test_suite_set_correct();
return nullptr;
}