mirror of
https://github.com/aristocratos/btop.git
synced 2025-12-23 22:29:08 -05:00
test: add tests for string split
This commit is contained in:
@@ -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
23
tests/tools.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user