]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0063-string-list.sh
Merge branch 'jk/complete-commit-c' into maint
[thirdparty/git.git] / t / t0063-string-list.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2012 Michael Haggerty
4 #
5
6 test_description='Test string list functionality'
7
8 . ./test-lib.sh
9
10 test_split () {
11 cat >expected &&
12 test_expect_success "split $1 at $2, max $3" "
13 test-string-list split '$1' '$2' '$3' >actual &&
14 test_cmp expected actual &&
15 test-string-list split_in_place '$1' '$2' '$3' >actual &&
16 test_cmp expected actual
17 "
18 }
19
20 test_longest_prefix () {
21 test "$(test-string-list longest_prefix "$1" "$2")" = "$3"
22 }
23
24 test_no_longest_prefix () {
25 test_must_fail test-string-list longest_prefix "$1" "$2"
26 }
27
28 test_split "foo:bar:baz" ":" "-1" <<EOF
29 3
30 [0]: "foo"
31 [1]: "bar"
32 [2]: "baz"
33 EOF
34
35 test_split "foo:bar:baz" ":" "0" <<EOF
36 1
37 [0]: "foo:bar:baz"
38 EOF
39
40 test_split "foo:bar:baz" ":" "1" <<EOF
41 2
42 [0]: "foo"
43 [1]: "bar:baz"
44 EOF
45
46 test_split "foo:bar:baz" ":" "2" <<EOF
47 3
48 [0]: "foo"
49 [1]: "bar"
50 [2]: "baz"
51 EOF
52
53 test_split "foo:bar:" ":" "-1" <<EOF
54 3
55 [0]: "foo"
56 [1]: "bar"
57 [2]: ""
58 EOF
59
60 test_split "" ":" "-1" <<EOF
61 1
62 [0]: ""
63 EOF
64
65 test_split ":" ":" "-1" <<EOF
66 2
67 [0]: ""
68 [1]: ""
69 EOF
70
71 test_expect_success "test filter_string_list" '
72 test "x-" = "x$(test-string-list filter - y)" &&
73 test "x-" = "x$(test-string-list filter no y)" &&
74 test yes = "$(test-string-list filter yes y)" &&
75 test yes = "$(test-string-list filter no:yes y)" &&
76 test yes = "$(test-string-list filter yes:no y)" &&
77 test y1:y2 = "$(test-string-list filter y1:y2 y)" &&
78 test y2:y1 = "$(test-string-list filter y2:y1 y)" &&
79 test "x-" = "x$(test-string-list filter x1:x2 y)"
80 '
81
82 test_expect_success "test remove_duplicates" '
83 test "x-" = "x$(test-string-list remove_duplicates -)" &&
84 test "x" = "x$(test-string-list remove_duplicates "")" &&
85 test a = "$(test-string-list remove_duplicates a)" &&
86 test a = "$(test-string-list remove_duplicates a:a)" &&
87 test a = "$(test-string-list remove_duplicates a:a:a:a:a)" &&
88 test a:b = "$(test-string-list remove_duplicates a:b)" &&
89 test a:b = "$(test-string-list remove_duplicates a:a:b)" &&
90 test a:b = "$(test-string-list remove_duplicates a:b:b)" &&
91 test a:b:c = "$(test-string-list remove_duplicates a:b:c)" &&
92 test a:b:c = "$(test-string-list remove_duplicates a:a:b:c)" &&
93 test a:b:c = "$(test-string-list remove_duplicates a:b:b:c)" &&
94 test a:b:c = "$(test-string-list remove_duplicates a:b:c:c)" &&
95 test a:b:c = "$(test-string-list remove_duplicates a:a:b:b:c:c)" &&
96 test a:b:c = "$(test-string-list remove_duplicates a:a:a:b:b:b:c:c:c)"
97 '
98
99 test_expect_success "test longest_prefix" '
100 test_no_longest_prefix - '' &&
101 test_no_longest_prefix - x &&
102 test_longest_prefix "" x "" &&
103 test_longest_prefix x x x &&
104 test_longest_prefix "" foo "" &&
105 test_longest_prefix : foo "" &&
106 test_longest_prefix f foo f &&
107 test_longest_prefix foo foobar foo &&
108 test_longest_prefix foo foo foo &&
109 test_no_longest_prefix bar foo &&
110 test_no_longest_prefix bar:bar foo &&
111 test_no_longest_prefix foobar foo &&
112 test_longest_prefix foo:bar foo foo &&
113 test_longest_prefix foo:bar bar bar &&
114 test_longest_prefix foo::bar foo foo &&
115 test_longest_prefix foo:foobar foo foo &&
116 test_longest_prefix foobar:foo foo foo &&
117 test_longest_prefix foo: bar "" &&
118 test_longest_prefix :foo bar ""
119 '
120
121 test_done