]> git.saurik.com Git - apt.git/blob - test/libapt/strutil_test.cc
start adding apt.8.xml
[apt.git] / test / libapt / strutil_test.cc
1 #include <apt-pkg/strutl.h>
2
3 #include "assert.h"
4
5 int main(int argc,char *argv[])
6 {
7 std::string input, output, expected;
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
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
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
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
68 input = "abc";
69 result = StringSplit(input, "");
70 equals(result.size(), 0);
71
72 return 0;
73 }