|
1 | 1 | #include <catch.hpp> |
2 | 2 | #include <ut/constexpr_hash/constexpr_hash.hpp> |
3 | 3 |
|
| 4 | +#include <algorithm> |
4 | 5 | #include <array> |
| 6 | +#include <cctype> |
| 7 | +#include <iterator> |
5 | 8 | #include <string> |
6 | 9 |
|
7 | 10 | constexpr auto empty = ""; |
8 | 11 | constexpr auto short_str = "hello"; |
9 | 12 | constexpr auto long_str = |
10 | 13 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pellentesque justo eu mauris gravida aliquet. Nam et velit tortor. Vestibulum sit amet commodo ante. Fusce eleifend tellus ac euismod porta. Proin at gravida tortor. Suspendisse eget urna vitae dui varius auctor et ac quam. Phasellus sodales sodales dolor, vel aliquet erat posuere hendrerit. Donec consectetur orci eget pulvinar pellentesque. Donec in bibendum orci. Phasellus congue, ligula non tincidunt malesuada, nisl ligula mauris. "; |
| 14 | +constexpr auto ascii = |
| 15 | + "\a\b\t\n\v\f\r\"\\@!#$%&'()*+,-./0123456789:;<=>?[]^_ `abcdefghijklmnopqrstuvwxyz{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
| 16 | +constexpr auto ascii_lower = |
| 17 | + "\a\b\t\n\v\f\r\"\\@!#$%&'()*+,-./0123456789:;<=>?[]^_ `abcdefghijklmnopqrstuvwxyz{|}~abcdefghijklmnopqrstuvwxyz"; |
11 | 18 |
|
12 | 19 | constexpr auto len(char const *str) { |
13 | 20 | return std::char_traits<char>::length(str); |
@@ -80,3 +87,36 @@ TEST_CASE("Runtime hashing", "[constexpr_hash]") { |
80 | 87 | REQUIRE(str3_hash != str_cpy_1_hash); |
81 | 88 | REQUIRE(str3_hash != str_cpy_2_hash); |
82 | 89 | } |
| 90 | + |
| 91 | +TEST_CASE("Compile time ignore case", "[constexpr_hash]") { |
| 92 | + |
| 93 | + static constexpr auto ascii_2 = makeCopy<len(ascii)>(ascii); |
| 94 | + static constexpr auto ascii_lower_2 = makeCopy<len(ascii_lower)>(ascii_lower); |
| 95 | + |
| 96 | + STATIC_REQUIRE(ut::fnv_1a<std::size_t>(ascii) == ut::fnv_1a<std::size_t>(ascii_2.data())); |
| 97 | + STATIC_REQUIRE(ut::fnv_1a<std::size_t, ut::CHIgnoreCase::No>(ascii) |
| 98 | + == ut::fnv_1a<std::size_t, ut::CHIgnoreCase::No>(ascii_2.data())); |
| 99 | + STATIC_REQUIRE(ut::fnv_1a<std::size_t, ut::CHIgnoreCase::Yes>(ascii) |
| 100 | + == ut::fnv_1a<std::size_t, ut::CHIgnoreCase::Yes>(ascii_2.data())); |
| 101 | + STATIC_REQUIRE(ut::fnv_1a<std::size_t, ut::CHIgnoreCase::Yes>(ascii) |
| 102 | + != ut::fnv_1a<std::size_t, ut::CHIgnoreCase::No>(ascii_2.data())); |
| 103 | + |
| 104 | + STATIC_REQUIRE(ut::fnv_1a<std::size_t>(ascii) != ut::fnv_1a<std::size_t>(ascii_lower_2.data())); |
| 105 | + STATIC_REQUIRE(ut::fnv_1a<std::size_t, ut::CHIgnoreCase::No>(ascii) |
| 106 | + != ut::fnv_1a<std::size_t, ut::CHIgnoreCase::No>(ascii_lower_2.data())); |
| 107 | + STATIC_REQUIRE(ut::fnv_1a<std::size_t, ut::CHIgnoreCase::Yes>(ascii) |
| 108 | + == ut::fnv_1a<std::size_t, ut::CHIgnoreCase::Yes>(ascii_lower_2.data())); |
| 109 | + STATIC_REQUIRE(ut::fnv_1a<std::size_t, ut::CHIgnoreCase::Yes>(ascii) |
| 110 | + == ut::fnv_1a<std::size_t, ut::CHIgnoreCase::No>(ascii_lower_2.data())); |
| 111 | +} |
| 112 | + |
| 113 | +TEST_CASE("Runtime ignore case", "[constexpr_hash]") { |
| 114 | + std::string str1, str2; |
| 115 | + std::generate_n(std::back_inserter(str1), 20, []() { return std::rand() % (128 - '!') + '!'; }); |
| 116 | + std::transform(str1.begin(), str1.end(), std::back_inserter(str2), [](char ch) { return std::tolower(ch); }); |
| 117 | + |
| 118 | + REQUIRE(ut::fnv_1a<std::size_t>(str1) != ut::fnv_1a<std::size_t>(str2)); |
| 119 | + REQUIRE(ut::fnv_1a<std::size_t, ut::CHIgnoreCase::No>(str1) != ut::fnv_1a<std::size_t, ut::CHIgnoreCase::No>(str2)); |
| 120 | + REQUIRE(ut::fnv_1a<std::size_t, ut::CHIgnoreCase::Yes>(str1) == ut::fnv_1a<std::size_t, ut::CHIgnoreCase::Yes>(str2)); |
| 121 | + REQUIRE(ut::fnv_1a<std::size_t, ut::CHIgnoreCase::Yes>(str1) == ut::fnv_1a<std::size_t, ut::CHIgnoreCase::No>(str2)); |
| 122 | +} |
0 commit comments