blob: a214d31114be5befe96a43e5a397a77e29b6c366 [file] [log] [blame]
Ed Tanous50ebd4a2023-01-19 19:03:17 -08001#include "str_utility.hpp"
2
3#include <string>
4#include <vector>
5
Ed Tanous478b7ad2024-07-15 19:11:54 -07006#include <gmock/gmock.h>
7#include <gtest/gtest.h>
Ed Tanous50ebd4a2023-01-19 19:03:17 -08008
9namespace
10{
11
12using ::testing::ElementsAre;
Ed Tanous50ebd4a2023-01-19 19:03:17 -080013
14TEST(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 Tanousb64c6262023-02-21 10:27:14 -080020
Ed Tanous50ebd4a2023-01-19 19:03:17 -080021 vec.clear();
22 split(vec, "", '-');
Ed Tanousb64c6262023-02-21 10:27:14 -080023 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
38TEST(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 Tanous50ebd4a2023-01-19 19:03:17 -080045}
46
Ed Tanous18f8f602023-07-18 10:07:23 -070047TEST(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
61TEST(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 Tanous50ebd4a2023-01-19 19:03:17 -080072} // namespace