mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-07 01:51:14 -03:00
Port math test to littlecheck
This shows one bit where not trimming whitespace would make sense.
This commit is contained in:
128
tests/checks/math.fish
Normal file
128
tests/checks/math.fish
Normal file
@@ -0,0 +1,128 @@
|
||||
#RUN: %fish %s
|
||||
# Validate basic expressions
|
||||
math 3 / 2
|
||||
# CHECK: 1.5
|
||||
math 10/6
|
||||
# CHECK: 1.666667
|
||||
math -s0 10 / 6
|
||||
# CHECK: 1
|
||||
math 'floor(10 / 6)'
|
||||
# CHECK: 1
|
||||
math -s3 10/6
|
||||
# CHECK: 1.667
|
||||
math '10 % 6'
|
||||
# CHECK: 4
|
||||
math -s0 '10 % 6'
|
||||
# CHECK: 4
|
||||
math '23 % 7'
|
||||
# CHECK: 2
|
||||
math --scale=6 '5 / 3 * 0.3'
|
||||
# CHECK: 0.5
|
||||
math --scale=max '5 / 3'
|
||||
# CHECK: 1.666666666666667
|
||||
math "7^2"
|
||||
# CHECK: 49
|
||||
math -1 + 1
|
||||
# CHECK: 0
|
||||
math '-2 * -2'
|
||||
# CHECK: 4
|
||||
math 5 \* -2
|
||||
# CHECK: -10
|
||||
math -- -4 / 2
|
||||
# CHECK: -2
|
||||
math -- '-4 * 2'
|
||||
# CHECK: -8
|
||||
|
||||
# Validate some rounding functions
|
||||
math 'round(3/2)' ; math 'floor(3/2)' ; math 'ceil(3/2)'
|
||||
# CHECK: 2
|
||||
# CHECK: 1
|
||||
# CHECK: 2
|
||||
math 'round(-3/2)' ; math 'floor(-3/2)' ; math 'ceil(-3/2)'
|
||||
# CHECK: -2
|
||||
# CHECK: -2
|
||||
# CHECK: -1
|
||||
|
||||
# Validate some integral computations
|
||||
math 1
|
||||
math 10
|
||||
math 100
|
||||
math 1000
|
||||
# CHECK: 1
|
||||
# CHECK: 10
|
||||
# CHECK: 100
|
||||
# CHECK: 1000
|
||||
math '10^15'
|
||||
math '-10^14'
|
||||
math '-10^15'
|
||||
# CHECK: 1000000000000000
|
||||
# CHECK: 100000000000000
|
||||
# CHECK: -1000000000000000
|
||||
|
||||
math -s0 '1.0 / 2.0'
|
||||
math -s0 '3.0 / 2.0'
|
||||
math -s0 '10^15 / 2.0'
|
||||
# CHECK: 0
|
||||
# CHECK: 1
|
||||
# CHECK: 500000000000000
|
||||
|
||||
# Validate how variables in an expression are handled
|
||||
math $x + 1
|
||||
set x 1
|
||||
math $x + 1
|
||||
set x 3
|
||||
set y 1.5
|
||||
math "-$x * $y"
|
||||
math -s0 "-$x * $y"
|
||||
# CHECK: 1
|
||||
# CHECK: 2
|
||||
# CHECK: -4.5
|
||||
# CHECK: -4
|
||||
|
||||
# Validate math error reporting
|
||||
# NOTE: The leading whitespace for the carets here is ignored
|
||||
# by littlecheck.
|
||||
not math '2 - '
|
||||
# CHECKERR: math: Error: Too few arguments
|
||||
# CHECKERR: '2 - '
|
||||
# CHECKERR: ^
|
||||
not math 'ncr(1)'
|
||||
# CHECKERR: math: Error: Too few arguments
|
||||
# CHECKERR: 'ncr(1)'
|
||||
# CHECKERR: ^
|
||||
not math 'max()'
|
||||
# CHECKERR: math: Error: Expression is bogus
|
||||
# CHECKERR: 'max()'
|
||||
# CHECKERR: ^
|
||||
not math 'sin()'
|
||||
# CHECKERR: math: Error: Too few arguments
|
||||
# CHECKERR: 'sin()'
|
||||
# CHECKERR: ^
|
||||
not math '2 + 2 4'
|
||||
# CHECKERR: math: Error: Too many arguments
|
||||
# CHECKERR: '2 + 2 4'
|
||||
# CHECKERR: ^
|
||||
not math
|
||||
# CHECKERR: math: Expected at least 1 args, got only 0
|
||||
not math -s 12
|
||||
# CHECKERR: math: Expected at least 1 args, got only 0
|
||||
not math 2^999999
|
||||
# CHECKERR: math: Error: Result is infinite
|
||||
# CHECKERR: '2^999999'
|
||||
not math 1 / 0
|
||||
# CHECKERR: math: Error: Result is infinite
|
||||
# CHECKERR: '1 / 0'
|
||||
|
||||
# Validate "x" as multiplier
|
||||
math 0x2 # Hex
|
||||
math 5 x 4
|
||||
math 2x 4
|
||||
math 2 x4 # ERROR
|
||||
# CHECKERR: math: Error: Unknown variable
|
||||
# CHECKERR: '2 x4'
|
||||
# CHECKERR: ^
|
||||
math 0x 3
|
||||
# CHECK: 2
|
||||
# CHECK: 20
|
||||
# CHECK: 8
|
||||
# CHECK: 0
|
||||
@@ -1,42 +0,0 @@
|
||||
|
||||
####################
|
||||
# Validate basic expressions
|
||||
|
||||
####################
|
||||
# Validate some rounding functions
|
||||
|
||||
####################
|
||||
# Validate some integral computations
|
||||
|
||||
####################
|
||||
# Validate how variables in an expression are handled
|
||||
|
||||
####################
|
||||
# Validate math error reporting
|
||||
math: Error: Too few arguments
|
||||
'2 - '
|
||||
^
|
||||
math: Error: Too few arguments
|
||||
'ncr(1)'
|
||||
^
|
||||
math: Error: Expression is bogus
|
||||
'max()'
|
||||
^
|
||||
math: Error: Too few arguments
|
||||
'sin()'
|
||||
^
|
||||
math: Error: Too many arguments
|
||||
'2 + 2 4'
|
||||
^
|
||||
math: Expected at least 1 args, got only 0
|
||||
math: Expected at least 1 args, got only 0
|
||||
math: Error: Result is infinite
|
||||
'2^999999'
|
||||
math: Error: Result is infinite
|
||||
'1 / 0'
|
||||
|
||||
####################
|
||||
# Validate x as multiplier
|
||||
math: Error: Unknown variable
|
||||
'2 x4'
|
||||
^
|
||||
@@ -1,61 +0,0 @@
|
||||
logmsg Validate basic expressions
|
||||
math 3 / 2
|
||||
math 10/6
|
||||
math -s0 10 / 6
|
||||
math 'floor(10 / 6)'
|
||||
math -s3 10/6
|
||||
math '10 % 6'
|
||||
math -s0 '10 % 6'
|
||||
math '23 % 7'
|
||||
math --scale=6 '5 / 3 * 0.3'
|
||||
math --scale=max '5 / 3'
|
||||
math "7^2"
|
||||
math -1 + 1
|
||||
math '-2 * -2'
|
||||
math 5 \* -2
|
||||
math -- -4 / 2
|
||||
math -- '-4 * 2'
|
||||
|
||||
logmsg Validate some rounding functions
|
||||
math 'round(3/2)' ; math 'floor(3/2)' ; math 'ceil(3/2)'
|
||||
math 'round(-3/2)' ; math 'floor(-3/2)' ; math 'ceil(-3/2)'
|
||||
|
||||
logmsg Validate some integral computations
|
||||
math 1
|
||||
math 10
|
||||
math 100
|
||||
math 1000
|
||||
math '10^15'
|
||||
math '-10^14'
|
||||
math '-10^15'
|
||||
|
||||
math -s0 '1.0 / 2.0'
|
||||
math -s0 '3.0 / 2.0'
|
||||
math -s0 '10^15 / 2.0'
|
||||
|
||||
logmsg Validate how variables in an expression are handled
|
||||
math $x + 1
|
||||
set x 1
|
||||
math $x + 1
|
||||
set x 3
|
||||
set y 1.5
|
||||
math "-$x * $y"
|
||||
math -s0 "-$x * $y"
|
||||
|
||||
logmsg Validate math error reporting
|
||||
not math '2 - '
|
||||
not math 'ncr(1)'
|
||||
not math 'max()'
|
||||
not math 'sin()'
|
||||
not math '2 + 2 4'
|
||||
not math
|
||||
not math -s 12
|
||||
not math 2^999999
|
||||
not math 1 / 0
|
||||
|
||||
logmsg Validate "x" as multiplier
|
||||
math 0x2 # Hex
|
||||
math 5 x 4
|
||||
math 2x 4
|
||||
math 2 x4 # ERROR
|
||||
math 0x 3
|
||||
@@ -1,58 +0,0 @@
|
||||
|
||||
####################
|
||||
# Validate basic expressions
|
||||
1.5
|
||||
1.666667
|
||||
1
|
||||
1
|
||||
1.667
|
||||
4
|
||||
4
|
||||
2
|
||||
0.5
|
||||
1.666666666666667
|
||||
49
|
||||
0
|
||||
4
|
||||
-10
|
||||
-2
|
||||
-8
|
||||
|
||||
####################
|
||||
# Validate some rounding functions
|
||||
2
|
||||
1
|
||||
2
|
||||
-2
|
||||
-2
|
||||
-1
|
||||
|
||||
####################
|
||||
# Validate some integral computations
|
||||
1
|
||||
10
|
||||
100
|
||||
1000
|
||||
1000000000000000
|
||||
100000000000000
|
||||
-1000000000000000
|
||||
0
|
||||
1
|
||||
500000000000000
|
||||
|
||||
####################
|
||||
# Validate how variables in an expression are handled
|
||||
1
|
||||
2
|
||||
-4.5
|
||||
-4
|
||||
|
||||
####################
|
||||
# Validate math error reporting
|
||||
|
||||
####################
|
||||
# Validate x as multiplier
|
||||
2
|
||||
20
|
||||
8
|
||||
0
|
||||
Reference in New Issue
Block a user