Show More
@@ -290,8 +290,15 b' def evalfuncarg(context, mapping, arg):' | |||||
290 | return thing |
|
290 | return thing | |
291 |
|
291 | |||
292 | def evalboolean(context, mapping, arg): |
|
292 | def evalboolean(context, mapping, arg): | |
|
293 | """Evaluate given argument as boolean, but also takes boolean literals""" | |||
293 | func, data = arg |
|
294 | func, data = arg | |
294 | thing = func(context, mapping, data) |
|
295 | if func is runsymbol: | |
|
296 | thing = func(context, mapping, data, default=None) | |||
|
297 | if thing is None: | |||
|
298 | # not a template keyword, takes as a boolean literal | |||
|
299 | thing = util.parsebool(data) | |||
|
300 | else: | |||
|
301 | thing = func(context, mapping, data) | |||
295 | if isinstance(thing, bool): |
|
302 | if isinstance(thing, bool): | |
296 | return thing |
|
303 | return thing | |
297 | # other objects are evaluated as strings, which means 0 is True, but |
|
304 | # other objects are evaluated as strings, which means 0 is True, but | |
@@ -516,7 +523,7 b' def pad(context, mapping, args):' | |||||
516 | if len(args) > 2: |
|
523 | if len(args) > 2: | |
517 | fillchar = evalstring(context, mapping, args[2]) |
|
524 | fillchar = evalstring(context, mapping, args[2]) | |
518 | if len(args) > 3: |
|
525 | if len(args) > 3: | |
519 |
right = |
|
526 | right = evalboolean(context, mapping, args[3]) | |
520 |
|
527 | |||
521 | if right: |
|
528 | if right: | |
522 | return text.rjust(width, fillchar) |
|
529 | return text.rjust(width, fillchar) |
@@ -3323,6 +3323,27 b' Test width argument passed to pad functi' | |||||
3323 | hg: parse error: pad() expects an integer width |
|
3323 | hg: parse error: pad() expects an integer width | |
3324 | [255] |
|
3324 | [255] | |
3325 |
|
3325 | |||
|
3326 | Test boolean argument passed to pad function | |||
|
3327 | ||||
|
3328 | no crash | |||
|
3329 | ||||
|
3330 | $ hg log -r 0 -T '{pad(rev, 10, "-", "f{"oo"}")}\n' | |||
|
3331 | ---------0 | |||
|
3332 | ||||
|
3333 | string/literal | |||
|
3334 | ||||
|
3335 | $ hg log -r 0 -T '{pad(rev, 10, "-", "false")}\n' | |||
|
3336 | ---------0 | |||
|
3337 | $ hg log -r 0 -T '{pad(rev, 10, "-", false)}\n' | |||
|
3338 | 0--------- | |||
|
3339 | $ hg log -r 0 -T '{pad(rev, 10, "-", "")}\n' | |||
|
3340 | 0--------- | |||
|
3341 | ||||
|
3342 | unknown keyword is evaluated to '' | |||
|
3343 | ||||
|
3344 | $ hg log -r 0 -T '{pad(rev, 10, "-", unknownkeyword)}\n' | |||
|
3345 | 0--------- | |||
|
3346 | ||||
3326 | Test separate function |
|
3347 | Test separate function | |
3327 |
|
3348 | |||
3328 | $ hg log -r 0 -T '{separate("-", "", "a", "b", "", "", "c", "")}\n' |
|
3349 | $ hg log -r 0 -T '{separate("-", "", "a", "b", "", "", "c", "")}\n' | |
@@ -3332,6 +3353,23 b' Test separate function' | |||||
3332 | $ hg log -r 0 --color=always -T '{separate(" ", "a", label(red, "b"), "c", label(red, ""), "d")}\n' |
|
3353 | $ hg log -r 0 --color=always -T '{separate(" ", "a", label(red, "b"), "c", label(red, ""), "d")}\n' | |
3333 | a \x1b[0;31mb\x1b[0m c d (esc) |
|
3354 | a \x1b[0;31mb\x1b[0m c d (esc) | |
3334 |
|
3355 | |||
|
3356 | Test boolean expression/literal passed to if function | |||
|
3357 | ||||
|
3358 | $ hg log -r 0 -T '{if(rev, "rev 0 is True")}\n' | |||
|
3359 | rev 0 is True | |||
|
3360 | $ hg log -r 0 -T '{if(0, "literal 0 is True as well")}\n' | |||
|
3361 | literal 0 is True as well | |||
|
3362 | $ hg log -r 0 -T '{if("", "", "empty string is False")}\n' | |||
|
3363 | empty string is False | |||
|
3364 | $ hg log -r 0 -T '{if(revset(r"0 - 0"), "", "empty list is False")}\n' | |||
|
3365 | empty list is False | |||
|
3366 | $ hg log -r 0 -T '{if(true, "true is True")}\n' | |||
|
3367 | true is True | |||
|
3368 | $ hg log -r 0 -T '{if(false, "", "false is False")}\n' | |||
|
3369 | false is False | |||
|
3370 | $ hg log -r 0 -T '{if("false", "non-empty string is True")}\n' | |||
|
3371 | non-empty string is True | |||
|
3372 | ||||
3335 | Test ifcontains function |
|
3373 | Test ifcontains function | |
3336 |
|
3374 | |||
3337 | $ hg log --template '{rev} {ifcontains(rev, "2 two 0", "is in the string", "is not")}\n' |
|
3375 | $ hg log --template '{rev} {ifcontains(rev, "2 two 0", "is in the string", "is not")}\n' |
General Comments 0
You need to be logged in to leave comments.
Login now