Mercurial > hg
comparison tests/test-command-template.t @ 29817:cc11079644fc
templater: make pad() evaluate boolean argument (BC)
Otherwise it would crash if template expression was passed.
This patch unifies the way how boolean expression is evaluated, which involves
BC. Before "if(true)" and "pad(..., 'false')" were False, which are now True
since they are boolean literal and non-empty string respectively.
"func is runsymbol" is the same hack as evalstringliteral(), which is needed
for label() to take color literals.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 22 Apr 2016 21:29:13 +0900 |
parents | 84ef4517de03 |
children | b1f69dbdd76b |
comparison
equal
deleted
inserted
replaced
29816:034412ca28c3 | 29817:cc11079644fc |
---|---|
3321 0 test | 3321 0 test |
3322 $ hg log -r 0 -T '{pad(rev, "not an int")}\n' | 3322 $ hg log -r 0 -T '{pad(rev, "not an int")}\n' |
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' |
3329 a-b-c | 3350 a-b-c |
3330 $ hg log -r 0 -T '{separate(" ", "{rev}:{node|short}", author|user, branch)}\n' | 3351 $ hg log -r 0 -T '{separate(" ", "{rev}:{node|short}", author|user, branch)}\n' |
3331 0:f7769ec2ab97 test default | 3352 0:f7769ec2ab97 test default |
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) |
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 | |
3334 | 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' |
3338 2 is in the string | 3376 2 is in the string |