]>
Commit | Line | Data |
---|---|---|
1 | #include <config.h> | |
2 | ||
3 | #include <apt-pkg/strutl.h> | |
4 | ||
5 | #include <string> | |
6 | #include <vector> | |
7 | ||
8 | #include "assert.h" | |
9 | ||
10 | int main() | |
11 | { | |
12 | std::string input, output, expected; | |
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 | ||
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 | ||
50 | // Split | |
51 | input = "status: libnet1:amd64: unpacked"; | |
52 | std::vector<std::string> result = StringSplit(input, ": "); | |
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 | ||
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 | ||
73 | input = "abc"; | |
74 | result = StringSplit(input, ""); | |
75 | equals(result.size(), 0); | |
76 | ||
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 | ||
95 | return 0; | |
96 | } |