]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0063-string-list.sh
The third batch
[thirdparty/git.git] / t / t0063-string-list.sh
CommitLineData
ff919f96
MH
1#!/bin/sh
2#
3# Copyright (c) 2012 Michael Haggerty
4#
5
6test_description='Test string list functionality'
7
956d2e46 8TEST_PASSES_SANITIZE_LEAK=true
ff919f96
MH
9. ./test-lib.sh
10
11test_split () {
12 cat >expected &&
13 test_expect_success "split $1 at $2, max $3" "
c932a5ff 14 test-tool string-list split '$1' '$2' '$3' >actual &&
ff919f96 15 test_cmp expected actual &&
c932a5ff 16 test-tool string-list split_in_place '$1' '$2' '$3' >actual &&
ff919f96
MH
17 test_cmp expected actual
18 "
19}
20
52acddf3
TB
21test_split_in_place() {
22 cat >expected &&
23 test_expect_success "split (in place) $1 at $2, max $3" "
24 test-tool string-list split_in_place '$1' '$2' '$3' >actual &&
25 test_cmp expected actual
26 "
27}
28
ff919f96
MH
29test_split "foo:bar:baz" ":" "-1" <<EOF
303
31[0]: "foo"
32[1]: "bar"
33[2]: "baz"
34EOF
35
36test_split "foo:bar:baz" ":" "0" <<EOF
371
38[0]: "foo:bar:baz"
39EOF
40
41test_split "foo:bar:baz" ":" "1" <<EOF
422
43[0]: "foo"
44[1]: "bar:baz"
45EOF
46
47test_split "foo:bar:baz" ":" "2" <<EOF
483
49[0]: "foo"
50[1]: "bar"
51[2]: "baz"
52EOF
53
54test_split "foo:bar:" ":" "-1" <<EOF
553
56[0]: "foo"
57[1]: "bar"
58[2]: ""
59EOF
60
61test_split "" ":" "-1" <<EOF
621
63[0]: ""
64EOF
65
66test_split ":" ":" "-1" <<EOF
672
68[0]: ""
69[1]: ""
70EOF
71
52acddf3
TB
72test_split_in_place "foo:;:bar:;:baz:;:" ":;" "-1" <<EOF
7310
74[0]: "foo"
75[1]: ""
76[2]: ""
77[3]: "bar"
78[4]: ""
79[5]: ""
80[6]: "baz"
81[7]: ""
82[8]: ""
83[9]: ""
84EOF
85
86test_split_in_place "foo:;:bar:;:baz" ":;" "0" <<EOF
871
88[0]: "foo:;:bar:;:baz"
89EOF
90
91test_split_in_place "foo:;:bar:;:baz" ":;" "1" <<EOF
922
93[0]: "foo"
94[1]: ";:bar:;:baz"
95EOF
96
97test_split_in_place "foo:;:bar:;:baz" ":;" "2" <<EOF
983
99[0]: "foo"
100[1]: ""
101[2]: ":bar:;:baz"
102EOF
103
104test_split_in_place "foo:;:bar:;:" ":;" "-1" <<EOF
1057
106[0]: "foo"
107[1]: ""
108[2]: ""
109[3]: "bar"
110[4]: ""
111[5]: ""
112[6]: ""
113EOF
114
eb5f0c7a 115test_expect_success "test filter_string_list" '
c932a5ff
NTND
116 test "x-" = "x$(test-tool string-list filter - y)" &&
117 test "x-" = "x$(test-tool string-list filter no y)" &&
118 test yes = "$(test-tool string-list filter yes y)" &&
119 test yes = "$(test-tool string-list filter no:yes y)" &&
120 test yes = "$(test-tool string-list filter yes:no y)" &&
121 test y1:y2 = "$(test-tool string-list filter y1:y2 y)" &&
122 test y2:y1 = "$(test-tool string-list filter y2:y1 y)" &&
123 test "x-" = "x$(test-tool string-list filter x1:x2 y)"
eb5f0c7a
MH
124'
125
31d5451e 126test_expect_success "test remove_duplicates" '
c932a5ff
NTND
127 test "x-" = "x$(test-tool string-list remove_duplicates -)" &&
128 test "x" = "x$(test-tool string-list remove_duplicates "")" &&
129 test a = "$(test-tool string-list remove_duplicates a)" &&
130 test a = "$(test-tool string-list remove_duplicates a:a)" &&
131 test a = "$(test-tool string-list remove_duplicates a:a:a:a:a)" &&
132 test a:b = "$(test-tool string-list remove_duplicates a:b)" &&
133 test a:b = "$(test-tool string-list remove_duplicates a:a:b)" &&
134 test a:b = "$(test-tool string-list remove_duplicates a:b:b)" &&
135 test a:b:c = "$(test-tool string-list remove_duplicates a:b:c)" &&
136 test a:b:c = "$(test-tool string-list remove_duplicates a:a:b:c)" &&
137 test a:b:c = "$(test-tool string-list remove_duplicates a:b:b:c)" &&
138 test a:b:c = "$(test-tool string-list remove_duplicates a:b:c:c)" &&
139 test a:b:c = "$(test-tool string-list remove_duplicates a:a:b:b:c:c)" &&
140 test a:b:c = "$(test-tool string-list remove_duplicates a:a:a:b:b:b:c:c:c)"
31d5451e
MH
141'
142
ff919f96 143test_done