tests/test-template-functions.t
changeset 40934 d3e688b9ef2e
parent 40341 d916ed3ca951
child 40935 4591c9791a82
equal deleted inserted replaced
40933:18513d6ef7d4 40934:d3e688b9ef2e
   600   $ hg debugtemplate '{if(false, count(0), "")}'
   600   $ hg debugtemplate '{if(false, count(0), "")}'
   601   $ hg debugtemplate '{ifcontains("a", "aa", "", count(0))}'
   601   $ hg debugtemplate '{ifcontains("a", "aa", "", count(0))}'
   602   $ hg debugtemplate '{ifcontains("a", "bb", count(0), "")}'
   602   $ hg debugtemplate '{ifcontains("a", "bb", count(0), "")}'
   603   $ hg debugtemplate '{ifeq(0, 0, "", count(0))}'
   603   $ hg debugtemplate '{ifeq(0, 0, "", count(0))}'
   604   $ hg debugtemplate '{ifeq(0, 1, count(0), "")}'
   604   $ hg debugtemplate '{ifeq(0, 1, count(0), "")}'
       
   605 
       
   606 Test search() function:
       
   607 
       
   608   $ hg log -R a -r2 -T '{desc}\n'
       
   609   no person
       
   610 
       
   611   $ hg log -R a -r2 -T '{search(r"p.*", desc)}\n'
       
   612   person
       
   613 
       
   614  as bool
       
   615 
       
   616   $ hg log -R a -r2 -T '{if(search(r"p.*", desc), "", "not ")}found\n'
       
   617   found
       
   618   $ hg log -R a -r2 -T '{if(search(r"q", desc), "", "not ")}found\n'
       
   619   not found
       
   620 
       
   621  match as json
       
   622 
       
   623   $ hg log -R a -r2 -T '{search(r"(no) p.*", desc)|json}\n'
       
   624   {"0": "no person", "1": "no"}
       
   625   $ hg log -R a -r2 -T '{search(r"q", desc)|json}\n'
       
   626   null
       
   627 
       
   628  group reference
       
   629 
       
   630   $ hg log -R a -r2 -T '{search(r"(no) (p.*)", desc) % "{1|upper} {2|hex}"}\n'
       
   631   NO 706572736f6e
       
   632   $ hg log -R a -r2 -T '{search(r"(?P<foo>[a-z]*)", desc) % "{foo}"}\n'
       
   633   no
       
   634   $ hg log -R a -r2 -T '{search(r"(?P<foo>[a-z]*)", desc).foo}\n'
       
   635   no
       
   636 
       
   637  group reference with no match
       
   638  (TODO: we'll probably want to map it to an empty value)
       
   639 
       
   640   $ hg log -R a -r2 -T '{search(r"q", desc) % "match: {0}"}\n'
       
   641   hg: parse error: None is not iterable of mappings
       
   642   [255]
       
   643 
       
   644  bad group names
       
   645 
       
   646   $ hg log -R a -r2 -T '{search(r"(?P<0>.)", desc) % "{0}"}\n'
       
   647   hg: parse error: search got an invalid pattern: (?P<0>.)
       
   648   [255]
       
   649   $ hg log -R a -r2 -T '{search(r"(?P<repo>.)", desc) % "{repo}"}\n'
       
   650   hg: parse error: invalid group 'repo' in search pattern: (?P<repo>.)
       
   651   [255]
   605 
   652 
   606 Test the sub function of templating for expansion:
   653 Test the sub function of templating for expansion:
   607 
   654 
   608   $ hg log -R latesttag -r 10 --template '{sub("[0-9]", "x", "{rev}")}\n'
   655   $ hg log -R latesttag -r 10 --template '{sub("[0-9]", "x", "{rev}")}\n'
   609   xx
   656   xx