|
@@ -1,33 +1,7 @@
|
|
|
-#include <cstddef>
|
|
|
|
|
|
|
+#include <type_traits>
|
|
|
#include <gtest/gtest.h>
|
|
#include <gtest/gtest.h>
|
|
|
#include <entt/core/hashed_string.hpp>
|
|
#include <entt/core/hashed_string.hpp>
|
|
|
|
|
|
|
|
-static constexpr bool ptr(const char *str) {
|
|
|
|
|
- using hash_type = entt::HashedString::hash_type;
|
|
|
|
|
-
|
|
|
|
|
- return (static_cast<hash_type>(entt::HashedString{str}) == entt::HashedString{str}
|
|
|
|
|
- && static_cast<const char *>(entt::HashedString{str}) == str
|
|
|
|
|
- && entt::HashedString{str} == entt::HashedString{str}
|
|
|
|
|
- && !(entt::HashedString{str} != entt::HashedString{str}));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-template<std::size_t N>
|
|
|
|
|
-static constexpr bool ref(const char (&str)[N]) {
|
|
|
|
|
- using hash_type = entt::HashedString::hash_type;
|
|
|
|
|
-
|
|
|
|
|
- return (static_cast<hash_type>(entt::HashedString{str}) == entt::HashedString{str}
|
|
|
|
|
- && static_cast<const char *>(entt::HashedString{str}) == str
|
|
|
|
|
- && entt::HashedString{str} == entt::HashedString{str}
|
|
|
|
|
- && !(entt::HashedString{str} != entt::HashedString{str}));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-TEST(HashedString, Constexprness) {
|
|
|
|
|
- // how would you test a constexpr otherwise?
|
|
|
|
|
- static_assert(ptr("foo"), "!");
|
|
|
|
|
- static_assert(ref("bar"), "!");
|
|
|
|
|
- ASSERT_TRUE(true);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
TEST(HashedString, Functionalities) {
|
|
TEST(HashedString, Functionalities) {
|
|
|
using hash_type = entt::HashedString::hash_type;
|
|
using hash_type = entt::HashedString::hash_type;
|
|
|
|
|
|
|
@@ -40,10 +14,21 @@ TEST(HashedString, Functionalities) {
|
|
|
ASSERT_EQ(static_cast<const char *>(fooHs), "foo");
|
|
ASSERT_EQ(static_cast<const char *>(fooHs), "foo");
|
|
|
ASSERT_EQ(static_cast<const char *>(barHs), bar);
|
|
ASSERT_EQ(static_cast<const char *>(barHs), bar);
|
|
|
|
|
|
|
|
- ASSERT_TRUE(fooHs == fooHs);
|
|
|
|
|
- ASSERT_TRUE(fooHs != barHs);
|
|
|
|
|
|
|
+ ASSERT_EQ(fooHs, fooHs);
|
|
|
|
|
+ ASSERT_NE(fooHs, barHs);
|
|
|
|
|
|
|
|
entt::HashedString hs{"foobar"};
|
|
entt::HashedString hs{"foobar"};
|
|
|
|
|
|
|
|
ASSERT_EQ(static_cast<hash_type>(hs), 0x85944171f73967e8);
|
|
ASSERT_EQ(static_cast<hash_type>(hs), 0x85944171f73967e8);
|
|
|
|
|
+
|
|
|
|
|
+ ASSERT_EQ(fooHs, "foo"_hs);
|
|
|
|
|
+ ASSERT_NE(barHs, "foo"_hs);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST(HashedString, Constexprness) {
|
|
|
|
|
+ using hash_type = entt::HashedString::hash_type;
|
|
|
|
|
+ // how would you test a constexpr otherwise?
|
|
|
|
|
+ (void)std::integral_constant<hash_type, entt::HashedString{"quux"}>{};
|
|
|
|
|
+ (void)std::integral_constant<hash_type, "quux"_hs>{};
|
|
|
|
|
+ ASSERT_TRUE(true);
|
|
|
}
|
|
}
|