mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Add some math tests for invalid inputs
This commit is contained in:
parent
3faccc8b3e
commit
67a6f756f2
4 changed files with 17 additions and 1 deletions
|
@ -168,7 +168,7 @@ ValueOrError Parser::Min(const value_type *a_afArg, int a_iArgc) {
|
||||||
\param [in] a_iArgc The size of a_afArg
|
\param [in] a_iArgc The size of a_afArg
|
||||||
*/
|
*/
|
||||||
ValueOrError Parser::Max(const value_type *a_afArg, int a_iArgc) {
|
ValueOrError Parser::Max(const value_type *a_afArg, int a_iArgc) {
|
||||||
if (!a_iArgc) throw exception_type(_T("too few arguments for function min."));
|
if (!a_iArgc) throw exception_type(_T("too few arguments for function max."));
|
||||||
|
|
||||||
value_type fRes = a_afArg[0];
|
value_type fRes = a_afArg[0];
|
||||||
for (int i = 0; i < a_iArgc; ++i) fRes = std::max(fRes, a_afArg[i]);
|
for (int i = 0; i < a_iArgc; ++i) fRes = std::max(fRes, a_afArg[i]);
|
||||||
|
|
|
@ -4,3 +4,10 @@
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Validate how variables in an expression are handled
|
# Validate how variables in an expression are handled
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Validate math error reporting
|
||||||
|
math: Invalid expression: Too few parameters for function "min" at expression position 5
|
||||||
|
math: Invalid expression: String value used where a numerical argument is expected.
|
||||||
|
math: Invalid expression: Too few parameters for function "max" at expression position 5
|
||||||
|
math: Invalid expression: Too few parameters for function "sum" at expression position 5
|
||||||
|
|
|
@ -22,3 +22,9 @@ set x 3
|
||||||
set y 1.5
|
set y 1.5
|
||||||
math "-$x * $y"
|
math "-$x * $y"
|
||||||
math -s1 "-$x * $y"
|
math -s1 "-$x * $y"
|
||||||
|
|
||||||
|
logmsg Validate math error reporting
|
||||||
|
not math 'min()'
|
||||||
|
not math 'min("abc")'
|
||||||
|
not math 'max()'
|
||||||
|
not math 'sum()'
|
||||||
|
|
|
@ -22,3 +22,6 @@
|
||||||
2
|
2
|
||||||
-4
|
-4
|
||||||
-4.5
|
-4.5
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Validate math error reporting
|
||||||
|
|
Loading…
Reference in a new issue