From ff919f965d20d003e3882c70de667f41a86349ac Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Wed, 12 Sep 2012 16:04:43 +0200 Subject: string_list: add two new functions for splitting strings Add two new functions, string_list_split() and string_list_split_in_place(). These split a string into a string_list on a separator character. The first makes copies of the substrings (leaving the input string untouched) and the second splits the original string in place, overwriting the separator characters with NULs and referring to the original string's memory. These functions are similar to the strbuf_split_*() functions except that they work with the more powerful string_list interface. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0063-string-list.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 t/t0063-string-list.sh (limited to 't/t0063-string-list.sh') diff --git a/t/t0063-string-list.sh b/t/t0063-string-list.sh new file mode 100755 index 0000000000..fb85430751 --- /dev/null +++ b/t/t0063-string-list.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# +# Copyright (c) 2012 Michael Haggerty +# + +test_description='Test string list functionality' + +. ./test-lib.sh + +test_split () { + cat >expected && + test_expect_success "split $1 at $2, max $3" " + test-string-list split '$1' '$2' '$3' >actual && + test_cmp expected actual && + test-string-list split_in_place '$1' '$2' '$3' >actual && + test_cmp expected actual + " +} + +test_split "foo:bar:baz" ":" "-1" < Date: Wed, 12 Sep 2012 16:04:44 +0200 Subject: string_list: add a new function, filter_string_list() This function allows entries that don't match a specified criterion to be discarded from a string_list while preserving the order of the remaining entries. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0063-string-list.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 't/t0063-string-list.sh') diff --git a/t/t0063-string-list.sh b/t/t0063-string-list.sh index fb85430751..a5f05cd206 100755 --- a/t/t0063-string-list.sh +++ b/t/t0063-string-list.sh @@ -60,4 +60,15 @@ test_split ":" ":" "-1" < Date: Wed, 12 Sep 2012 16:04:45 +0200 Subject: string_list: add a new function, string_list_remove_duplicates() Add a function that deletes duplicate entries from a sorted string_list. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0063-string-list.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 't/t0063-string-list.sh') diff --git a/t/t0063-string-list.sh b/t/t0063-string-list.sh index a5f05cd206..dbfc05ebdc 100755 --- a/t/t0063-string-list.sh +++ b/t/t0063-string-list.sh @@ -71,4 +71,21 @@ test_expect_success "test filter_string_list" ' test "x-" = "x$(test-string-list filter x1:x2 y)" ' +test_expect_success "test remove_duplicates" ' + test "x-" = "x$(test-string-list remove_duplicates -)" && + test "x" = "x$(test-string-list remove_duplicates "")" && + test a = "$(test-string-list remove_duplicates a)" && + test a = "$(test-string-list remove_duplicates a:a)" && + test a = "$(test-string-list remove_duplicates a:a:a:a:a)" && + test a:b = "$(test-string-list remove_duplicates a:b)" && + test a:b = "$(test-string-list remove_duplicates a:a:b)" && + test a:b = "$(test-string-list remove_duplicates a:b:b)" && + test a:b:c = "$(test-string-list remove_duplicates a:b:c)" && + test a:b:c = "$(test-string-list remove_duplicates a:a:b:c)" && + test a:b:c = "$(test-string-list remove_duplicates a:b:b:c)" && + test a:b:c = "$(test-string-list remove_duplicates a:b:c:c)" && + test a:b:c = "$(test-string-list remove_duplicates a:a:b:b:c:c)" && + test a:b:c = "$(test-string-list remove_duplicates a:a:a:b:b:b:c:c:c)" +' + test_done -- cgit v1.2.1 From f103f95b11d087f07c0c48bf784cd9197e18f203 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Wed, 12 Sep 2012 16:04:46 +0200 Subject: string_list: add a function string_list_longest_prefix() Add a function that finds the longest string from a string_list that is a prefix of a given string. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0063-string-list.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 't/t0063-string-list.sh') diff --git a/t/t0063-string-list.sh b/t/t0063-string-list.sh index dbfc05ebdc..41c8826a74 100755 --- a/t/t0063-string-list.sh +++ b/t/t0063-string-list.sh @@ -17,6 +17,14 @@ test_split () { " } +test_longest_prefix () { + test "$(test-string-list longest_prefix "$1" "$2")" = "$3" +} + +test_no_longest_prefix () { + test_must_fail test-string-list longest_prefix "$1" "$2" +} + test_split "foo:bar:baz" ":" "-1" <