1# RUN: %fish %s 2 3printf "Hello %d %i %f %F %g %G\n" 1 2 3 4 5 6 4# CHECK: Hello 1 2 3.000000 4.000000 5 6 5 6printf "%x %X %o %llu\n" 10 11 8 -1 7# CHECK: a B 10 18446744073709551615 8 9# %a has OS-dependent output - see #1139 10#printf "%a %A\n" 14 15 11 12printf "%c %s\n" a hello 13# CHECK: a hello 14 15printf "%c%c%c\n" hello … o 16# CHECK: h…o 17 18printf "%e %E\n" 5 6 19# CHECK: 5.000000e+00 6.000000E+00 20 21printf "%20d\n" 50 22# CHECK: 50 23 24printf "%-20d%d\n" 5 10 25# CHECK: 5 10 26 27printf "%*d\n" 10 100 28# CHECK: 100 29 30printf "%%\"\\\n" 31printf "%s\b%s\n" x y 32# CHECK: %"\nxy 33 34printf "abc\rdef\n" 35# CHECK: abc{{\r}}def 36 37printf "Msg1\fMsg2\n" 38# CHECK: Msg1{{\f}}Msg2 39 40printf "foo\vbar\vbaz\n" 41# CHECK: foobarbaz 42 43printf "\111 \x50 \u0051 \U00000052" 44echo 45# CHECK: I P Q R 46 47# \c escape means "stop printing" 48printf 'a\cb' 49echo 50# CHECK: a 51 52# Bogus printf specifier, should produce no stdout 53printf "%5" 10 2>/dev/null 54 55# Octal escapes produce literal bytes, not characters 56# \376 is 0xFE 57printf '\376' | display_bytes 58# CHECK: 0000000 376 59# CHECK: 0000001 60 61# Verify that floating point conversions and output work correctly with 62# different combinations of locales and floating point strings. See issue 63# #3334. This starts by assuming an locale using english conventions. 64printf '%e\n' "1.23" # should succeed, output should be 1.230000e+00 65# CHECK: 1.230000e+00 66 67printf '%e\n' "2,34" # should fail 68# CHECK: 2.000000e+00 69# CHECKERR: 2,34: value not completely converted 70 71# Try to use one of several locales that use a comma as the decimal mark 72# rather than the period used in english speaking locales. If we don't find 73# one installed we simply don't run this test. 74# 75# musl currently does not have a `locale` command, so we also skip it then. 76set -l locales (command -sq locale; and locale -a) 77set -l acceptable_locales bg_BG de_DE es_ES fr_FR ru_RU 78set -l numeric_locale 79for locale in {$acceptable_locales}.{UTF-8,UTF8} 80 if string match -i -q $locale $locales 81 set numeric_locale $locale 82 break 83 end 84end 85 86# OpenBSD's wcstod does not honor LC_NUMERIC, meaning this feature is broken there. 87if set -q numeric_locale[1]; and test (uname) != OpenBSD 88 set -x LC_NUMERIC $numeric_locale 89 printf '%e\n' "3,45" # should succeed, output should be 3,450000e+00 90 printf '%e\n' "4.56" # should succeed, output should be 4,560000e+00 91else 92 echo '3,450000e+00' 93 echo '4,560000e+00' 94end 95# CHECK: 3,450000e+00 96# CHECK: 4,560000e+00 97 98# Verify long long ints are handled correctly. See issue #3352. 99printf 'long hex1 %x\n' 498216206234 100# CHECK: long hex1 73ffffff9a 101printf 'long hex2 %X\n' 498216206234 102# CHECK: long hex2 73FFFFFF9A 103printf 'long hex3 %X\n' 0xABCDEF1234567890 104# CHECK: long hex3 ABCDEF1234567890 105printf 'long hex4 %X\n' 0xABCDEF12345678901 106# CHECKERR: 0xABCDEF12345678901: Number out of range 107printf 'long decimal %d\n' 498216206594 108# CHECK: long hex4 long decimal 498216206594 109printf 'long signed %d\n' -498216206595 110# CHECK: long signed -498216206595 111printf 'long signed to unsigned %u\n' -498216206596 112# CHECK: long signed to unsigned 18446743575493345020 113 114# Just check that we print no error for no arguments 115printf 116echo $status 117# CHECK: 2 118 119# Verify numeric conversion still happens even if it couldn't be fully converted 120printf '%d\n' 15.1 121# CHECK: 15 122# CHECKERR: 15.1: value not completely converted 123echo $status 124# CHECK: 1 125