]>
git.saurik.com Git - apt.git/blob - test/libapt/strutil_test.cc
2 #include <apt-pkg/strutl.h>
6 #include <gtest/gtest.h>
8 TEST(StrUtilTest
,DeEscapeString
)
11 EXPECT_EQ("", DeEscapeString(""));
12 EXPECT_EQ("foobar", DeEscapeString("foobar"));
14 EXPECT_EQ("foo bar\nbaz", DeEscapeString("foo\\040bar\\x0abaz"));
15 EXPECT_EQ("foo ", DeEscapeString("foo\\040"));
16 EXPECT_EQ("\nbaz", DeEscapeString("\\x0abaz"));
17 EXPECT_EQ("/media/Ubuntu 11.04 amd64", DeEscapeString("/media/Ubuntu\\04011.04\\040amd64"));
19 EXPECT_EQ("foo\\ x", DeEscapeString("foo\\\\ x"));
20 EXPECT_EQ("\\foo\\", DeEscapeString("\\\\foo\\\\"));
22 TEST(StrUtilTest
,StringSplitBasic
)
24 std::vector
<std::string
> result
= StringSplit("", "");
25 EXPECT_EQ(result
.size(), 0);
27 result
= StringSplit("abc", "");
28 EXPECT_EQ(result
.size(), 0);
30 result
= StringSplit("", "abc");
31 EXPECT_EQ(result
.size(), 1);
33 result
= StringSplit("abc", "b");
34 ASSERT_EQ(result
.size(), 2);
35 EXPECT_EQ(result
[0], "a");
36 EXPECT_EQ(result
[1], "c");
38 result
= StringSplit("abc", "abc");
39 ASSERT_EQ(result
.size(), 2);
40 EXPECT_EQ(result
[0], "");
41 EXPECT_EQ(result
[1], "");
43 TEST(StrUtilTest
,StringSplitDpkgStatus
)
45 std::string
const input
= "status: libnet1:amd64: unpacked";
46 std::vector
<std::string
> result
= StringSplit(input
, "xxx");
47 ASSERT_EQ(result
.size(), 1);
48 EXPECT_EQ(result
[0], input
);
50 result
= StringSplit(input
, "");
51 EXPECT_EQ(result
.size(), 0);
53 result
= StringSplit(input
, ": ");
54 ASSERT_EQ(result
.size(), 3);
55 EXPECT_EQ(result
[0], "status");
56 EXPECT_EQ(result
[1], "libnet1:amd64");
57 EXPECT_EQ(result
[2], "unpacked");
59 result
= StringSplit("x:y:z", ":", 2);
60 ASSERT_EQ(result
.size(), 2);
61 EXPECT_EQ(result
[0], "x");
62 EXPECT_EQ(result
[1], "y:z");
64 TEST(StrUtilTest
,EndsWith
)
66 using APT::String::Endswith
;
67 EXPECT_TRUE(Endswith("abcd", "d"));
68 EXPECT_TRUE(Endswith("abcd", "cd"));
69 EXPECT_TRUE(Endswith("abcd", "abcd"));
70 EXPECT_FALSE(Endswith("abcd", "x"));
71 EXPECT_FALSE(Endswith("abcd", "abcndefg"));