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