test: add tests for string split

This commit is contained in:
Steffen Winter
2025-11-05 00:13:33 +01:00
committed by Steffen
parent ede6b18eb7
commit 7e76afbfab
2 changed files with 32 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
include(FetchContent)
FetchContent_Declare(
googletest
@@ -8,4 +10,11 @@ FetchContent_Declare(
FetchContent_MakeAvailable(googletest)
add_library(libbtop_test INTERFACE)
target_include_directories(libbtop_test INTERFACE ${PROJECT_SOURCE_DIR}/src)
target_link_libraries(libbtop_test INTERFACE libbtop GTest::gtest_main)
add_executable(btop_test tools.cpp)
target_link_libraries(btop_test libbtop_test)
include(GoogleTest)
gtest_discover_tests(btop_test)

23
tests/tools.cpp Normal file
View File

@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
#include <vector>
#include <gtest/gtest.h>
#include "btop_tools.hpp"
TEST(tools, string_split) {
EXPECT_EQ(Tools::ssplit(""), std::vector<std::string> {});
EXPECT_EQ(Tools::ssplit("foo"), std::vector<std::string> { "foo" });
{
auto actual = Tools::ssplit("foo bar baz ");
auto expected = std::vector<std::string> { "foo", "bar", "baz" };
EXPECT_EQ(actual, expected);
}
{
auto actual = Tools::ssplit("foobo oho barbo bo bazbo", 'o');
auto expected = std::vector<std::string> { "f", "b", " ", "h", " barb", " b", " bazb" };
EXPECT_EQ(actual, expected);
}
}