]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0063-string-list.sh
Sync with 2.36.3
[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
21test_split "foo:bar:baz" ":" "-1" <<EOF
223
23[0]: "foo"
24[1]: "bar"
25[2]: "baz"
26EOF
27
28test_split "foo:bar:baz" ":" "0" <<EOF
291
30[0]: "foo:bar:baz"
31EOF
32
33test_split "foo:bar:baz" ":" "1" <<EOF
342
35[0]: "foo"
36[1]: "bar:baz"
37EOF
38
39test_split "foo:bar:baz" ":" "2" <<EOF
403
41[0]: "foo"
42[1]: "bar"
43[2]: "baz"
44EOF
45
46test_split "foo:bar:" ":" "-1" <<EOF
473
48[0]: "foo"
49[1]: "bar"
50[2]: ""
51EOF
52
53test_split "" ":" "-1" <<EOF
541
55[0]: ""
56EOF
57
58test_split ":" ":" "-1" <<EOF
592
60[0]: ""
61[1]: ""
62EOF
63
eb5f0c7a 64test_expect_success "test filter_string_list" '
c932a5ff
NTND
65 test "x-" = "x$(test-tool string-list filter - y)" &&
66 test "x-" = "x$(test-tool string-list filter no y)" &&
67 test yes = "$(test-tool string-list filter yes y)" &&
68 test yes = "$(test-tool string-list filter no:yes y)" &&
69 test yes = "$(test-tool string-list filter yes:no y)" &&
70 test y1:y2 = "$(test-tool string-list filter y1:y2 y)" &&
71 test y2:y1 = "$(test-tool string-list filter y2:y1 y)" &&
72 test "x-" = "x$(test-tool string-list filter x1:x2 y)"
eb5f0c7a
MH
73'
74
31d5451e 75test_expect_success "test remove_duplicates" '
c932a5ff
NTND
76 test "x-" = "x$(test-tool string-list remove_duplicates -)" &&
77 test "x" = "x$(test-tool string-list remove_duplicates "")" &&
78 test a = "$(test-tool string-list remove_duplicates a)" &&
79 test a = "$(test-tool string-list remove_duplicates a:a)" &&
80 test a = "$(test-tool string-list remove_duplicates a:a:a:a:a)" &&
81 test a:b = "$(test-tool string-list remove_duplicates a:b)" &&
82 test a:b = "$(test-tool string-list remove_duplicates a:a:b)" &&
83 test a:b = "$(test-tool string-list remove_duplicates a:b:b)" &&
84 test a:b:c = "$(test-tool string-list remove_duplicates a:b:c)" &&
85 test a:b:c = "$(test-tool string-list remove_duplicates a:a:b:c)" &&
86 test a:b:c = "$(test-tool string-list remove_duplicates a:b:b:c)" &&
87 test a:b:c = "$(test-tool string-list remove_duplicates a:b:c:c)" &&
88 test a:b:c = "$(test-tool string-list remove_duplicates a:a:b:b:c:c)" &&
89 test a:b:c = "$(test-tool string-list remove_duplicates a:a:a:b:b:b:c:c:c)"
31d5451e
MH
90'
91
ff919f96 92test_done