Add unit tests for Commit parsing
[libgit2.git] / tests / t0003-strutil.c
blob8399c6e8a4fce8eb0448429ad557eae77d2d78ab
1 #include "test_lib.h"
2 #include "common.h"
4 BEGIN_TEST(prefixcmp_empty_empty)
5 must_be_true(git__prefixcmp("", "") == 0);
6 END_TEST
8 BEGIN_TEST(prefixcmp_a_empty)
9 must_be_true(git__prefixcmp("a", "") == 0);
10 END_TEST
12 BEGIN_TEST(prefixcmp_empty_a)
13 must_be_true(git__prefixcmp("", "a") < 0);
14 END_TEST
16 BEGIN_TEST(prefixcmp_a_b)
17 must_be_true(git__prefixcmp("a", "b") < 0);
18 END_TEST
20 BEGIN_TEST(prefixcmp_b_a)
21 must_be_true(git__prefixcmp("b", "a") > 0);
22 END_TEST
24 BEGIN_TEST(prefixcmp_ab_a)
25 must_be_true(git__prefixcmp("ab", "a") == 0);
26 END_TEST
28 BEGIN_TEST(prefixcmp_ab_ac)
29 must_be_true(git__prefixcmp("ab", "ac") < 0);
30 END_TEST
32 BEGIN_TEST(prefixcmp_ab_aa)
33 must_be_true(git__prefixcmp("ab", "aa") > 0);
34 END_TEST
37 BEGIN_TEST(suffixcmp_empty_empty)
38 must_be_true(git__suffixcmp("", "") == 0);
39 END_TEST
41 BEGIN_TEST(suffixcmp_a_empty)
42 must_be_true(git__suffixcmp("a", "") == 0);
43 END_TEST
45 BEGIN_TEST(suffixcmp_empty_a)
46 must_be_true(git__suffixcmp("", "a") < 0);
47 END_TEST
49 BEGIN_TEST(suffixcmp_a_b)
50 must_be_true(git__suffixcmp("a", "b") < 0);
51 END_TEST
53 BEGIN_TEST(suffixcmp_b_a)
54 must_be_true(git__suffixcmp("b", "a") > 0);
55 END_TEST
57 BEGIN_TEST(suffixcmp_ba_a)
58 must_be_true(git__suffixcmp("ba", "a") == 0);
59 END_TEST
61 BEGIN_TEST(suffixcmp_zaa_ac)
62 must_be_true(git__suffixcmp("zaa", "ac") < 0);
63 END_TEST
65 BEGIN_TEST(suffixcmp_zaz_ac)
66 must_be_true(git__suffixcmp("zaz", "ac") > 0);
67 END_TEST
69 BEGIN_TEST(dirname)
70 char dir[64];
72 must_be_true(!(git__dirname(dir, sizeof(dir), NULL) < 0));
73 must_be_true(!strcmp(dir, "."));
75 must_be_true(!(git__dirname(dir, sizeof(dir), "") < 0));
76 must_be_true(!strcmp(dir, "."));
78 must_be_true(!(git__dirname(dir, sizeof(dir), "a") < 0));
79 must_be_true(!strcmp(dir, "."));
81 must_be_true(!(git__dirname(dir, sizeof(dir), "/") < 0));
82 must_be_true(!strcmp(dir, "/"));
84 must_be_true(!(git__dirname(dir, sizeof(dir), "/usr") < 0));
85 must_be_true(!strcmp(dir, "/"));
87 /* TODO: should this be "/" instead (ie strip trailing / first) */
88 must_be_true(!(git__dirname(dir, sizeof(dir), "/usr/") < 0));
89 must_be_true(!strcmp(dir, "/usr"));
91 must_be_true(!(git__dirname(dir, sizeof(dir), "/usr/lib") < 0));
92 must_be_true(!strcmp(dir, "/usr"));
94 must_be_true(!(git__dirname(dir, sizeof(dir), "usr/lib") < 0));
95 must_be_true(!strcmp(dir, "usr"));
96 END_TEST
98 BEGIN_TEST(basename)
99 char base[64];
101 must_be_true(!(git__basename(base, sizeof(base), NULL) < 0));
102 must_be_true(!strcmp(base, "."));
104 must_be_true(!(git__basename(base, sizeof(base), "") < 0));
105 must_be_true(!strcmp(base, "."));
107 must_be_true(!(git__basename(base, sizeof(base), "a") < 0));
108 must_be_true(!strcmp(base, "a"));
110 must_be_true(!(git__basename(base, sizeof(base), "/") < 0));
111 must_be_true(!strcmp(base, "/"));
113 must_be_true(!(git__basename(base, sizeof(base), "/usr") < 0));
114 must_be_true(!strcmp(base, "usr"));
116 /* TODO: should this be "usr" instead (ie strip trailing / first) */
117 must_be_true(!(git__basename(base, sizeof(base), "/usr/") < 0));
118 must_be_true(!strcmp(base, ""));
120 must_be_true(!(git__basename(base, sizeof(base), "/usr/lib") < 0));
121 must_be_true(!strcmp(base, "lib"));
123 must_be_true(!(git__basename(base, sizeof(base), "usr/lib") < 0));
124 must_be_true(!strcmp(base, "lib"));
125 END_TEST