Files
MapLibreParticleLab/test/util/string_indexer.test.cpp
Tim Sylvester 25c1f3c7a6 Rebase fill-extrusion work to eliminate dependence on render target branch (#1618)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Alex Cristici <alex.cristici@gmail.com>
Co-authored-by: mwilsnd <mwilsnd@gmail.com>
Co-authored-by: Stefan Karschti <stefan.karschti@gmail.com>
Co-authored-by: Bart Louwers <bart@emeel.net>
Co-authored-by: Alex Cristici <alex@skoon.energy>
Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
Co-authored-by: Wei Chen <alanchenboy@gmail.com>
Co-authored-by: Siarhei Fedartsou <siarhei.fedartsou@gmail.com>
Co-authored-by: tdcosta100 <tdcosta100@gmail.com>
2023-09-15 16:02:26 -07:00

51 lines
1.3 KiB
C++

#include <mbgl/test/util.hpp>
#include <mbgl/util/string_indexer.hpp>
#include <cstdint>
using namespace mbgl;
TEST(StringIndexer, AddStrings) {
StringIndexer::clear();
EXPECT_EQ(StringIndexer::size(), 0);
const auto id1 = StringIndexer::get("test string1");
EXPECT_EQ(id1, 0);
EXPECT_EQ(StringIndexer::size(), 1);
const std::string_view s2 = "test string2";
const auto id2 = StringIndexer::get(s2);
EXPECT_EQ(id2, 1);
EXPECT_EQ(StringIndexer::size(), 2);
}
TEST(StringIndexer, GetString) {
StringIndexer::clear();
EXPECT_EQ(StringIndexer::size(), 0);
constexpr auto str = "test string1";
const auto id1 = StringIndexer::get(str);
EXPECT_EQ(id1, 0);
EXPECT_EQ(StringIndexer::size(), 1);
const std::string str1 = StringIndexer::get(id1);
EXPECT_EQ(str, str1);
const auto str2 = str;
const auto id2 = StringIndexer::get(str2);
EXPECT_EQ(id1, id2);
}
TEST(StringIndexer, GetOOBIdentity) {
StringIndexer::clear();
EXPECT_EQ(StringIndexer::size(), 0);
std::string str;
EXPECT_DEATH_IF_SUPPORTED(str = StringIndexer::get(42), "id < identityToString.size()");
EXPECT_TRUE(str.empty());
EXPECT_DEATH_IF_SUPPORTED(str = StringIndexer::get(-1), "id < identityToString.size()");
EXPECT_TRUE(str.empty());
}