3 # Copyright (c) 2012 Michael Haggerty
6 test_description
='Test string list functionality'
8 TEST_PASSES_SANITIZE_LEAK
=true
13 test_expect_success
"split $1 at $2, max $3" "
14 test-tool string-list split '$1' '$2' '$3' >actual &&
15 test_cmp expected actual &&
16 test-tool string-list split_in_place '$1' '$2' '$3' >actual &&
17 test_cmp expected actual
21 test_split_in_place
() {
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
29 test_split
"foo:bar:baz" ":" "-1" <<EOF
36 test_split
"foo:bar:baz" ":" "0" <<EOF
41 test_split
"foo:bar:baz" ":" "1" <<EOF
47 test_split
"foo:bar:baz" ":" "2" <<EOF
54 test_split
"foo:bar:" ":" "-1" <<EOF
61 test_split
"" ":" "-1" <<EOF
66 test_split
":" ":" "-1" <<EOF
72 test_split_in_place
"foo:;:bar:;:baz:;:" ":;" "-1" <<EOF
86 test_split_in_place
"foo:;:bar:;:baz" ":;" "0" <<EOF
88 [0]: "foo:;:bar:;:baz"
91 test_split_in_place
"foo:;:bar:;:baz" ":;" "1" <<EOF
97 test_split_in_place
"foo:;:bar:;:baz" ":;" "2" <<EOF
104 test_split_in_place
"foo:;:bar:;:" ":;" "-1" <<EOF
115 test_expect_success
"test filter_string_list" '
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)"
126 test_expect_success
"test remove_duplicates" '
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)"