Skip to content

Commit 6ed610b

Browse files
committed
Merge branch 'am/t0028-utf16-tests'
Test fixes. * am/t0028-utf16-tests: t0028: add more tests t0028: fix test for UTF-16-LE-BOM
2 parents 5b900fb + d928a83 commit 6ed610b

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

t/t0028-working-tree-encoding.sh

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test_expect_success 'setup test files' '
4040
printf "$text" | write_utf16 >test.utf16.raw &&
4141
printf "$text" | write_utf32 >test.utf32.raw &&
4242
printf "\377\376" >test.utf16lebom.raw &&
43-
printf "$text" | iconv -f UTF-8 -t UTF-32LE >>test.utf16lebom.raw &&
43+
printf "$text" | iconv -f UTF-8 -t UTF-16LE >>test.utf16lebom.raw &&
4444
4545
# Line ending tests
4646
printf "one\ntwo\nthree\n" >lf.utf8.raw &&
@@ -280,4 +280,43 @@ test_expect_success ICONV_SHIFT_JIS 'check roundtrip encoding' '
280280
git reset
281281
'
282282

283+
# $1: checkout encoding
284+
# $2: test string
285+
# $3: binary test string in checkout encoding
286+
test_commit_utf8_checkout_other () {
287+
encoding="$1"
288+
orig_string="$2"
289+
expect_bytes="$3"
290+
291+
test_expect_success "Commit UTF-8, checkout $encoding" '
292+
test_when_finished "git checkout HEAD -- .gitattributes" &&
293+
294+
test_ext="commit_utf8_checkout_$encoding" &&
295+
test_file="test.$test_ext" &&
296+
297+
# Commit as UTF-8
298+
echo "*.$test_ext text working-tree-encoding=UTF-8" >.gitattributes &&
299+
printf "$orig_string" >$test_file &&
300+
git add $test_file &&
301+
git commit -m "Test data" &&
302+
303+
# Checkout in tested encoding
304+
rm $test_file &&
305+
echo "*.$test_ext text working-tree-encoding=$encoding" >.gitattributes &&
306+
git checkout HEAD -- $test_file &&
307+
308+
# Test
309+
printf $expect_bytes >$test_file.raw &&
310+
test_cmp_bin $test_file.raw $test_file
311+
'
312+
}
313+
314+
test_commit_utf8_checkout_other "UTF-8" "Test Тест" "\124\145\163\164\040\320\242\320\265\321\201\321\202"
315+
test_commit_utf8_checkout_other "UTF-16LE" "Test Тест" "\124\000\145\000\163\000\164\000\040\000\042\004\065\004\101\004\102\004"
316+
test_commit_utf8_checkout_other "UTF-16BE" "Test Тест" "\000\124\000\145\000\163\000\164\000\040\004\042\004\065\004\101\004\102"
317+
test_commit_utf8_checkout_other "UTF-16LE-BOM" "Test Тест" "\377\376\124\000\145\000\163\000\164\000\040\000\042\004\065\004\101\004\102\004"
318+
test_commit_utf8_checkout_other "UTF-16BE-BOM" "Test Тест" "\376\377\000\124\000\145\000\163\000\164\000\040\004\042\004\065\004\101\004\102"
319+
test_commit_utf8_checkout_other "UTF-32LE" "Test Тест" "\124\000\000\000\145\000\000\000\163\000\000\000\164\000\000\000\040\000\000\000\042\004\000\000\065\004\000\000\101\004\000\000\102\004\000\000"
320+
test_commit_utf8_checkout_other "UTF-32BE" "Test Тест" "\000\000\000\124\000\000\000\145\000\000\000\163\000\000\000\164\000\000\000\040\000\000\004\042\000\000\004\065\000\000\004\101\000\000\004\102"
321+
283322
test_done

0 commit comments

Comments
 (0)