a5f05cd2060425b9c5451fe3033e354367f51b85
1#!/bin/sh
2#
3# Copyright (c) 2012 Michael Haggerty
4#
5
6test_description='Test string list functionality'
7
8. ./test-lib.sh
9
10test_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
17 "
18}
19
20test_split "foo:bar:baz" ":" "-1" <<EOF
213
22[0]: "foo"
23[1]: "bar"
24[2]: "baz"
25EOF
26
27test_split "foo:bar:baz" ":" "0" <<EOF
281
29[0]: "foo:bar:baz"
30EOF
31
32test_split "foo:bar:baz" ":" "1" <<EOF
332
34[0]: "foo"
35[1]: "bar:baz"
36EOF
37
38test_split "foo:bar:baz" ":" "2" <<EOF
393
40[0]: "foo"
41[1]: "bar"
42[2]: "baz"
43EOF
44
45test_split "foo:bar:" ":" "-1" <<EOF
463
47[0]: "foo"
48[1]: "bar"
49[2]: ""
50EOF
51
52test_split "" ":" "-1" <<EOF
531
54[0]: ""
55EOF
56
57test_split ":" ":" "-1" <<EOF
582
59[0]: ""
60[1]: ""
61EOF
62
63test_expect_success "test filter_string_list" '
64 test "x-" = "x$(test-string-list filter - y)" &&
65 test "x-" = "x$(test-string-list filter no y)" &&
66 test yes = "$(test-string-list filter yes y)" &&
67 test yes = "$(test-string-list filter no:yes y)" &&
68 test yes = "$(test-string-list filter yes:no y)" &&
69 test y1:y2 = "$(test-string-list filter y1:y2 y)" &&
70 test y2:y1 = "$(test-string-list filter y2:y1 y)" &&
71 test "x-" = "x$(test-string-list filter x1:x2 y)"
72'
73
74test_done