diff options
author | Ed Tanous <edtanous@google.com> | 2023-02-21 21:27:14 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-02-21 22:51:59 +0300 |
commit | b64c62627d7a7473a590dcd97b7b50c57d599786 (patch) | |
tree | 1962101c8f3b2bad36362ee2eec64ac1e2afa714 /test | |
parent | e645c5e6a922817a56c3b9452799b8b4cce38a7c (diff) | |
download | bmcweb-b64c62627d7a7473a590dcd97b7b50c57d599786.tar.xz |
Disable token compress in str
There are certain cases where we use this split function, and we expect
tokens to be read out. For example:
/xyz/openbmc_project/sensors/unit/name
Should split into a "" in the first position. This use case is not
common, and a quick grep shows only two places in the code expect this
behavior. Boost::split has this behavior already, which is what this
function is emulating. While we could fix these, in the end they should
be following the rules outlined in COMMON_ERRORS.md, which disallow
this kind of parsing completely.
Tested: New unit tests passing.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Iec3dcbf2b495b2b3b4ed419172c4133b16f7c65d
Diffstat (limited to 'test')
-rw-r--r-- | test/include/str_utility_test.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/test/include/str_utility_test.cpp b/test/include/str_utility_test.cpp index bab14c96bf..a32ce09d95 100644 --- a/test/include/str_utility_test.cpp +++ b/test/include/str_utility_test.cpp @@ -15,7 +15,6 @@ namespace { using ::testing::ElementsAre; -using ::testing::IsEmpty; TEST(Split, PositiveTests) { @@ -23,9 +22,31 @@ TEST(Split, PositiveTests) std::vector<std::string> vec; split(vec, "xx-abc-xx-abb", '-'); EXPECT_THAT(vec, ElementsAre("xx", "abc", "xx", "abb")); + vec.clear(); split(vec, "", '-'); - EXPECT_THAT(vec, IsEmpty()); + EXPECT_THAT(vec, ElementsAre("")); + + vec.clear(); + split(vec, "foo/", '/'); + EXPECT_THAT(vec, ElementsAre("foo", "")); + + vec.clear(); + split(vec, "/bar", '/'); + EXPECT_THAT(vec, ElementsAre("", "bar")); + + vec.clear(); + split(vec, "/", '/'); + EXPECT_THAT(vec, ElementsAre("", "")); +} + +TEST(Split, Sensor) +{ + using bmcweb::split; + std::vector<std::string> vec; + split(vec, "/xyz/openbmc_project/sensors/unit/name", '/'); + EXPECT_THAT(vec, ElementsAre("", "xyz", "openbmc_project", "sensors", + "unit", "name")); } } // namespace |