summaryrefslogtreecommitdiff
path: root/Test
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-04-19 16:09:06 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-04-19 16:09:06 +0000
commitb7474e065b82d930f8da472440282ea7654d491d (patch)
tree07ae2866628b6fd4f180824d566de06be94796ed /Test
parent5c2d5b013e1d8cab43ca19507bf669693c95cd95 (diff)
downloadzsh-b7474e065b82d930f8da472440282ea7654d491d.tar.gz
zsh-b7474e065b82d930f8da472440282ea7654d491d.zip
22416, tweaked: math functions via shell functions
unposted: add styles to pick-web-browser
Diffstat (limited to 'Test')
-rw-r--r--Test/C04funcdef.ztst59
1 files changed, 59 insertions, 0 deletions
diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst
index 07a20349d..04098d2ce 100644
--- a/Test/C04funcdef.ztst
+++ b/Test/C04funcdef.ztst
@@ -11,3 +11,62 @@
foo
0:Function definition without braces
>bar
+
+ functions -M m1
+ m1() { (( $# )) }
+ print $(( m1() ))
+ print $(( m1(1) ))
+ print $(( m1(1,2) ))
+0:User-defined math functions, argument handling
+>0
+>1
+>2
+
+ functions -M m2
+ m2() {
+ integer sum
+ local val
+ for val in $*; do
+ (( sum += $val ))
+ done
+ }
+ print $(( m2(1) ))
+ print $(( m2(1,3+3,4**2) ))
+0:User-defined math functions, complex argument handling
+>1
+>23
+
+ functions -M m3 1 2
+ m3() { (( 1 )) }
+ print zero
+ (print $(( m3() )))
+ print one
+ print $(( m3(1) ))
+ print two
+ print $(( m3(1,2) ))
+ print three
+ (print $(( m3(1,2,3) )))
+1:User-defined math functions, argument checking
+>zero
+>one
+>1
+>two
+>1
+>three
+?(eval):4: wrong number of arguments: m3()
+?(eval):10: wrong number of arguments: m3(1,2,3)
+
+ functions -M m4 0 0 testmathfunc
+ functions -M m5 0 0 testmathfunc
+ testmathfunc() {
+ if [[ $0 = m4 ]]; then
+ (( 4 ))
+ else
+ (( 5 ))
+ fi
+ }
+ print $(( m4() ))
+ print $(( m5() ))
+0:User-defined math functions, multiple interfaces
+>4
+>5