diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 15773d8..5b54873 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/tools.cpp b/tests/tools.cpp new file mode 100644 index 0000000..978ed74 --- /dev/null +++ b/tests/tools.cpp @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include + +#include "btop_tools.hpp" + +TEST(tools, string_split) { + EXPECT_EQ(Tools::ssplit(""), std::vector {}); + EXPECT_EQ(Tools::ssplit("foo"), std::vector { "foo" }); + { + auto actual = Tools::ssplit("foo bar baz "); + auto expected = std::vector { "foo", "bar", "baz" }; + EXPECT_EQ(actual, expected); + } + + { + auto actual = Tools::ssplit("foobo oho barbo bo bazbo", 'o'); + auto expected = std::vector { "f", "b", " ", "h", " barb", " b", " bazb" }; + EXPECT_EQ(actual, expected); + } +}