string_list: add two new functions for splitting strings
[git.git] / t / t0063-string-list.sh
blobfb85430751ae2e1a1296daae8a1873d521d18b0a
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_split "foo:bar:baz" ":" "-1" <<EOF
22 [0]: "foo"
23 [1]: "bar"
24 [2]: "baz"
25 EOF
27 test_split "foo:bar:baz" ":" "0" <<EOF
29 [0]: "foo:bar:baz"
30 EOF
32 test_split "foo:bar:baz" ":" "1" <<EOF
34 [0]: "foo"
35 [1]: "bar:baz"
36 EOF
38 test_split "foo:bar:baz" ":" "2" <<EOF
40 [0]: "foo"
41 [1]: "bar"
42 [2]: "baz"
43 EOF
45 test_split "foo:bar:" ":" "-1" <<EOF
47 [0]: "foo"
48 [1]: "bar"
49 [2]: ""
50 EOF
52 test_split "" ":" "-1" <<EOF
54 [0]: ""
55 EOF
57 test_split ":" ":" "-1" <<EOF
59 [0]: ""
60 [1]: ""
61 EOF
63 test_done