diff mbox series

test: encoding: simplify BOM addition

Message ID 20230313050459.3465060-1-felipe.contreras@gmail.com (mailing list archive)
State New, archived
Headers show
Series test: encoding: simplify BOM addition | expand

Commit Message

Felipe Contreras March 13, 2023, 5:04 a.m. UTC
In 79444c9294 (utf8: handle systems that don't write BOM for UTF-16,
2019-02-12) some prereqs were added (NO_UTF16_BOM and NO_UTF32_BOM) in
order to conditionally add BOMs for the systems that need them.

But we don't need to check that prereq every time we are going to write
some text.

Let's check the requirement only once and generate write_utf{16,32}
accordingly.

Cc: Brian M. Carlson <sandals@crustytoothpaste.net>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 t/lib-encoding.sh | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/t/lib-encoding.sh b/t/lib-encoding.sh
index 2dabc8c73e..15aea597be 100644
--- a/t/lib-encoding.sh
+++ b/t/lib-encoding.sh
@@ -1,25 +1,25 @@ 
 # Encoding helpers
 
-test_lazy_prereq NO_UTF16_BOM '
-	test $(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c) = 6
-'
+if test "$(printf abc | iconv -f UTF-8 -t UTF-16 | wc -c)" = 6
+then
+	add_utf16_bom () { printf '\376\377'; }
+else
+	add_utf16_bom () { :; }
+fi
 
-test_lazy_prereq NO_UTF32_BOM '
-	test $(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c) = 12
-'
+if test "$(printf abc | iconv -f UTF-8 -t UTF-32 | wc -c)" = 12
+then
+	add_utf32_bom () { printf '\0\0\376\377'; }
+else
+	add_utf32_bom () { :; }
+fi
 
 write_utf16 () {
-	if test_have_prereq NO_UTF16_BOM
-	then
-		printf '\376\377'
-	fi &&
+	add_utf16_bom &&
 	iconv -f UTF-8 -t UTF-16
 }
 
 write_utf32 () {
-	if test_have_prereq NO_UTF32_BOM
-	then
-		printf '\0\0\376\377'
-	fi &&
+	add_utf32_bom &&
 	iconv -f UTF-8 -t UTF-32
 }