t / t0063-string-list.shon commit Merge branch 'jl/interrupt-clone-remove-separate-git-dir' into maint (32e820b)
   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_longest_prefix () {
  21        test "$(test-string-list longest_prefix "$1" "$2")" = "$3"
  22}
  23
  24test_no_longest_prefix () {
  25        test_must_fail test-string-list longest_prefix "$1" "$2"
  26}
  27
  28test_split "foo:bar:baz" ":" "-1" <<EOF
  293
  30[0]: "foo"
  31[1]: "bar"
  32[2]: "baz"
  33EOF
  34
  35test_split "foo:bar:baz" ":" "0" <<EOF
  361
  37[0]: "foo:bar:baz"
  38EOF
  39
  40test_split "foo:bar:baz" ":" "1" <<EOF
  412
  42[0]: "foo"
  43[1]: "bar:baz"
  44EOF
  45
  46test_split "foo:bar:baz" ":" "2" <<EOF
  473
  48[0]: "foo"
  49[1]: "bar"
  50[2]: "baz"
  51EOF
  52
  53test_split "foo:bar:" ":" "-1" <<EOF
  543
  55[0]: "foo"
  56[1]: "bar"
  57[2]: ""
  58EOF
  59
  60test_split "" ":" "-1" <<EOF
  611
  62[0]: ""
  63EOF
  64
  65test_split ":" ":" "-1" <<EOF
  662
  67[0]: ""
  68[1]: ""
  69EOF
  70
  71test_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)"
  80'
  81
  82test_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)"
  97'
  98
  99test_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 ""
 119'
 120
 121test_done