tests/test-template-basic.t
changeset 45895 fc4fb2f17dd4
parent 40942 e48fdeb08c77
child 46120 c000eff2c635
equal deleted inserted replaced
45894:9dc1351d0b5f 45895:fc4fb2f17dd4
   137         (symbol 'stringify')))
   137         (symbol 'stringify')))
   138     (string '\n'))
   138     (string '\n'))
   139   * keywords: 
   139   * keywords: 
   140   * functions: stringify
   140   * functions: stringify
   141   hg: parse error: arithmetic only defined on integers
   141   hg: parse error: arithmetic only defined on integers
   142   [255]
   142   [10]
   143   $ hg debugtemplate -r0 -v '{-3|stringify}\n'
   143   $ hg debugtemplate -r0 -v '{-3|stringify}\n'
   144   (template
   144   (template
   145     (|
   145     (|
   146       (negate
   146       (negate
   147         (integer '3'))
   147         (integer '3'))
   177         (symbol 'bar')
   177         (symbol 'bar')
   178         (symbol 'baz'))))
   178         (symbol 'baz'))))
   179   * keywords: bar, foo
   179   * keywords: bar, foo
   180   * functions: baz
   180   * functions: baz
   181   hg: parse error: can't use a key-value pair in this context
   181   hg: parse error: can't use a key-value pair in this context
   182   [255]
   182   [10]
   183 
   183 
   184   $ hg debugtemplate '{pad("foo", width=10, left=true)}\n'
   184   $ hg debugtemplate '{pad("foo", width=10, left=true)}\n'
   185          foo
   185          foo
   186 
   186 
   187 Call function which takes named arguments by filter syntax:
   187 Call function which takes named arguments by filter syntax:
   188 
   188 
   189   $ hg debugtemplate '{" "|separate}'
   189   $ hg debugtemplate '{" "|separate}'
   190   $ hg debugtemplate '{("not", "an", "argument", "list")|separate}'
   190   $ hg debugtemplate '{("not", "an", "argument", "list")|separate}'
   191   hg: parse error: can't use a list in this context
   191   hg: parse error: can't use a list in this context
   192   (check place of comma and parens)
   192   (check place of comma and parens)
   193   [255]
   193   [10]
   194 
   194 
   195 Second branch starting at nullrev:
   195 Second branch starting at nullrev:
   196 
   196 
   197   $ hg update null
   197   $ hg update null
   198   0 files updated, 0 files merged, 4 files removed, 0 files unresolved
   198   0 files updated, 0 files merged, 4 files removed, 0 files unresolved
   305   > EOF
   305   > EOF
   306   $ echo '[ui]' > .hg/hgrc
   306   $ echo '[ui]' > .hg/hgrc
   307   $ echo 'style = t' >> .hg/hgrc
   307   $ echo 'style = t' >> .hg/hgrc
   308   $ hg log
   308   $ hg log
   309   hg: parse error at t:3: unmatched quotes
   309   hg: parse error at t:3: unmatched quotes
   310   [255]
   310   [10]
   311 
   311 
   312   $ hg log -T '{date'
   312   $ hg log -T '{date'
   313   hg: parse error at 1: unterminated template expansion
   313   hg: parse error at 1: unterminated template expansion
   314   ({date
   314   ({date
   315     ^ here)
   315     ^ here)
   316   [255]
   316   [10]
   317   $ hg log -T '{date(}'
   317   $ hg log -T '{date(}'
   318   hg: parse error at 6: not a prefix: end
   318   hg: parse error at 6: not a prefix: end
   319   ({date(}
   319   ({date(}
   320          ^ here)
   320          ^ here)
   321   [255]
   321   [10]
   322   $ hg log -T '{date)}'
   322   $ hg log -T '{date)}'
   323   hg: parse error at 5: invalid token
   323   hg: parse error at 5: invalid token
   324   ({date)}
   324   ({date)}
   325         ^ here)
   325         ^ here)
   326   [255]
   326   [10]
   327   $ hg log -T '{date date}'
   327   $ hg log -T '{date date}'
   328   hg: parse error at 6: invalid token
   328   hg: parse error at 6: invalid token
   329   ({date date}
   329   ({date date}
   330          ^ here)
   330          ^ here)
   331   [255]
   331   [10]
   332 
   332 
   333   $ hg log -T '{}'
   333   $ hg log -T '{}'
   334   hg: parse error at 1: not a prefix: end
   334   hg: parse error at 1: not a prefix: end
   335   ({}
   335   ({}
   336     ^ here)
   336     ^ here)
   337   [255]
   337   [10]
   338   $ hg debugtemplate -v '{()}'
   338   $ hg debugtemplate -v '{()}'
   339   (template
   339   (template
   340     (group
   340     (group
   341       None))
   341       None))
   342   * keywords: 
   342   * keywords: 
   343   * functions: 
   343   * functions: 
   344   hg: parse error: missing argument
   344   hg: parse error: missing argument
   345   [255]
   345   [10]
   346 
   346 
   347 Behind the scenes, this would throw TypeError without intype=bytes
   347 Behind the scenes, this would throw TypeError without intype=bytes
   348 
   348 
   349   $ hg log -l 3 --template '{date|obfuscate}\n'
   349   $ hg log -l 3 --template '{date|obfuscate}\n'
   350   0.00
   350   0.00
   354 Behind the scenes, this will throw a ValueError
   354 Behind the scenes, this will throw a ValueError
   355 
   355 
   356   $ hg log -l 3 --template 'line: {desc|shortdate}\n'
   356   $ hg log -l 3 --template 'line: {desc|shortdate}\n'
   357   hg: parse error: invalid date: 'Modify, add, remove, rename'
   357   hg: parse error: invalid date: 'Modify, add, remove, rename'
   358   (template filter 'shortdate' is not compatible with keyword 'desc')
   358   (template filter 'shortdate' is not compatible with keyword 'desc')
   359   [255]
   359   [10]
   360 
   360 
   361 Behind the scenes, this would throw AttributeError without intype=bytes
   361 Behind the scenes, this would throw AttributeError without intype=bytes
   362 
   362 
   363   $ hg log -l 3 --template 'line: {date|escape}\n'
   363   $ hg log -l 3 --template 'line: {date|escape}\n'
   364   line: 0.00
   364   line: 0.00
   365   line: 0.00
   365   line: 0.00
   366   line: 1577872860.00
   366   line: 1577872860.00
   367 
   367 
   368   $ hg log -l 3 --template 'line: {extras|localdate}\n'
   368   $ hg log -l 3 --template 'line: {extras|localdate}\n'
   369   hg: parse error: localdate expects a date information
   369   hg: parse error: localdate expects a date information
   370   [255]
   370   [10]
   371 
   371 
   372 Behind the scenes, this will throw ValueError
   372 Behind the scenes, this will throw ValueError
   373 
   373 
   374   $ hg tip --template '{author|email|date}\n'
   374   $ hg tip --template '{author|email|date}\n'
   375   hg: parse error: date expects a date information
   375   hg: parse error: date expects a date information
   376   [255]
   376   [10]
   377 
   377 
   378   $ hg tip -T '{author|email|shortdate}\n'
   378   $ hg tip -T '{author|email|shortdate}\n'
   379   hg: parse error: invalid date: 'test'
   379   hg: parse error: invalid date: 'test'
   380   (template filter 'shortdate' is not compatible with keyword 'author')
   380   (template filter 'shortdate' is not compatible with keyword 'author')
   381   [255]
   381   [10]
   382 
   382 
   383   $ hg tip -T '{get(extras, "branch")|shortdate}\n'
   383   $ hg tip -T '{get(extras, "branch")|shortdate}\n'
   384   hg: parse error: invalid date: 'default'
   384   hg: parse error: invalid date: 'default'
   385   (incompatible use of template filter 'shortdate')
   385   (incompatible use of template filter 'shortdate')
   386   [255]
   386   [10]
   387 
   387 
   388 Error in nested template:
   388 Error in nested template:
   389 
   389 
   390   $ hg log -T '{"date'
   390   $ hg log -T '{"date'
   391   hg: parse error at 2: unterminated string
   391   hg: parse error at 2: unterminated string
   392   ({"date
   392   ({"date
   393      ^ here)
   393      ^ here)
   394   [255]
   394   [10]
   395 
   395 
   396   $ hg log -T '{"foo{date|?}"}'
   396   $ hg log -T '{"foo{date|?}"}'
   397   hg: parse error at 11: syntax error
   397   hg: parse error at 11: syntax error
   398   ({"foo{date|?}"}
   398   ({"foo{date|?}"}
   399               ^ here)
   399               ^ here)
   400   [255]
   400   [10]
   401 
   401 
   402 Thrown an error if a template function doesn't exist
   402 Thrown an error if a template function doesn't exist
   403 
   403 
   404   $ hg tip --template '{foo()}\n'
   404   $ hg tip --template '{foo()}\n'
   405   hg: parse error: unknown function 'foo'
   405   hg: parse error: unknown function 'foo'
   406   [255]
   406   [10]
   407 
   407 
   408   $ cd ..
   408   $ cd ..
   409 
   409 
   410 Set up latesttag repository:
   410 Set up latesttag repository:
   411 
   411 
   451   
   451   
   452 
   452 
   453   $ hg log -R latesttag -r tip -T '{rev % "a"}\n'
   453   $ hg log -R latesttag -r tip -T '{rev % "a"}\n'
   454   hg: parse error: 11 is not iterable of mappings
   454   hg: parse error: 11 is not iterable of mappings
   455   (keyword 'rev' does not support map operation)
   455   (keyword 'rev' does not support map operation)
   456   [255]
   456   [10]
   457   $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "a"}\n'
   457   $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "a"}\n'
   458   hg: parse error: None is not iterable of mappings
   458   hg: parse error: None is not iterable of mappings
   459   [255]
   459   [10]
   460   $ hg log -R latesttag -r tip -T '{extras % "{key}\n" % "{key}\n"}'
   460   $ hg log -R latesttag -r tip -T '{extras % "{key}\n" % "{key}\n"}'
   461   hg: parse error: list of strings is not mappable
   461   hg: parse error: list of strings is not mappable
   462   [255]
   462   [10]
   463 
   463 
   464 Test new-style inline templating of non-list/dict type:
   464 Test new-style inline templating of non-list/dict type:
   465 
   465 
   466   $ hg log -R latesttag -r tip -T '{manifest}\n'
   466   $ hg log -R latesttag -r tip -T '{manifest}\n'
   467   11:2bc6e9006ce2
   467   11:2bc6e9006ce2
   472 
   472 
   473   $ hg log -R latesttag -r tip -T '{get(extras, "branch") % "{key}: {value}\n"}'
   473   $ hg log -R latesttag -r tip -T '{get(extras, "branch") % "{key}: {value}\n"}'
   474   branch: default
   474   branch: default
   475   $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "{key}\n"}'
   475   $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "{key}\n"}'
   476   hg: parse error: None is not iterable of mappings
   476   hg: parse error: None is not iterable of mappings
   477   [255]
   477   [10]
   478   $ hg log -R latesttag -r tip -T '{min(extras) % "{key}: {value}\n"}'
   478   $ hg log -R latesttag -r tip -T '{min(extras) % "{key}: {value}\n"}'
   479   branch: default
   479   branch: default
   480   $ hg log -R latesttag -l1 -T '{min(revset("0:9")) % "{rev}:{node|short}\n"}'
   480   $ hg log -R latesttag -l1 -T '{min(revset("0:9")) % "{rev}:{node|short}\n"}'
   481   0:ce3cec86e6c2
   481   0:ce3cec86e6c2
   482   $ hg log -R latesttag -l1 -T '{max(revset("0:9")) % "{rev}:{node|short}\n"}'
   482   $ hg log -R latesttag -l1 -T '{max(revset("0:9")) % "{rev}:{node|short}\n"}'
   504       (symbol 'foo')
   504       (symbol 'foo')
   505       (.
   505       (.
   506         (symbol 'bar')
   506         (symbol 'bar')
   507         (symbol 'baz')))
   507         (symbol 'baz')))
   508     (string '\n'))
   508     (string '\n'))
   509   [255]
   509   [10]
   510   $ hg debugtemplate -R latesttag -r0 -v '{foo.bar()}\n' 2> /dev/null
   510   $ hg debugtemplate -R latesttag -r0 -v '{foo.bar()}\n' 2> /dev/null
   511   (template
   511   (template
   512     (.
   512     (.
   513       (symbol 'foo')
   513       (symbol 'foo')
   514       (func
   514       (func
   515         (symbol 'bar')
   515         (symbol 'bar')
   516         None))
   516         None))
   517     (string '\n'))
   517     (string '\n'))
   518   * keywords: foo
   518   * keywords: foo
   519   * functions: bar
   519   * functions: bar
   520   [255]
   520   [10]
   521 
   521 
   522 Test evaluation of dot operator:
   522 Test evaluation of dot operator:
   523 
   523 
   524   $ hg log -R latesttag -l1 -T '{min(revset("0:9")).node}\n'
   524   $ hg log -R latesttag -l1 -T '{min(revset("0:9")).node}\n'
   525   ce3cec86e6c26bd9bdfc590a6b92abc9680f1796
   525   ce3cec86e6c26bd9bdfc590a6b92abc9680f1796
   529   0 -7200
   529   0 -7200
   530 
   530 
   531   $ hg log -R latesttag -l1 -T '{author.invalid}\n'
   531   $ hg log -R latesttag -l1 -T '{author.invalid}\n'
   532   hg: parse error: 'test' is not a dictionary
   532   hg: parse error: 'test' is not a dictionary
   533   (keyword 'author' does not support member operation)
   533   (keyword 'author' does not support member operation)
   534   [255]
   534   [10]
   535   $ hg log -R latesttag -l1 -T '{min("abc").invalid}\n'
   535   $ hg log -R latesttag -l1 -T '{min("abc").invalid}\n'
   536   hg: parse error: 'a' is not a dictionary
   536   hg: parse error: 'a' is not a dictionary
   537   [255]
   537   [10]
   538 
   538 
   539 Test integer literal:
   539 Test integer literal:
   540 
   540 
   541   $ hg debugtemplate -v '{(0)}\n'
   541   $ hg debugtemplate -v '{(0)}\n'
   542   (template
   542   (template
   565   -4
   565   -4
   566   $ hg debugtemplate '{(-)}\n'
   566   $ hg debugtemplate '{(-)}\n'
   567   hg: parse error at 3: not a prefix: )
   567   hg: parse error at 3: not a prefix: )
   568   ({(-)}\n
   568   ({(-)}\n
   569       ^ here)
   569       ^ here)
   570   [255]
   570   [10]
   571   $ hg debugtemplate '{(-a)}\n'
   571   $ hg debugtemplate '{(-a)}\n'
   572   hg: parse error: negation needs an integer argument
   572   hg: parse error: negation needs an integer argument
   573   [255]
   573   [10]
   574 
   574 
   575 top-level integer literal is interpreted as symbol (i.e. variable name):
   575 top-level integer literal is interpreted as symbol (i.e. variable name):
   576 
   576 
   577   $ hg debugtemplate -D 1=one -v '{1}\n'
   577   $ hg debugtemplate -D 1=one -v '{1}\n'
   578   (template
   578   (template
   605 
   605 
   606 unless explicit symbol is expected:
   606 unless explicit symbol is expected:
   607 
   607 
   608   $ hg log -Ra -r0 -T '{desc|1}\n'
   608   $ hg log -Ra -r0 -T '{desc|1}\n'
   609   hg: parse error: expected a symbol, got 'integer'
   609   hg: parse error: expected a symbol, got 'integer'
   610   [255]
   610   [10]
   611   $ hg log -Ra -r0 -T '{1()}\n'
   611   $ hg log -Ra -r0 -T '{1()}\n'
   612   hg: parse error: expected a symbol, got 'integer'
   612   hg: parse error: expected a symbol, got 'integer'
   613   [255]
   613   [10]
   614 
   614 
   615 Test string literal:
   615 Test string literal:
   616 
   616 
   617   $ hg debugtemplate -Ra -r0 -v '{"string with no template fragment"}\n'
   617   $ hg debugtemplate -Ra -r0 -v '{"string with no template fragment"}\n'
   618   (template
   618   (template
   746   foo
   746   foo
   747   $ hg log -r 2 -T '{if(rev, "{if(rev, \")}")}\n'
   747   $ hg log -r 2 -T '{if(rev, "{if(rev, \")}")}\n'
   748   hg: parse error at 21: unterminated string
   748   hg: parse error at 21: unterminated string
   749   ({if(rev, "{if(rev, \")}")}\n
   749   ({if(rev, "{if(rev, \")}")}\n
   750                         ^ here)
   750                         ^ here)
   751   [255]
   751   [10]
   752   $ hg log -r 2 -T '{if(rev, \"\\"")}\n'
   752   $ hg log -r 2 -T '{if(rev, \"\\"")}\n'
   753   hg: parse error: trailing \ in string
   753   hg: parse error: trailing \ in string
   754   [255]
   754   [10]
   755   $ hg log -r 2 -T '{if(rev, r\"\\"")}\n'
   755   $ hg log -r 2 -T '{if(rev, r\"\\"")}\n'
   756   hg: parse error: trailing \ in string
   756   hg: parse error: trailing \ in string
   757   [255]
   757   [10]
   758 
   758 
   759   $ cd ..
   759   $ cd ..
   760 
   760 
   761 Test leading backslashes:
   761 Test leading backslashes:
   762 
   762 
   898   text.1:be wrapped
   898   text.1:be wrapped
   899   text.1:desc to be
   899   text.1:desc to be
   900   text.1:wrapped (no-eol)
   900   text.1:wrapped (no-eol)
   901   $ hg log -l1 -T '{fill(desc, date, "", "")}\n'
   901   $ hg log -l1 -T '{fill(desc, date, "", "")}\n'
   902   hg: parse error: fill expects an integer width
   902   hg: parse error: fill expects an integer width
   903   [255]
   903   [10]
   904 
   904 
   905   $ hg log -l 1 --template '{sub(r"[0-9]", "-", author)}'
   905   $ hg log -l 1 --template '{sub(r"[0-9]", "-", author)}'
   906   {node|short} (no-eol)
   906   {node|short} (no-eol)
   907   $ hg log -l 1 --template '{sub(r"[0-9]", "-", "{node|short}")}'
   907   $ hg log -l 1 --template '{sub(r"[0-9]", "-", "{node|short}")}'
   908   bcc-ff---b-e (no-eol)
   908   bcc-ff---b-e (no-eol)
   924 
   924 
   925 Test bad template with better error message
   925 Test bad template with better error message
   926 
   926 
   927   $ hg log -Gv -R a --template '{desc|user()}'
   927   $ hg log -Gv -R a --template '{desc|user()}'
   928   hg: parse error: expected a symbol, got 'func'
   928   hg: parse error: expected a symbol, got 'func'
   929   [255]
   929   [10]
   930 
   930 
   931 Test broken string escapes:
   931 Test broken string escapes:
   932 
   932 
   933   $ hg log -T "bogus\\" -R a
   933   $ hg log -T "bogus\\" -R a
   934   hg: parse error: trailing \ in string
   934   hg: parse error: trailing \ in string
   935   [255]
   935   [10]
   936   $ hg log -T "\\xy" -R a
   936   $ hg log -T "\\xy" -R a
   937   hg: parse error: invalid \x escape* (glob)
   937   hg: parse error: invalid \x escape* (glob)
   938   [255]
   938   [10]
   939 
   939 
   940 Templater supports aliases of symbol and func() styles:
   940 Templater supports aliases of symbol and func() styles:
   941 
   941 
   942   $ hg clone -q a aliases
   942   $ hg clone -q a aliases
   943   $ cd aliases
   943   $ cd aliases