Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 1 | #include "str_utility.hpp" |
| 2 | |
| 3 | #include <string> |
| 4 | #include <vector> |
| 5 | |
Ed Tanous | 478b7ad | 2024-07-15 19:11:54 -0700 | [diff] [blame] | 6 | #include <gmock/gmock.h> |
| 7 | #include <gtest/gtest.h> |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 8 | |
| 9 | namespace |
| 10 | { |
| 11 | |
| 12 | using ::testing::ElementsAre; |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 13 | |
| 14 | TEST(Split, PositiveTests) |
| 15 | { |
| 16 | using bmcweb::split; |
| 17 | std::vector<std::string> vec; |
| 18 | split(vec, "xx-abc-xx-abb", '-'); |
| 19 | EXPECT_THAT(vec, ElementsAre("xx", "abc", "xx", "abb")); |
Ed Tanous | b64c626 | 2023-02-21 10:27:14 -0800 | [diff] [blame] | 20 | |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 21 | vec.clear(); |
| 22 | split(vec, "", '-'); |
Ed Tanous | b64c626 | 2023-02-21 10:27:14 -0800 | [diff] [blame] | 23 | EXPECT_THAT(vec, ElementsAre("")); |
| 24 | |
| 25 | vec.clear(); |
| 26 | split(vec, "foo/", '/'); |
| 27 | EXPECT_THAT(vec, ElementsAre("foo", "")); |
| 28 | |
| 29 | vec.clear(); |
| 30 | split(vec, "/bar", '/'); |
| 31 | EXPECT_THAT(vec, ElementsAre("", "bar")); |
| 32 | |
| 33 | vec.clear(); |
| 34 | split(vec, "/", '/'); |
| 35 | EXPECT_THAT(vec, ElementsAre("", "")); |
| 36 | } |
| 37 | |
| 38 | TEST(Split, Sensor) |
| 39 | { |
| 40 | using bmcweb::split; |
| 41 | std::vector<std::string> vec; |
| 42 | split(vec, "/xyz/openbmc_project/sensors/unit/name", '/'); |
| 43 | EXPECT_THAT(vec, ElementsAre("", "xyz", "openbmc_project", "sensors", |
| 44 | "unit", "name")); |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 47 | TEST(AsciiToLower, Positive) |
| 48 | { |
| 49 | using bmcweb::asciiToLower; |
| 50 | // Noop |
| 51 | EXPECT_EQ(asciiToLower('a'), 'a'); |
| 52 | EXPECT_EQ(asciiToLower('z'), 'z'); |
| 53 | EXPECT_EQ(asciiToLower('0'), '0'); |
| 54 | EXPECT_EQ(asciiToLower('_'), '_'); |
| 55 | |
| 56 | // Converted |
| 57 | EXPECT_EQ(asciiToLower('A'), 'a'); |
| 58 | EXPECT_EQ(asciiToLower('Z'), 'z'); |
| 59 | } |
| 60 | |
| 61 | TEST(AsciiIEquals, Positive) |
| 62 | { |
| 63 | using bmcweb::asciiIEquals; |
| 64 | EXPECT_TRUE(asciiIEquals("FOO", "foo")); |
| 65 | EXPECT_TRUE(asciiIEquals("foo", "foo")); |
| 66 | EXPECT_TRUE(asciiIEquals("", "")); |
| 67 | EXPECT_TRUE(asciiIEquals("_", "_")); |
| 68 | |
| 69 | EXPECT_FALSE(asciiIEquals("bar", "foo")); |
| 70 | } |
| 71 | |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 72 | } // namespace |