]>
Commit | Line | Data |
---|---|---|
ff919f96 MH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2012 Michael Haggerty | |
4 | # | |
5 | ||
6 | test_description='Test string list functionality' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
10 | test_split () { | |
11 | cat >expected && | |
12 | test_expect_success "split $1 at $2, max $3" " | |
c932a5ff | 13 | test-tool string-list split '$1' '$2' '$3' >actual && |
ff919f96 | 14 | test_cmp expected actual && |
c932a5ff | 15 | test-tool string-list split_in_place '$1' '$2' '$3' >actual && |
ff919f96 MH |
16 | test_cmp expected actual |
17 | " | |
18 | } | |
19 | ||
20 | test_split "foo:bar:baz" ":" "-1" <<EOF | |
21 | 3 | |
22 | [0]: "foo" | |
23 | [1]: "bar" | |
24 | [2]: "baz" | |
25 | EOF | |
26 | ||
27 | test_split "foo:bar:baz" ":" "0" <<EOF | |
28 | 1 | |
29 | [0]: "foo:bar:baz" | |
30 | EOF | |
31 | ||
32 | test_split "foo:bar:baz" ":" "1" <<EOF | |
33 | 2 | |
34 | [0]: "foo" | |
35 | [1]: "bar:baz" | |
36 | EOF | |
37 | ||
38 | test_split "foo:bar:baz" ":" "2" <<EOF | |
39 | 3 | |
40 | [0]: "foo" | |
41 | [1]: "bar" | |
42 | [2]: "baz" | |
43 | EOF | |
44 | ||
45 | test_split "foo:bar:" ":" "-1" <<EOF | |
46 | 3 | |
47 | [0]: "foo" | |
48 | [1]: "bar" | |
49 | [2]: "" | |
50 | EOF | |
51 | ||
52 | test_split "" ":" "-1" <<EOF | |
53 | 1 | |
54 | [0]: "" | |
55 | EOF | |
56 | ||
57 | test_split ":" ":" "-1" <<EOF | |
58 | 2 | |
59 | [0]: "" | |
60 | [1]: "" | |
61 | EOF | |
62 | ||
eb5f0c7a | 63 | test_expect_success "test filter_string_list" ' |
c932a5ff NTND |
64 | test "x-" = "x$(test-tool string-list filter - y)" && |
65 | test "x-" = "x$(test-tool string-list filter no y)" && | |
66 | test yes = "$(test-tool string-list filter yes y)" && | |
67 | test yes = "$(test-tool string-list filter no:yes y)" && | |
68 | test yes = "$(test-tool string-list filter yes:no y)" && | |
69 | test y1:y2 = "$(test-tool string-list filter y1:y2 y)" && | |
70 | test y2:y1 = "$(test-tool string-list filter y2:y1 y)" && | |
71 | test "x-" = "x$(test-tool string-list filter x1:x2 y)" | |
eb5f0c7a MH |
72 | ' |
73 | ||
31d5451e | 74 | test_expect_success "test remove_duplicates" ' |
c932a5ff NTND |
75 | test "x-" = "x$(test-tool string-list remove_duplicates -)" && |
76 | test "x" = "x$(test-tool string-list remove_duplicates "")" && | |
77 | test a = "$(test-tool string-list remove_duplicates a)" && | |
78 | test a = "$(test-tool string-list remove_duplicates a:a)" && | |
79 | test a = "$(test-tool string-list remove_duplicates a:a:a:a:a)" && | |
80 | test a:b = "$(test-tool string-list remove_duplicates a:b)" && | |
81 | test a:b = "$(test-tool string-list remove_duplicates a:a:b)" && | |
82 | test a:b = "$(test-tool string-list remove_duplicates a:b:b)" && | |
83 | test a:b:c = "$(test-tool string-list remove_duplicates a:b:c)" && | |
84 | test a:b:c = "$(test-tool string-list remove_duplicates a:a:b:c)" && | |
85 | test a:b:c = "$(test-tool string-list remove_duplicates a:b:b:c)" && | |
86 | test a:b:c = "$(test-tool string-list remove_duplicates a:b:c:c)" && | |
87 | test a:b:c = "$(test-tool string-list remove_duplicates a:a:b:b:c:c)" && | |
88 | test a:b:c = "$(test-tool string-list remove_duplicates a:a:a:b:b:b:c:c:c)" | |
31d5451e MH |
89 | ' |
90 | ||
ff919f96 | 91 | test_done |