1 #include "str_utility.hpp"
2 
3 #include <string>
4 #include <vector>
5 
6 #include <gmock/gmock.h>
7 #include <gtest/gtest.h>
8 
9 namespace
10 {
11 
12 using ::testing::ElementsAre;
13 
TEST(Split,PositiveTests)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"));
20 
21     vec.clear();
22     split(vec, "", '-');
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 
TEST(Split,Sensor)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"));
45 }
46 
TEST(AsciiToLower,Positive)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 
TEST(AsciiIEquals,Positive)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 
72 } // namespace
73