Mercurial > public > mercurial-scm > hg
diff tests/test-command-template.t @ 21846:8f23f8096606
templater: introduce word function
This function allows returning only the nth "word" from a string. By default
a string is split as by Python's split() function default, but an optional
third parameter can also override what string the string is split by.
author | Ryan McElroy <rmcelroy@fb.com> |
---|---|
date | Thu, 12 Jun 2014 18:02:23 -0700 |
parents | 028a48105191 |
children | 2b41ee1b5ea1 |
line wrap: on
line diff
--- a/tests/test-command-template.t Thu Jul 03 23:01:37 2014 -0500 +++ b/tests/test-command-template.t Thu Jun 12 18:02:23 2014 -0700 @@ -1917,3 +1917,61 @@ $ hg log -Gv -R a --template '{desc|user()}' hg: parse error: expected a symbol, got 'func' [255] + +Test word function (including index out of bounds graceful failure) + + $ hg log -Gv -R a --template "{word('1', desc)}" + @ + | + o + | + o + + o + |\ + | o head + | | + o | branch + |/ + o user, + | + o person + | + o 1 + | + o 1 + + +Test word third parameter used as splitter + + $ hg log -Gv -R a --template "{word('0', desc, 'o')}" + @ future + | + o third + | + o sec + + o merge + |\ + | o new head + | | + o | new branch + |/ + o n + | + o n + | + o + | + o line 1 + line 2 + +Test word error messages for not enough and too many arguments + + $ hg log -Gv -R a --template "{word('0')}" + hg: parse error: word expects two or three arguments, got 1 + [255] + + $ hg log -Gv -R a --template "{word('0', desc, 'o', 'h', 'b', 'o', 'y')}" + hg: parse error: word expects two or three arguments, got 7 + [255]