blob: c52cab9527b904ebe12c9884b569ef5b7a89a08b [file] [log] [blame]
Ed Tanous50ebd4a2023-01-19 19:03:17 -08001#include "str_utility.hpp"
2
3#include <string>
4#include <vector>
5
6#include <gmock/gmock.h> // IWYU pragma: keep
7#include <gtest/gtest.h> // IWYU pragma: keep
8
9// IWYU pragma: no_include <gtest/gtest-message.h>
10// IWYU pragma: no_include <gtest/gtest-test-part.h>
11// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
12// IWYU pragma: no_include <gmock/gmock-matchers.h>
13
14namespace
15{
16
17using ::testing::ElementsAre;
Ed Tanous50ebd4a2023-01-19 19:03:17 -080018
19TEST(Split, PositiveTests)
20{
21 using bmcweb::split;
22 std::vector<std::string> vec;
23 split(vec, "xx-abc-xx-abb", '-');
24 EXPECT_THAT(vec, ElementsAre("xx", "abc", "xx", "abb"));
Ed Tanousb64c6262023-02-21 10:27:14 -080025
Ed Tanous50ebd4a2023-01-19 19:03:17 -080026 vec.clear();
27 split(vec, "", '-');
Ed Tanousb64c6262023-02-21 10:27:14 -080028 EXPECT_THAT(vec, ElementsAre(""));
29
30 vec.clear();
31 split(vec, "foo/", '/');
32 EXPECT_THAT(vec, ElementsAre("foo", ""));
33
34 vec.clear();
35 split(vec, "/bar", '/');
36 EXPECT_THAT(vec, ElementsAre("", "bar"));
37
38 vec.clear();
39 split(vec, "/", '/');
40 EXPECT_THAT(vec, ElementsAre("", ""));
41}
42
43TEST(Split, Sensor)
44{
45 using bmcweb::split;
46 std::vector<std::string> vec;
47 split(vec, "/xyz/openbmc_project/sensors/unit/name", '/');
48 EXPECT_THAT(vec, ElementsAre("", "xyz", "openbmc_project", "sensors",
49 "unit", "name"));
Ed Tanous50ebd4a2023-01-19 19:03:17 -080050}
51
Ed Tanous18f8f602023-07-18 10:07:23 -070052TEST(AsciiToLower, Positive)
53{
54 using bmcweb::asciiToLower;
55 // Noop
56 EXPECT_EQ(asciiToLower('a'), 'a');
57 EXPECT_EQ(asciiToLower('z'), 'z');
58 EXPECT_EQ(asciiToLower('0'), '0');
59 EXPECT_EQ(asciiToLower('_'), '_');
60
61 // Converted
62 EXPECT_EQ(asciiToLower('A'), 'a');
63 EXPECT_EQ(asciiToLower('Z'), 'z');
64}
65
66TEST(AsciiIEquals, Positive)
67{
68 using bmcweb::asciiIEquals;
69 EXPECT_TRUE(asciiIEquals("FOO", "foo"));
70 EXPECT_TRUE(asciiIEquals("foo", "foo"));
71 EXPECT_TRUE(asciiIEquals("", ""));
72 EXPECT_TRUE(asciiIEquals("_", "_"));
73
74 EXPECT_FALSE(asciiIEquals("bar", "foo"));
75}
76
Ed Tanous50ebd4a2023-01-19 19:03:17 -080077} // namespace