comparison tests/test-command-template.t @ 34073:7bbc4e113e5f

parser: stabilize output of prettyformat() by using byte-safe repr() The format of leaf nodes is slightly changed so they look more similar to internal nodes.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 03 Sep 2017 21:17:25 +0900
parents 42361715dd11
children 6367318327f0
comparison
equal deleted inserted replaced
34072:30535fe47e78 34073:7bbc4e113e5f
39 Test division: 39 Test division:
40 40
41 $ hg debugtemplate -r0 -v '{5 / 2} {mod(5, 2)}\n' 41 $ hg debugtemplate -r0 -v '{5 / 2} {mod(5, 2)}\n'
42 (template 42 (template
43 (/ 43 (/
44 ('integer', '5') 44 (integer '5')
45 ('integer', '2')) 45 (integer '2'))
46 ('string', ' ') 46 (string ' ')
47 (func 47 (func
48 ('symbol', 'mod') 48 (symbol 'mod')
49 (list 49 (list
50 ('integer', '5') 50 (integer '5')
51 ('integer', '2'))) 51 (integer '2')))
52 ('string', '\n')) 52 (string '\n'))
53 2 1 53 2 1
54 $ hg debugtemplate -r0 -v '{5 / -2} {mod(5, -2)}\n' 54 $ hg debugtemplate -r0 -v '{5 / -2} {mod(5, -2)}\n'
55 (template 55 (template
56 (/ 56 (/
57 ('integer', '5') 57 (integer '5')
58 (negate 58 (negate
59 ('integer', '2'))) 59 (integer '2')))
60 ('string', ' ') 60 (string ' ')
61 (func 61 (func
62 ('symbol', 'mod') 62 (symbol 'mod')
63 (list 63 (list
64 ('integer', '5') 64 (integer '5')
65 (negate 65 (negate
66 ('integer', '2')))) 66 (integer '2'))))
67 ('string', '\n')) 67 (string '\n'))
68 -3 -1 68 -3 -1
69 $ hg debugtemplate -r0 -v '{-5 / 2} {mod(-5, 2)}\n' 69 $ hg debugtemplate -r0 -v '{-5 / 2} {mod(-5, 2)}\n'
70 (template 70 (template
71 (/ 71 (/
72 (negate 72 (negate
73 ('integer', '5')) 73 (integer '5'))
74 ('integer', '2')) 74 (integer '2'))
75 ('string', ' ') 75 (string ' ')
76 (func 76 (func
77 ('symbol', 'mod') 77 (symbol 'mod')
78 (list 78 (list
79 (negate 79 (negate
80 ('integer', '5')) 80 (integer '5'))
81 ('integer', '2'))) 81 (integer '2')))
82 ('string', '\n')) 82 (string '\n'))
83 -3 1 83 -3 1
84 $ hg debugtemplate -r0 -v '{-5 / -2} {mod(-5, -2)}\n' 84 $ hg debugtemplate -r0 -v '{-5 / -2} {mod(-5, -2)}\n'
85 (template 85 (template
86 (/ 86 (/
87 (negate 87 (negate
88 ('integer', '5')) 88 (integer '5'))
89 (negate 89 (negate
90 ('integer', '2'))) 90 (integer '2')))
91 ('string', ' ') 91 (string ' ')
92 (func 92 (func
93 ('symbol', 'mod') 93 (symbol 'mod')
94 (list 94 (list
95 (negate 95 (negate
96 ('integer', '5')) 96 (integer '5'))
97 (negate 97 (negate
98 ('integer', '2')))) 98 (integer '2'))))
99 ('string', '\n')) 99 (string '\n'))
100 2 -1 100 2 -1
101 101
102 Filters bind closer than arithmetic: 102 Filters bind closer than arithmetic:
103 103
104 $ hg debugtemplate -r0 -v '{revset(".")|count - 1}\n' 104 $ hg debugtemplate -r0 -v '{revset(".")|count - 1}\n'
105 (template 105 (template
106 (- 106 (-
107 (| 107 (|
108 (func 108 (func
109 ('symbol', 'revset') 109 (symbol 'revset')
110 ('string', '.')) 110 (string '.'))
111 ('symbol', 'count')) 111 (symbol 'count'))
112 ('integer', '1')) 112 (integer '1'))
113 ('string', '\n')) 113 (string '\n'))
114 0 114 0
115 115
116 But negate binds closer still: 116 But negate binds closer still:
117 117
118 $ hg debugtemplate -r0 -v '{1-3|stringify}\n' 118 $ hg debugtemplate -r0 -v '{1-3|stringify}\n'
119 (template 119 (template
120 (- 120 (-
121 ('integer', '1') 121 (integer '1')
122 (| 122 (|
123 ('integer', '3') 123 (integer '3')
124 ('symbol', 'stringify'))) 124 (symbol 'stringify')))
125 ('string', '\n')) 125 (string '\n'))
126 hg: parse error: arithmetic only defined on integers 126 hg: parse error: arithmetic only defined on integers
127 [255] 127 [255]
128 $ hg debugtemplate -r0 -v '{-3|stringify}\n' 128 $ hg debugtemplate -r0 -v '{-3|stringify}\n'
129 (template 129 (template
130 (| 130 (|
131 (negate 131 (negate
132 ('integer', '3')) 132 (integer '3'))
133 ('symbol', 'stringify')) 133 (symbol 'stringify'))
134 ('string', '\n')) 134 (string '\n'))
135 -3 135 -3
136 136
137 Keyword arguments: 137 Keyword arguments:
138 138
139 $ hg debugtemplate -r0 -v '{foo=bar|baz}' 139 $ hg debugtemplate -r0 -v '{foo=bar|baz}'
140 (template 140 (template
141 (keyvalue 141 (keyvalue
142 ('symbol', 'foo') 142 (symbol 'foo')
143 (| 143 (|
144 ('symbol', 'bar') 144 (symbol 'bar')
145 ('symbol', 'baz')))) 145 (symbol 'baz'))))
146 hg: parse error: can't use a key-value pair in this context 146 hg: parse error: can't use a key-value pair in this context
147 [255] 147 [255]
148 148
149 $ hg debugtemplate '{pad("foo", width=10, left=true)}\n' 149 $ hg debugtemplate '{pad("foo", width=10, left=true)}\n'
150 foo 150 foo
3172 Test integer literal: 3172 Test integer literal:
3173 3173
3174 $ hg debugtemplate -v '{(0)}\n' 3174 $ hg debugtemplate -v '{(0)}\n'
3175 (template 3175 (template
3176 (group 3176 (group
3177 ('integer', '0')) 3177 (integer '0'))
3178 ('string', '\n')) 3178 (string '\n'))
3179 0 3179 0
3180 $ hg debugtemplate -v '{(123)}\n' 3180 $ hg debugtemplate -v '{(123)}\n'
3181 (template 3181 (template
3182 (group 3182 (group
3183 ('integer', '123')) 3183 (integer '123'))
3184 ('string', '\n')) 3184 (string '\n'))
3185 123 3185 123
3186 $ hg debugtemplate -v '{(-4)}\n' 3186 $ hg debugtemplate -v '{(-4)}\n'
3187 (template 3187 (template
3188 (group 3188 (group
3189 (negate 3189 (negate
3190 ('integer', '4'))) 3190 (integer '4')))
3191 ('string', '\n')) 3191 (string '\n'))
3192 -4 3192 -4
3193 $ hg debugtemplate '{(-)}\n' 3193 $ hg debugtemplate '{(-)}\n'
3194 hg: parse error at 3: not a prefix: ) 3194 hg: parse error at 3: not a prefix: )
3195 [255] 3195 [255]
3196 $ hg debugtemplate '{(-a)}\n' 3196 $ hg debugtemplate '{(-a)}\n'
3199 3199
3200 top-level integer literal is interpreted as symbol (i.e. variable name): 3200 top-level integer literal is interpreted as symbol (i.e. variable name):
3201 3201
3202 $ hg debugtemplate -D 1=one -v '{1}\n' 3202 $ hg debugtemplate -D 1=one -v '{1}\n'
3203 (template 3203 (template
3204 ('integer', '1') 3204 (integer '1')
3205 ('string', '\n')) 3205 (string '\n'))
3206 one 3206 one
3207 $ hg debugtemplate -D 1=one -v '{if("t", "{1}")}\n' 3207 $ hg debugtemplate -D 1=one -v '{if("t", "{1}")}\n'
3208 (template 3208 (template
3209 (func 3209 (func
3210 ('symbol', 'if') 3210 (symbol 'if')
3211 (list 3211 (list
3212 ('string', 't') 3212 (string 't')
3213 (template 3213 (template
3214 ('integer', '1')))) 3214 (integer '1'))))
3215 ('string', '\n')) 3215 (string '\n'))
3216 one 3216 one
3217 $ hg debugtemplate -D 1=one -v '{1|stringify}\n' 3217 $ hg debugtemplate -D 1=one -v '{1|stringify}\n'
3218 (template 3218 (template
3219 (| 3219 (|
3220 ('integer', '1') 3220 (integer '1')
3221 ('symbol', 'stringify')) 3221 (symbol 'stringify'))
3222 ('string', '\n')) 3222 (string '\n'))
3223 one 3223 one
3224 3224
3225 unless explicit symbol is expected: 3225 unless explicit symbol is expected:
3226 3226
3227 $ hg log -Ra -r0 -T '{desc|1}\n' 3227 $ hg log -Ra -r0 -T '{desc|1}\n'
3233 3233
3234 Test string literal: 3234 Test string literal:
3235 3235
3236 $ hg debugtemplate -Ra -r0 -v '{"string with no template fragment"}\n' 3236 $ hg debugtemplate -Ra -r0 -v '{"string with no template fragment"}\n'
3237 (template 3237 (template
3238 ('string', 'string with no template fragment') 3238 (string 'string with no template fragment')
3239 ('string', '\n')) 3239 (string '\n'))
3240 string with no template fragment 3240 string with no template fragment
3241 $ hg debugtemplate -Ra -r0 -v '{"template: {rev}"}\n' 3241 $ hg debugtemplate -Ra -r0 -v '{"template: {rev}"}\n'
3242 (template 3242 (template
3243 (template 3243 (template
3244 ('string', 'template: ') 3244 (string 'template: ')
3245 ('symbol', 'rev')) 3245 (symbol 'rev'))
3246 ('string', '\n')) 3246 (string '\n'))
3247 template: 0 3247 template: 0
3248 $ hg debugtemplate -Ra -r0 -v '{r"rawstring: {rev}"}\n' 3248 $ hg debugtemplate -Ra -r0 -v '{r"rawstring: {rev}"}\n'
3249 (template 3249 (template
3250 ('string', 'rawstring: {rev}') 3250 (string 'rawstring: {rev}')
3251 ('string', '\n')) 3251 (string '\n'))
3252 rawstring: {rev} 3252 rawstring: {rev}
3253 $ hg debugtemplate -Ra -r0 -v '{files % r"rawstring: {file}"}\n' 3253 $ hg debugtemplate -Ra -r0 -v '{files % r"rawstring: {file}"}\n'
3254 (template 3254 (template
3255 (% 3255 (%
3256 ('symbol', 'files') 3256 (symbol 'files')
3257 ('string', 'rawstring: {file}')) 3257 (string 'rawstring: {file}'))
3258 ('string', '\n')) 3258 (string '\n'))
3259 rawstring: {file} 3259 rawstring: {file}
3260 3260
3261 Test string escaping: 3261 Test string escaping:
3262 3262
3263 $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n' 3263 $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
4240 > utcdate(d) = localdate(d, "UTC") 4240 > utcdate(d) = localdate(d, "UTC")
4241 > EOF 4241 > EOF
4242 4242
4243 $ hg debugtemplate -vr0 '{rn} {utcdate(date)|isodate}\n' 4243 $ hg debugtemplate -vr0 '{rn} {utcdate(date)|isodate}\n'
4244 (template 4244 (template
4245 ('symbol', 'rn') 4245 (symbol 'rn')
4246 ('string', ' ') 4246 (string ' ')
4247 (| 4247 (|
4248 (func 4248 (func
4249 ('symbol', 'utcdate') 4249 (symbol 'utcdate')
4250 ('symbol', 'date')) 4250 (symbol 'date'))
4251 ('symbol', 'isodate')) 4251 (symbol 'isodate'))
4252 ('string', '\n')) 4252 (string '\n'))
4253 * expanded: 4253 * expanded:
4254 (template 4254 (template
4255 (template 4255 (template
4256 ('symbol', 'rev') 4256 (symbol 'rev')
4257 ('string', ':') 4257 (string ':')
4258 (| 4258 (|
4259 ('symbol', 'node') 4259 (symbol 'node')
4260 ('symbol', 'short'))) 4260 (symbol 'short')))
4261 ('string', ' ') 4261 (string ' ')
4262 (| 4262 (|
4263 (func 4263 (func
4264 ('symbol', 'localdate') 4264 (symbol 'localdate')
4265 (list 4265 (list
4266 ('symbol', 'date') 4266 (symbol 'date')
4267 ('string', 'UTC'))) 4267 (string 'UTC')))
4268 ('symbol', 'isodate')) 4268 (symbol 'isodate'))
4269 ('string', '\n')) 4269 (string '\n'))
4270 0:1e4e1b8f71e0 1970-01-12 13:46 +0000 4270 0:1e4e1b8f71e0 1970-01-12 13:46 +0000
4271 4271
4272 $ hg debugtemplate -vr0 '{status("A", file_adds)}' 4272 $ hg debugtemplate -vr0 '{status("A", file_adds)}'
4273 (template 4273 (template
4274 (func 4274 (func
4275 ('symbol', 'status') 4275 (symbol 'status')
4276 (list 4276 (list
4277 ('string', 'A') 4277 (string 'A')
4278 ('symbol', 'file_adds')))) 4278 (symbol 'file_adds'))))
4279 * expanded: 4279 * expanded:
4280 (template 4280 (template
4281 (% 4281 (%
4282 ('symbol', 'file_adds') 4282 (symbol 'file_adds')
4283 (template 4283 (template
4284 ('string', 'A') 4284 (string 'A')
4285 ('string', ' ') 4285 (string ' ')
4286 ('symbol', 'file') 4286 (symbol 'file')
4287 ('string', '\n')))) 4287 (string '\n'))))
4288 A a 4288 A a
4289 4289
4290 A unary function alias can be called as a filter: 4290 A unary function alias can be called as a filter:
4291 4291
4292 $ hg debugtemplate -vr0 '{date|utcdate|isodate}\n' 4292 $ hg debugtemplate -vr0 '{date|utcdate|isodate}\n'
4293 (template 4293 (template
4294 (| 4294 (|
4295 (| 4295 (|
4296 ('symbol', 'date') 4296 (symbol 'date')
4297 ('symbol', 'utcdate')) 4297 (symbol 'utcdate'))
4298 ('symbol', 'isodate')) 4298 (symbol 'isodate'))
4299 ('string', '\n')) 4299 (string '\n'))
4300 * expanded: 4300 * expanded:
4301 (template 4301 (template
4302 (| 4302 (|
4303 (func 4303 (func
4304 ('symbol', 'localdate') 4304 (symbol 'localdate')
4305 (list 4305 (list
4306 ('symbol', 'date') 4306 (symbol 'date')
4307 ('string', 'UTC'))) 4307 (string 'UTC')))
4308 ('symbol', 'isodate')) 4308 (symbol 'isodate'))
4309 ('string', '\n')) 4309 (string '\n'))
4310 1970-01-12 13:46 +0000 4310 1970-01-12 13:46 +0000
4311 4311
4312 Aliases should be applied only to command arguments and templates in hgrc. 4312 Aliases should be applied only to command arguments and templates in hgrc.
4313 Otherwise, our stock styles and web templates could be corrupted: 4313 Otherwise, our stock styles and web templates could be corrupted:
4314 4314
4339 4339
4340 Unparsable alias: 4340 Unparsable alias:
4341 4341
4342 $ hg debugtemplate --config templatealias.bad='x(' -v '{bad}' 4342 $ hg debugtemplate --config templatealias.bad='x(' -v '{bad}'
4343 (template 4343 (template
4344 ('symbol', 'bad')) 4344 (symbol 'bad'))
4345 abort: bad definition of template alias "bad": at 2: not a prefix: end 4345 abort: bad definition of template alias "bad": at 2: not a prefix: end
4346 [255] 4346 [255]
4347 $ hg log --config templatealias.bad='x(' -T '{bad}' 4347 $ hg log --config templatealias.bad='x(' -T '{bad}'
4348 abort: bad definition of template alias "bad": at 2: not a prefix: end 4348 abort: bad definition of template alias "bad": at 2: not a prefix: end
4349 [255] 4349 [255]