#include "catch.hpp" #include TEST_CASE("split_string string") { const std::string str{"foo,baramba,baz"}; const std::vector result = {"foo", "baramba", "baz"}; REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ',', true)); REQUIRE(result == osmium::split_string(str, ",;")); REQUIRE(result == osmium::split_string(str, ",;", true)); } TEST_CASE("split_string string without sep") { const std::string str{"foo"}; const std::vector result = {"foo"}; REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ',', true)); REQUIRE(result == osmium::split_string(str, ",;")); REQUIRE(result == osmium::split_string(str, ",;", true)); } TEST_CASE("split_string string with empty at end") { const std::string str{"foo,bar,"}; const std::vector result = {"foo", "bar", ""}; const std::vector resultc = {"foo", "bar"}; REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(resultc == osmium::split_string(str, ',', true)); REQUIRE(result == osmium::split_string(str, ";,")); REQUIRE(resultc == osmium::split_string(str, ";,", true)); } TEST_CASE("split_string string with empty in middle") { const std::string str{"foo,,bar"}; const std::vector result = {"foo", "", "bar"}; const std::vector resultc = {"foo", "bar"}; REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(resultc == osmium::split_string(str, ',', true)); REQUIRE(result == osmium::split_string(str, ",;")); REQUIRE(resultc == osmium::split_string(str, ";,", true)); } TEST_CASE("split_string string with empty at start") { const std::string str{",bar,baz"}; const std::vector result = {"", "bar", "baz"}; const std::vector resultc = {"bar", "baz"}; REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(resultc == osmium::split_string(str, ',', true)); REQUIRE(result == osmium::split_string(str, ";,")); REQUIRE(resultc == osmium::split_string(str, ",;", true)); } TEST_CASE("split_string sep") { const std::string str{","}; const std::vector result = {"", ""}; const std::vector resultc; REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(resultc == osmium::split_string(str, ',', true)); REQUIRE(result == osmium::split_string(str, ",;")); REQUIRE(resultc == osmium::split_string(str, ",;", true)); } TEST_CASE("split_string empty string") { const std::string str{""}; const std::vector result; REQUIRE(result == osmium::split_string(str, ',')); REQUIRE(result == osmium::split_string(str, ',', true)); REQUIRE(result == osmium::split_string(str, ",;")); REQUIRE(result == osmium::split_string(str, ",;", true)); } TEST_CASE("split_string string with multiple sep characters") { const std::string str{"foo,bar;baz-,blub"}; const std::vector result = {"foo", "bar", "baz", "", "blub"}; REQUIRE(result == osmium::split_string(str, ";,-")); }