1#!/bin/sh
2# Test fmt space handling
3
4# Copyright (C) 2022-2023 Free Software Foundation, Inc.
5
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ fmt printf
21
22# Before coreutils 9.1 macOS treated bytes like 0x85
23# as space characters in multi-byte locales (including UTF-8)
24
25check_non_space() {
26  char="$1"
27  test "$(env printf "=$char=" | fmt -s -w1 | wc -l)" = 1 || fail=1
28}
29
30export LC_ALL=en_US.iso8859-1  # only lowercase form works on macOS 10.15.7
31if test "$(locale charmap 2>/dev/null | sed 's/iso/ISO-/')" = ISO-8859-1; then
32  check_non_space '\xA0'
33fi
34
35export LC_ALL=en_US.UTF-8
36if test "$(locale charmap 2>/dev/null)" = UTF-8; then
37  check_non_space '\u00A0'  # No break space
38  check_non_space '\u2007'  # TODO: should probably split on figure space
39  check_non_space '\u202F'  # Narrow no break space
40  check_non_space '\u2060'  # zero-width no break space
41  check_non_space '\u0445'  # Cyrillic kha, for which macOS isspace(0x85)==true
42fi
43
44export LC_ALL=ru_RU.KOI8-R
45if test "$(locale charmap 2>/dev/null)" = KOI8-R; then
46  check_non_space '\x9A'
47fi
48
49Exit $fail
50