fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
99d63c21f
master
1#RUN: %fish %s 2# OpenBSD doesn't do hex numbers in str/wcstod (like C99 requires). 3# So let's skip this. 4#REQUIRES: test "$(uname)" != OpenBSD 5# Validate basic expressions 6math 3 /2 7# CHECK: 1.5 8math 10/6 9# CHECK: 1.666667 10math -s010 /6 11# CHECK: 1 12math 'floor(10 / 6)' 13# CHECK: 1 14math -s3 10/6 15# CHECK: 1.667 16math '10 % 6' 17# CHECK: 4 18math -s0'10 % 6' 19# CHECK: 4 20math '23 % 7' 21# CHECK: 2 22math --scale=6'5 / 3 * 0.3' 23# CHECK: 0.5 24math --scale=max'5 / 3' 25# CHECK: 1.666666666666667 26math --scale=1 --base=16"2 / 3 - 1" 27# CHECKERR: math: invalid option combination, non-zero scale value only valid for base 10 28math --scale=abc'5 / 3' 29# CHECKERR: math: abc: invalid scale 30math --scale=-1'5 / 3' 31# CHECKERR: math: -1: invalid scale 32math --scale=16'5 / 3' 33# CHECKERR: math: 16: invalid scale 34math "7^2" 35# CHECK: 49 36math -1 +1 37# CHECK: 0 38math '-2 * -2' 39# CHECK: 4 40math 5 \* -2 41# CHECK: -10 42math ---4 /2 43# CHECK: -2 44math --'-4 * 2' 45# CHECK: -8 46 47# Validate max and min 48math 'max(1,2)' 49math 'min(1,2)' 50# CHECK: 2 51# CHECK: 1 52 53# Validate some rounding functions 54math 'round(3/2)' 55math 'floor(3/2)' 56math 'ceil(3/2)' 57# CHECK: 2 58# CHECK: 1 59# CHECK: 2 60math 'round(-3/2)' 61math 'floor(-3/2)' 62math 'ceil(-3/2)' 63# CHECK: -2 64# CHECK: -2 65# CHECK: -1 66 67# Validate some integral computations 68math 1 69math 10 70math 100 71math 1000 72# CHECK: 1 73# CHECK: 10 74# CHECK: 100 75# CHECK: 1000 76math '10^15' 77math '-10^14' 78math '-10^15' 79# CHECK: 1000000000000000 80# CHECK: 100000000000000 81# CHECK: -1000000000000000 82 83# Floating point operations under x86 without SSE2 have reduced accuracy! 84# This includes both i586 targets and i686 under Debian, where it's patched to remove SSE2. 85# As a result, some floating point tests use regular expressions to loosely match against 86# the shape of the expected result. 87 88# NB: The i586 case should also pass under other platforms, but not the other way around. 89math "3^0.5^2" 90# CHECK: {{1\.316074|1\.316\d+}} 91 92math -2^2 93# CHECK: 4 94 95math -s0'1.0 / 2.0' 96math -s0'3.0 / 2.0' 97math -s0'10^15 / 2.0' 98# CHECK: 0 99# CHECK: 1 100# CHECK: 500000000000000 101 102# Validate how variables in an expression are handled 103math $x +1 104set x1 105math $x +1 106set x3 107set y1.5 108math "- $x * $y " 109math -s0"- $x * $y " 110# CHECK: 1 111# CHECK: 2 112# CHECK: -4.5 113# CHECK: -4 114 115# Validate math error reporting 116# NOTE: The leading whitespace for the carets here is ignored 117# by littlecheck. 118not math '2 - ' 119# CHECKERR: math: Error: Too few arguments 120# CHECKERR: '2 - ' 121# CHECKERR: ^ 122not math 'ncr(1)' 123# CHECKERR: math: Error: Too few arguments 124# CHECKERR: 'ncr(1)' 125# CHECKERR: ^ 126 127math "min()" 128# CHECKERR: math: Error: Too few arguments 129# CHECKERR: 'min()' 130# CHECKERR: ^ 131 132# There is no "blah" function. 133not math 'blah()' 134# CHECKERR: math: Error: Unknown function 135# CHECKERR: 'blah()' 136# CHECKERR: ^~~^ 137 138# There is also no "Blah" function. 139not math 'Blah()' 140# CHECKERR: math: Error: Unknown function 141# CHECKERR: 'Blah()' 142# CHECKERR: ^~~^ 143 144math n +4 145# CHECKERR: math: Error: Unknown function 146# CHECKERR: 'n + 4' 147# CHECKERR: ^ 148 149not math 'sin()' 150# CHECKERR: math: Error: Too few arguments 151# CHECKERR: 'sin()' 152# CHECKERR: ^ 153not math '2 + 2 4' 154# CHECKERR: math: Error: Missing operator 155# CHECKERR: '2 + 2 4' 156# This regex to check whitespace - the error appears between the second 2 and the 4! 157# (right after the 2) 158# CHECKERR: {{^}} ^ 159printf '<%s>\n' ( math '2 + 2 4' 2>&1 ) 160# CHECK: <math: Error: Missing operator> 161# CHECK: <'2 + 2 4'> 162# CHECK: < ^~~~~^> 163 164not math '(1 2)' 165# CHECKERR: math: Error: Missing operator 166# CHECKERR: '(1 2)' 167# CHECKERR: ^ 168not math '(1 pi)' 169# CHECKERR: math: Error: Missing operator 170# CHECKERR: '(1 pi)' 171# CHECKERR: ^ 172not math '(1 pow 1,2)' 173# CHECKERR: math: Error: Missing operator 174# CHECKERR: '(1 pow 1,2)' 175# CHECKERR: ^ 176not math 177# CHECKERR: math: expected >= 1 arguments; got 0 178not math -s12 179# CHECKERR: math: expected >= 1 arguments; got 0 180# XXX FIXME these two should be just "missing argument" errors, the count is not helpful 181not math 2^999999 182# CHECKERR: math: Error: Result is infinite 183# CHECKERR: '2^999999' 184not math 'sqrt(-1)' 185# CHECKERR: math: Error: Result is not a number 186# CHECKERR: 'sqrt(-1)' 187math 'sqrt(-0)' 188# CHECK: -0 189not math 2^53 +1 190# CHECKERR: math: Error: Result magnitude is too large 191# CHECKERR: '2^53 + 1' 192not math -2^53 -1 193# CHECKERR: math: Error: Result magnitude is too large 194# CHECKERR: '-2^53 - 1' 195printf '<%s>\n' ( not math 1 /0 2>&1 ) 196# CHECK: <math: Error: Division by zero> 197# CHECK: <'1 / 0'> 198# CHECK: < ^> 199printf '<%s>\n' ( math 1 %0 -5 2>&1 ) 200# CHECK: <math: Error: Division by zero> 201# CHECK: <'1 % 0 - 5'> 202# CHECK: < ^> 203printf '<%s>\n' ( math min1 / 0,5 2>&1 ) 204# CHECK: <math: Error: Division by zero> 205# CHECK: <'min 1 / 0, 5'> 206# CHECK: < ^> 207 208# Validate "x" as multiplier 209math 0x2# Hex 210math 5 x4 211math 2x4 212math 2 x4# ERROR 213# CHECKERR: math: Error: Unknown function 214# CHECKERR: '2 x4' 215# CHECKERR: ^^ 216math 0x3 217# CHECK: 2 218# CHECK: 20 219# CHECK: 8 220# CHECK: 0 221 222math "42 >= 1337" 223# CHECKERR: math: Error: Logical operations are not supported, use `test` instead 224# CHECKERR: '42 >= 1337' 225# CHECKERR: ^ 226 227math "bitand(0xFE, 1)" 228# CHECK: 0 229math "bitor(0xFE, 1)" 230# CHECK: 255 231math "bitxor(5, 1)" 232# CHECK: 4 233math "bitand(5.5, 2)" 234# CHECK: 0 235math "bitand(5.5, 1)" 236# CHECK: 1 237 238math "bitor(37 ^ 5, 255)" 239# CHECK: 69343999 240 241math 'log 16' 242# CHECK: 1.20412 243 244math 'log(16' 245# CHECKERR: math: Error: Missing closing parenthesis 246# CHECKERR: 'log(16' 247# CHECKERR: ^ 248 249math '(2' 250# CHECKERR: math: Error: Missing closing parenthesis 251# CHECKERR: '(2' 252# CHECKERR: ^ 253 254math --base=16255 /15 255# CHECK: 0x11 256math -bhex16 x2 257# CHECK: 0x20 258math --base hex12 + 0x50 259# CHECK: 0x5c 260math --base hex0 261# CHECK: 0x0 262math --base hex-1 263# CHECK: -0x1 264math --base hex-15 265# CHECK: -0xf 266math --base hex'pow(2,40)' 267# CHECK: 0x10000000000 268math --base octal0 269# CHECK: 0 270math --base octal-1 271# CHECK: -01 272math --base octal-15 273# CHECK: -017 274math --base octal'pow(2,40)' 275# CHECK: 020000000000000 276math --base octal --scale=055 277# CHECK: 067 278math --base notabase 279# CHECKERR: math: notabase: invalid base value 280echo $status 281# CHECK: 2 282 283math 'log2(8)' 284# CHECK: 3 285 286math 'log(8) / log(2)' 287# CHECK: 3 288math 'log(625) / log(5)' 289# CHECK: 4 290 291# same as sin(cos(2 x pi)) 292math sin cos2 x pi 293# CHECK: 0.841471 294# Inner function binds stronger, so this is interpreted as 295# pow(sin(3,5)) 296 297math pow sin 3,5 298# CHECKERR: math: Error: Too many arguments 299# CHECKERR: 'pow sin 3, 5' 300# CHECKERR: ^ 301 302math pow sin 3,5 +2 303# CHECKERR: math: Error: Too many arguments 304# CHECKERR: 'pow sin 3, 5 + 2' 305# CHECKERR: ^~~~^ 306 307math sin pow 3,5 308# CHECK: {{-0\.890009|-0.890\d*}} 309 310math pow 2, cos -pi 311# CHECK: 0.5 312 313# pow(2*cos(-pi), 2) 314# i.e. 2^2 315# i.e. 4 316math pow2 x cos'(-pi)' ,2 317# CHECK: 4 318 319# This used to take ages, see #8170. 320# If this test hangs, that's reintroduced! 321math 'ncr(0/0, 1)' 322# CHECKERR: math: Error: Division by zero 323# CHECKERR: 'ncr(0/0, 1)' 324# CHECKERR: ^ 325 326# Variadic functions require at least one argument 327math min 328# CHECKERR: math: Error: Too few arguments 329# CHECKERR: 'min' 330# CHECKERR: ^ 331math min2 332# CHECK: 2 333math min 2, 3, 4, 5, -10,1 334# CHECK: -10 335 336# Parentheses are required to disambiguate function call nested in argument list, 337# except when the call is the last argument. 338math 'min 5, 4, 3, ncr 2, 1, 5' 339# CHECKERR: math: Error: Too many arguments 340# CHECKERR: 'min 5, 4, 3, ncr 2, 1, 5' 341# CHECKERR: {{^}} ^ 342math 'min 5, 4, 3, ncr(2, 1), 5' 343# CHECK: 2 344math 'min 5, 4, 3, 5, ncr 2, 1' 345# CHECK: 2 346# Variadic function consumes all available arguments, 347# so it is always the last argument unless parenthesised. 348# max(1, 2, min(3, 4, 5)) 349math 'max 1, 2, min 3, 4, 5' 350# CHECK: 3 351# max(1, 2, min(3, 4), 5) 352math 'max 1, 2, min(3, 4), 5' 353# CHECK: 5 354math 0_1 355# CHECK: 1 356math 0x0_A 357# CHECK: 10 358math 1_000 + 2_000 359# CHECK: 3000 360math 1_0_0_0 361# CHECK: 1000 362math 0_0.5_0 + 0_1.0_0 363# CHECK: 1.5 364math 2e0_0_2 365# CHECK: 200 366math -0_0.5_0_0E0_0_3 367# CHECK: -500 368math 20e-0_1 369# CHECK: 2 370math 0x0_2.0_0_0P0_2 371# CHECK: 8 372math -0x8p-0_3 373# CHECK: -1 374 375echo 5 +6 | math 376# CHECK: 11 377 378# Historical: If we have arguments on stdin and argv, 379# the former takes precedence and the latter is ignored entirely. 380echo 7 +6 | math 2 +2 381# CHECK: 13 382 383# It isn't checked at all. 384echo 7 +8 | math not an expression 385# CHECK: 15 386 387math ( string repeat -n1000 1 ) 2>| string shorten -m50 --char="" 388# CHECK: math: Error: Number is too large 389# CHECK: '1111111111111111111111111111111111111111111111111 390# CHECK: ^ 391 392math 0x0_2.0P-0x3 393# CHECKERR: math: Error: Unknown function 394# CHECKERR: '0x0_2.0P-0x3' 395# CHECKERR: ^^ 396math 0x0_2.0P-f 397# CHECKERR: math: Error: Unexpected token 398# CHECKERR: '0x0_2.0P-f' 399# CHECKERR: ^ 400math "22 / 5 - 5" 401# CHECK: -0.6 402math -s0 --scale-mode=truncate"22 / 5 - 5" 403# CHECK: -0 404math --scale=0 -m truncate"22 / 5 - 5" 405# CHECK: -0 406math -s0 --scale-mode=floor"22 / 5 - 5" 407# CHECK: -1 408math -s0 --scale-mode=round"22 / 5 - 5" 409# CHECK: -1 410math -s0 --scale-mode=ceiling"22 / 5 - 5" 411# CHECK: -0 412math "1 / 3 - 1" 413# CHECK: -0.666667 414math --scale-mode=truncate"1 / 3 - 1" 415# CHECK: -0.666666 416math --scale-mode=floor"1 / 3 - 1" 417# CHECK: {{-0.666667|-0.666668}} 418math --scale-mode=floor"2 / 3 - 1" 419# CHECK: {{-0.333334|-0.333335}} 420math --scale-mode=round"1 / 3 - 1" 421# CHECK: {{-0.666667|-0.666668}} 422math --scale-mode=ceiling"1 / 3 - 1" 423# CHECK: -0.666666 424math --scale-mode=ceiling"2 / 3 - 1" 425# CHECK: -0.333333 426math -s6 --scale-mode=truncate"1 / 3 - 1" 427# CHECK: -0.666666 428math -s6 --scale-mode=floor"1 / 3 - 1" 429# CHECK: {{-0.666667|-0.666668}} 430math -s6 --scale-mode=floor"2 / 3 - 1" 431# CHECK: {{-0.333334|-0.333335}} 432math -s6 --scale-mode=round"1 / 3 - 1" 433# CHECK: {{-0.666667|-0.666668}} 434math -s6 --scale-mode=ceiling"1 / 3 - 1" 435# CHECK: -0.666666 436math -s6 --scale-mode=ceiling"2 / 3 - 1" 437# CHECK: -0.333333 438 439math -s6 --scale-mode=random"2 / 3 - 1" 440# CHECKERR: math: random: invalid mode