Git fork

t0028: extract encoding helpers to lib-encoding.sh

The following patch will add tests outside t0028 which will also need to
re-encode some strings. Extract the auxiliary encoding functions from
t0028 to a common lib file so that they can be reused.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Matheus Tavares and committed by
Junio C Hamano
2fa3cbad 6a7bc9d1

+26 -24
+25
t/lib-encoding.sh
··· 1 + # Encoding helpers 2 + 3 + test_lazy_prereq NO_UTF16_BOM ' 4 + test $(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c) = 6 5 + ' 6 + 7 + test_lazy_prereq NO_UTF32_BOM ' 8 + test $(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c) = 12 9 + ' 10 + 11 + write_utf16 () { 12 + if test_have_prereq NO_UTF16_BOM 13 + then 14 + printf '\376\377' 15 + fi && 16 + iconv -f UTF-8 -t UTF-16 17 + } 18 + 19 + write_utf32 () { 20 + if test_have_prereq NO_UTF32_BOM 21 + then 22 + printf '\0\0\376\377' 23 + fi && 24 + iconv -f UTF-8 -t UTF-32 25 + }
+1 -24
t/t0028-working-tree-encoding.sh
··· 6 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 7 8 8 . ./test-lib.sh 9 + . "$TEST_DIRECTORY/lib-encoding.sh" 9 10 10 11 GIT_TRACE_WORKING_TREE_ENCODING=1 && export GIT_TRACE_WORKING_TREE_ENCODING 11 - 12 - test_lazy_prereq NO_UTF16_BOM ' 13 - test $(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c) = 6 14 - ' 15 - 16 - test_lazy_prereq NO_UTF32_BOM ' 17 - test $(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c) = 12 18 - ' 19 - 20 - write_utf16 () { 21 - if test_have_prereq NO_UTF16_BOM 22 - then 23 - printf '\376\377' 24 - fi && 25 - iconv -f UTF-8 -t UTF-16 26 - } 27 - 28 - write_utf32 () { 29 - if test_have_prereq NO_UTF32_BOM 30 - then 31 - printf '\0\0\376\377' 32 - fi && 33 - iconv -f UTF-8 -t UTF-32 34 - } 35 12 36 13 test_expect_success 'setup test files' ' 37 14 git config core.eol lf &&