Skip to content

Commit 2fa3cba

Browse files
matheustavaresgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a7bc9d commit 2fa3cba

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

t/lib-encoding.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

t/t0028-working-tree-encoding.sh

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,10 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

88
. ./test-lib.sh
9+
. "$TEST_DIRECTORY/lib-encoding.sh"
910

1011
GIT_TRACE_WORKING_TREE_ENCODING=1 && export GIT_TRACE_WORKING_TREE_ENCODING
1112

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-
3613
test_expect_success 'setup test files' '
3714
git config core.eol lf &&
3815

0 commit comments

Comments
 (0)