status: add --long output format option
[git/mjg.git] / t / t0063-string-list.sh
blob41c8826a74db9a5c34ad3365f4875f6317a5bca0
1 #!/bin/sh
3 # Copyright (c) 2012 Michael Haggerty
6 test_description='Test string list functionality'
8 . ./test-lib.sh
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
20 test_longest_prefix () {
21 test "$(test-string-list longest_prefix "$1" "$2")" = "$3"
24 test_no_longest_prefix () {
25 test_must_fail test-string-list longest_prefix "$1" "$2"
28 test_split "foo:bar:baz" ":" "-1" <<EOF
30 [0]: "foo"
31 [1]: "bar"
32 [2]: "baz"
33 EOF
35 test_split "foo:bar:baz" ":" "0" <<EOF
37 [0]: "foo:bar:baz"
38 EOF
40 test_split "foo:bar:baz" ":" "1" <<EOF
42 [0]: "foo"
43 [1]: "bar:baz"
44 EOF
46 test_split "foo:bar:baz" ":" "2" <<EOF
48 [0]: "foo"
49 [1]: "bar"
50 [2]: "baz"
51 EOF
53 test_split "foo:bar:" ":" "-1" <<EOF
55 [0]: "foo"
56 [1]: "bar"
57 [2]: ""
58 EOF
60 test_split "" ":" "-1" <<EOF
62 [0]: ""
63 EOF
65 test_split ":" ":" "-1" <<EOF
67 [0]: ""
68 [1]: ""
69 EOF
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)"
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)"
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 ""
121 test_done