Standardize iFindFirst
iFindFirst was added in the previous commit. Move it to using
std::ranges::subrange, withi is a direct replacement for boost, rather
than inventing a new type.
Tested: Unit tests pass.
Change-Id: I6d88fc90f34ee0748b52e9fb6438635f9cdbd0a9
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/test/meson.build b/test/meson.build
index 50f0901..adb6097 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -62,6 +62,6 @@
'test_utils.cpp',
'../src/utils.cpp',
include_directories: test_include_dir,
- dependencies: [gtest, phosphor_logging_dep],
+ dependencies: [gtest, phosphor_logging_dep, sdbusplus],
),
)
diff --git a/test/test_utils.cpp b/test/test_utils.cpp
index 76570df..7c67e9b 100644
--- a/test/test_utils.cpp
+++ b/test/test_utils.cpp
@@ -2,51 +2,54 @@
#include <gtest/gtest.h>
+constexpr std::string_view helloWorld = "Hello World";
+
TEST(IfindFirstTest, BasicMatch)
{
- auto [firstIndex, lastIndex] = iFindFirst("Hello World", "World");
- EXPECT_EQ(firstIndex, 6);
- EXPECT_EQ(lastIndex, 11);
+ auto match = iFindFirst(helloWorld, "World");
+ EXPECT_TRUE(match);
+ EXPECT_EQ(std::distance(helloWorld.begin(), match.begin()), 6);
+ EXPECT_EQ(std::distance(helloWorld.begin(), match.end()), 11);
}
TEST(IfindFirstTest, CaseInsensitiveMatch)
{
- auto [firstIndex, lastIndex] = iFindFirst("Hello World", "world");
- EXPECT_EQ(firstIndex, 6);
- EXPECT_EQ(lastIndex, 11);
+ auto match = iFindFirst(helloWorld, "world");
+ EXPECT_TRUE(match);
+ EXPECT_EQ(std::distance(helloWorld.begin(), match.begin()), 6);
+ EXPECT_EQ(std::distance(helloWorld.begin(), match.end()), 11);
}
TEST(IfindFirstTest, NoMatch)
{
- auto [firstIndex, lastIndex] = iFindFirst("Hello World", "Planet");
- EXPECT_EQ(firstIndex, std::string_view::npos);
- EXPECT_EQ(lastIndex, std::string_view::npos);
+ auto match = iFindFirst(helloWorld, "Planet");
+ EXPECT_FALSE(match);
}
TEST(IfindFirstTest, MatchAtStart)
{
- auto [firstIndex, lastIndex] = iFindFirst("Hello World", "HeLLo");
- EXPECT_EQ(firstIndex, 0);
- EXPECT_EQ(lastIndex, 5);
+ auto match = iFindFirst(helloWorld, "HeLLo");
+ EXPECT_TRUE(match);
+ EXPECT_EQ(std::distance(helloWorld.begin(), match.begin()), 0);
+ EXPECT_EQ(std::distance(helloWorld.begin(), match.end()), 5);
}
TEST(IfindFirstTest, MatchAtEnd)
{
- auto [firstIndex, lastIndex] = iFindFirst("Hello World", "LD");
- EXPECT_EQ(firstIndex, 9);
- EXPECT_EQ(lastIndex, 11);
+ auto match = iFindFirst(helloWorld, "LD");
+ EXPECT_TRUE(match);
+ EXPECT_EQ(std::distance(helloWorld.begin(), match.begin()), 9);
+ EXPECT_EQ(std::distance(helloWorld.begin(), match.end()), 11);
}
TEST(IfindFirstTest, EmptySubstring)
{
- auto [firstIndex, lastIndex] = iFindFirst("Hello", "");
- EXPECT_EQ(firstIndex, std::string_view::npos);
- EXPECT_EQ(lastIndex, std::string_view::npos);
+ auto match = iFindFirst(helloWorld, "");
+ EXPECT_FALSE(match);
}
TEST(IfindFirstTest, EmptyString)
{
- auto [firstIndex, lastIndex] = iFindFirst("", "Hello");
- EXPECT_EQ(firstIndex, std::string_view::npos);
- EXPECT_EQ(lastIndex, std::string_view::npos);
+ auto match = iFindFirst("", "Hello");
+ EXPECT_FALSE(match);
}