mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-03 06:41:14 -03:00
Move the numeric locale tests to a different file
This lets us check for locales once, and to have littlecheck mark the test as skipped.
This commit is contained in:
37
tests/checks/locale-numeric.fish
Normal file
37
tests/checks/locale-numeric.fish
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# RUN: %fish %s
|
||||||
|
# musl currently does not have a `locale` command, so we skip this test there.
|
||||||
|
# REQUIRES: command -v locale
|
||||||
|
# We need a comma-using locale we know.
|
||||||
|
# REQUIRES: locale -a | grep -i '(bg_BG\|de_DE\|es_ES\|fr_FR\|ru_RU).(UTF-8|utf8)'
|
||||||
|
# OpenBSD does not use LC_NUMERIC, this test is pointless there.
|
||||||
|
# REQUIRES: test "$(uname)" != OpenBSD
|
||||||
|
|
||||||
|
set -l locales (locale -a)
|
||||||
|
set -l acceptable_locales bg_BG de_DE es_ES fr_FR ru_RU
|
||||||
|
set -l numeric_locale
|
||||||
|
for locale in {$acceptable_locales}.{UTF-8,UTF8}
|
||||||
|
if string match -i -q $locale $locales
|
||||||
|
set numeric_locale $locale
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not set -q numeric_locale[1]
|
||||||
|
# Note we tried to check for a locale above,
|
||||||
|
# but in case this fails because of e.g. case issues,
|
||||||
|
# let's error again.
|
||||||
|
echo Please install one of the following locales: >&2
|
||||||
|
printf '%s\n' $acceptable_locales".utf-8" >&2
|
||||||
|
exit 127
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
set -x LC_NUMERIC $numeric_locale
|
||||||
|
printf '%e\n' "3,45" # should succeed, output should be 3,450000e+00
|
||||||
|
# CHECK: 3,450000e+00
|
||||||
|
printf '%e\n' "4.56" # should succeed, output should be 4,560000e+00
|
||||||
|
# CHECK: 4,560000e+00
|
||||||
|
|
||||||
|
# This should succeed without output
|
||||||
|
test 42.5 -gt 37.2
|
||||||
|
end
|
||||||
@@ -68,33 +68,6 @@ printf '%e\n' "2,34" # should fail
|
|||||||
# CHECK: 2.000000e+00
|
# CHECK: 2.000000e+00
|
||||||
# CHECKERR: 2,34: value not completely converted
|
# CHECKERR: 2,34: value not completely converted
|
||||||
|
|
||||||
# Try to use one of several locales that use a comma as the decimal mark
|
|
||||||
# rather than the period used in english speaking locales. If we don't find
|
|
||||||
# one installed we simply don't run this test.
|
|
||||||
#
|
|
||||||
# musl currently does not have a `locale` command, so we also skip it then.
|
|
||||||
set -l locales (command -sq locale; and locale -a)
|
|
||||||
set -l acceptable_locales bg_BG de_DE es_ES fr_FR ru_RU
|
|
||||||
set -l numeric_locale
|
|
||||||
for locale in {$acceptable_locales}.{UTF-8,UTF8}
|
|
||||||
if string match -i -q $locale $locales
|
|
||||||
set numeric_locale $locale
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# OpenBSD's wcstod does not honor LC_NUMERIC, meaning this feature is broken there.
|
|
||||||
if set -q numeric_locale[1]; and test (uname) != OpenBSD
|
|
||||||
set -x LC_NUMERIC $numeric_locale
|
|
||||||
printf '%e\n' "3,45" # should succeed, output should be 3,450000e+00
|
|
||||||
printf '%e\n' "4.56" # should succeed, output should be 4,560000e+00
|
|
||||||
else
|
|
||||||
echo '3,450000e+00'
|
|
||||||
echo '4,560000e+00'
|
|
||||||
end
|
|
||||||
# CHECK: 3,450000e+00
|
|
||||||
# CHECK: 4,560000e+00
|
|
||||||
|
|
||||||
# Verify long long ints are handled correctly. See issue #3352.
|
# Verify long long ints are handled correctly. See issue #3352.
|
||||||
printf 'long hex1 %x\n' 498216206234
|
printf 'long hex1 %x\n' 498216206234
|
||||||
# CHECK: long hex1 73ffffff9a
|
# CHECK: long hex1 73ffffff9a
|
||||||
|
|||||||
@@ -51,20 +51,3 @@ t 5,2
|
|||||||
# CHECKERR: ^
|
# CHECKERR: ^
|
||||||
# CHECKERR: in function 't' with arguments '5,2'
|
# CHECKERR: in function 't' with arguments '5,2'
|
||||||
# CHECKERR: called on line {{\d+}} of file {{.*}}test.fish
|
# CHECKERR: called on line {{\d+}} of file {{.*}}test.fish
|
||||||
|
|
||||||
if command -q locale
|
|
||||||
# Try to get a comma-using locale.
|
|
||||||
# We have a cheesy list hardcoded, and try to get it in the spelling
|
|
||||||
# that "locale" uses.
|
|
||||||
set -l locales (locale -a)
|
|
||||||
set -l use
|
|
||||||
for locale in de_de fr_fr nl_NL pt_BR
|
|
||||||
set use (string match -ri "$locale.utf.?8" -- $locales)
|
|
||||||
and break
|
|
||||||
end
|
|
||||||
if set -q use[1]
|
|
||||||
set -gx LC_ALL $use
|
|
||||||
# This should succeed without output
|
|
||||||
test 42.5 -gt 37.2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
Reference in New Issue
Block a user