mirror of
https://github.com/chase/awrit.git
synced 2026-10-15 00:49:22 +02:00
63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
#include "string_utils.h"
|
|
|
|
using namespace string;
|
|
|
|
TEST(SplitTest, NoView) {
|
|
std::string_view input{};
|
|
std::vector<std::string_view> expected_output = {};
|
|
char delimiter = ';';
|
|
|
|
auto result = split(input, delimiter);
|
|
ASSERT_EQ(expected_output, result);
|
|
}
|
|
|
|
TEST(SplitTest, EmptyString) {
|
|
std::string_view input = "";
|
|
std::vector<std::string_view> expected_output = {};
|
|
char delimiter = ';';
|
|
|
|
auto result = split(input, delimiter);
|
|
ASSERT_EQ(expected_output, result);
|
|
}
|
|
|
|
TEST(SplitTest, SingleCharacterDelimiter) {
|
|
std::string_view input = "a;b;c";
|
|
std::vector<std::string_view> expected_output = {"a", "b", "c"};
|
|
char delimiter = ';';
|
|
|
|
auto result = split(input, delimiter);
|
|
ASSERT_EQ(expected_output, result);
|
|
}
|
|
|
|
TEST(SplitTest, NoDelimiterInString) {
|
|
std::string_view input = "abc";
|
|
std::vector<std::string_view> expected_output = {"abc"};
|
|
char delimiter = ';';
|
|
|
|
auto result = split(input, delimiter);
|
|
ASSERT_EQ(expected_output, result);
|
|
}
|
|
|
|
TEST(SplitTest, ConsecutiveDelimiters) {
|
|
std::string_view input = "a;;b;c;";
|
|
std::vector<std::string_view> expected_output = {"a", "", "b", "c", ""};
|
|
char delimiter = ';';
|
|
|
|
auto result = split(input, delimiter);
|
|
ASSERT_EQ(expected_output, result);
|
|
}
|
|
|
|
TEST(SplitTest, OtherDelimiter) {
|
|
std::string_view input = "a:b:c";
|
|
std::vector<std::string_view> expected_output = {"a", "b", "c"};
|
|
char delimiter = ':';
|
|
|
|
auto result = split(input, delimiter);
|
|
ASSERT_EQ(expected_output, result);
|
|
}
|