Add tests for variadic functions and nested calls

This commit is contained in:
Juho Eerola
2022-01-20 00:12:30 +02:00
parent a9ad49e81b
commit 66ef4d5eb5

View File

@@ -261,3 +261,32 @@ math pow 2 x cos'(-pi)', 2
math 'ncr(0/0, 1)'
# CHECKERR: math: Error: Result is infinite
# CHECKERR: 'ncr(0/0, 1)'
# Variadic functions require at least one argument
math min
# CHECKERR: math: Error: Too few arguments
# CHECKERR: 'min'
# CHECKERR: ^
math min 2
# CHECK: 2
math min 2, 3, 4, 5, -10, 1
# CHECK: -10
# Parentheses are required to disambiguate function call nested in argument list,
# except when the call is the last argument.
math 'min 5, 4, 3, ncr 2, 1, 5'
# CHECKERR: math: Error: Too many arguments
# CHECKERR: 'min 5, 4, 3, ncr 2, 1, 5'
# CHECKERR: {{^}} ^
math 'min 5, 4, 3, ncr(2, 1), 5'
# CHECK: 2
math 'min 5, 4, 3, 5, ncr 2, 1'
# CHECK: 2
# Variadic function consumes all available arguments,
# so it is always the last argument unless parenthesised.
# max(1, 2, min(3, 4, 5))
math 'max 1, 2, min 3, 4, 5'
# CHECK: 3
# max(1, 2, min(3, 4), 5)
math 'max 1, 2, min(3, 4), 5'
# CHECK: 5