summaryrefslogtreecommitdiffstats
path: root/Test
diff options
context:
space:
mode:
authordana <dana@dana.is>2026-05-18 04:06:17 -0500
committerdana <dana@dana.is>2026-05-21 14:25:56 -0500
commita04c944804642aa083d46ce5dae2356d3c8fcc0c (patch)
tree9db2bfc6603b6d02d22738c29f46a35b7d427f56 /Test
parent54579: docs: clarify zformat -F ternary behaviour (diff)
downloadzsh-a04c944804642aa083d46ce5dae2356d3c8fcc0c.tar
zsh-a04c944804642aa083d46ce5dae2356d3c8fcc0c.tar.gz
zsh-a04c944804642aa083d46ce5dae2356d3c8fcc0c.tar.bz2
zsh-a04c944804642aa083d46ce5dae2356d3c8fcc0c.tar.lz
zsh-a04c944804642aa083d46ce5dae2356d3c8fcc0c.tar.xz
zsh-a04c944804642aa083d46ce5dae2356d3c8fcc0c.tar.zst
zsh-a04c944804642aa083d46ce5dae2356d3c8fcc0c.zip
54580: zformat: better handle literal % in format string
Diffstat (limited to 'Test')
-rw-r--r--Test/V13zformat.ztst138
1 files changed, 138 insertions, 0 deletions
diff --git a/Test/V13zformat.ztst b/Test/V13zformat.ztst
index 035a0a495..545d5e615 100644
--- a/Test/V13zformat.ztst
+++ b/Test/V13zformat.ztst
@@ -89,3 +89,141 @@
>ipsum.bar
>bazbaz
>\esc:ape
+
+ zformat REPLY ''
+ zformat REPLY '' x:
+1:one of -f -F -a required
+?(eval):zformat:1: not enough arguments
+?(eval):zformat:2: invalid argument: REPLY
+
+ zformat -F REPLY %B && print -r - $REPLY
+ zformat -F REPLY %3B && print -r - $REPLY
+0:sequence with no matching spec falls through
+>%B
+>%3B
+
+ for 1 in - . 0 9; do
+ REPLY1= REPLY2=
+ zformat -F REPLY1 %$1
+ zformat -F REPLY2 %1$1
+ zformat -F REPLY3 %1%$1
+ print -r - $REPLY1 $REPLY2 $REPLY3
+ done
+0:impossible spec in format string
+>%- %1- %1%-
+>%. %1. %1%.
+>%0 %10 %1%0
+>%9 %19 %1%9
+
+ # extra char at end to avoid triggering premature eos condition
+ zformat -F REPLY '%% %3% %) %3) x'
+ print -r - $REPLY
+0:%% and %) in format string
+>% %3% ) %3) x
+
+ for 1 in % %% %%% %%%% %%%%% %%%%%%; do
+ zformat -F REPLY $1 &&
+ print -r - $REPLY
+ done
+0:more literal % in format string
+>%
+>%
+>%%
+>%%
+>%%%
+>%%%
+
+ for 1 in % \) - . 0 9 ''; do
+ zformat -F REPLY '' $1:
+ done
+1:spec with illegal char
+?(eval):zformat:2: invalid spec: %:
+?(eval):zformat:2: invalid spec: ):
+?(eval):zformat:2: invalid spec: -:
+?(eval):zformat:2: invalid spec: .:
+?(eval):zformat:2: invalid spec: 0:
+?(eval):zformat:2: invalid spec: 9:
+?(eval):zformat:2: invalid spec: :
+
+ zformat -F REPLY '' ab:
+ zformat -F REPLY '' é:
+-:spec char longer than 1 byte
+?(eval):zformat:1: invalid spec: ab:
+?(eval):zformat:2: invalid spec: \M-C\M-):
+
+ for 1 in ! $ + , : \; \\ $'\a' $'\xff'; do
+ zformat -F REPLY "<%$1>" $1:$1 &&
+ print -r - ${(V)REPLY}
+ done
+0:weird spec char
+><!>
+><$>
+><+>
+><,>
+><:>
+><;>
+><\>
+><^G>
+><\M-^?>
+
+ zformat -F REPLY '%(' &&
+ print -r - $REPLY
+0:%( at end of format string
+>%(
+
+ zformat -F REPLY '%(.'
+ zformat -F REPLY '%()'
+ zformat -F REPLY '%(..)'
+ zformat -F REPLY '<%(>'
+1:incomplete ternary expression
+?(eval):zformat:1: malformed format string: %(.
+?(eval):zformat:2: malformed format string: %()
+?(eval):zformat:3: malformed format string: %(..)
+?(eval):zformat:4: malformed format string: <%(>
+
+ for 1 in % - . 0 9; do
+ zformat -F REPLY "%($1.true.false)" &&
+ print -r - $REPLY
+ done
+1:ternary expression with impossible spec char
+>false
+?(eval):zformat:2: malformed format string: %(-.true.false)
+>false
+?(eval):zformat:2: malformed format string: %(0.true.false)
+?(eval):zformat:2: malformed format string: %(9.true.false)
+
+ for 1 in ! / : @; do
+ zformat -F REPLY "%(x${1}true${1}false)" &&
+ print -r - $REPLY
+ done
+0:ternary expression with alternate delimiters
+>false
+>false
+>false
+>false
+
+ zformat -F REPLY '%(x.%t.%f)' x:123 t:true f:false && print -r - $REPLY
+ zformat -F REPLY '%(X.%t.%f)' x:123 t:true f:false && print -r - $REPLY
+0:ternary expression returning matching spec
+>true
+>false
+
+ zformat -F REPLY '%(x.%T.%F)' x:123 && print -r - $REPLY
+ zformat -F REPLY '%(X.%T.%F)' x:123 && print -r - $REPLY
+0:ternary expression returning non-matching spec
+>%T
+>%F
+
+ zformat -F REPLY '%(x/%../%--)' x:123 && print -r - $REPLY
+ zformat -F REPLY '%(X/%../%--)' x:123 && print -r - $REPLY
+ zformat -F REPLY '%(X.%1%-.%2%-)' x:123 && print -r - $REPLY
+0:ternary expression returning impossible spec
+>%..
+>%--
+>%2%-
+
+ zformat -F REPLY '%(x.%%.%))' x:123 && print -r - $REPLY
+ zformat -F REPLY '%(X.%%.%))' x:123 && print -r - $REPLY
+0:ternary expression returning literal % or )
+>%
+>)