]>
Commit | Line | Data |
---|---|---|
453b82a3 DK |
1 | #include <config.h> |
2 | ||
a513ace2 MV |
3 | #include <apt-pkg/strutl.h> |
4 | ||
453b82a3 DK |
5 | #include <string> |
6 | #include <vector> | |
7 | ||
a513ace2 MV |
8 | #include "assert.h" |
9 | ||
65512241 | 10 | int main() |
a513ace2 | 11 | { |
8f3ba4e8 | 12 | std::string input, output, expected; |
a513ace2 MV |
13 | |
14 | // no input | |
15 | input = "foobar"; | |
16 | expected = "foobar"; | |
17 | output = DeEscapeString(input); | |
18 | equals(output, expected); | |
19 | ||
20 | // hex and octal | |
21 | input = "foo\\040bar\\x0abaz"; | |
22 | expected = "foo bar\nbaz"; | |
23 | output = DeEscapeString(input); | |
24 | equals(output, expected); | |
25 | ||
26 | // at the end | |
27 | input = "foo\\040"; | |
28 | expected = "foo "; | |
29 | output = DeEscapeString(input); | |
30 | equals(output, expected); | |
31 | ||
32 | // double escape | |
33 | input = "foo\\\\ x"; | |
34 | expected = "foo\\ x"; | |
35 | output = DeEscapeString(input); | |
36 | equals(output, expected); | |
37 | ||
38 | // double escape at the end | |
39 | input = "\\\\foo\\\\"; | |
40 | expected = "\\foo\\"; | |
41 | output = DeEscapeString(input); | |
42 | equals(output, expected); | |
43 | ||
b9dc4706 MV |
44 | // the string that we actually need it for |
45 | input = "/media/Ubuntu\\04011.04\\040amd64"; | |
46 | expected = "/media/Ubuntu 11.04 amd64"; | |
47 | output = DeEscapeString(input); | |
48 | equals(output, expected); | |
49 | ||
00f4d9ff MV |
50 | // Split |
51 | input = "status: libnet1:amd64: unpacked"; | |
453b82a3 | 52 | std::vector<std::string> result = StringSplit(input, ": "); |
00f4d9ff MV |
53 | equals(result[0], "status"); |
54 | equals(result[1], "libnet1:amd64"); | |
55 | equals(result[2], "unpacked"); | |
56 | equals(result.size(), 3); | |
57 | ||
58 | input = "status: libnet1:amd64: unpacked"; | |
59 | result = StringSplit(input, "xxx"); | |
60 | equals(result[0], input); | |
61 | equals(result.size(), 1); | |
62 | ||
63 | input = "status: libnet1:amd64: unpacked"; | |
64 | result = StringSplit(input, ""); | |
65 | equals(result.size(), 0); | |
66 | ||
85bf0019 MV |
67 | input = "x:y:z"; |
68 | result = StringSplit(input, ":", 2); | |
69 | equals(result.size(), 2); | |
70 | equals(result[0], "x"); | |
71 | equals(result[1], "y:z"); | |
72 | ||
2ddab3fb MV |
73 | input = "abc"; |
74 | result = StringSplit(input, ""); | |
75 | equals(result.size(), 0); | |
76 | ||
cf993341 MV |
77 | // endswith |
78 | bool b; | |
79 | input = "abcd"; | |
80 | b = APT::String::Endswith(input, "d"); | |
81 | equals(b, true); | |
82 | ||
83 | b = APT::String::Endswith(input, "cd"); | |
84 | equals(b, true); | |
85 | ||
86 | b = APT::String::Endswith(input, "abcd"); | |
87 | equals(b, true); | |
88 | ||
89 | b = APT::String::Endswith(input, "x"); | |
90 | equals(b, false); | |
91 | ||
92 | b = APT::String::Endswith(input, "abcndefg"); | |
93 | equals(b, false); | |
94 | ||
a513ace2 MV |
95 | return 0; |
96 | } |