Commit 62bc457b authored by François Perrad's avatar François Perrad

fix when consecutive captures

parent 9d720b0d
Pipeline #156422 passed with stages
in 23 seconds
......@@ -246,7 +246,7 @@ local function match (s, ops)
c = s:sub(i, i)
if c == sep_var[oper] then
capture[varname] = unescape(s:sub(start, i-1), query)
if oper == '/' and not op[nvar+1] then
if (oper == '/' or oper == '.') and not op[nvar+1] then
break
else
nvar = nvar + 1
......
......@@ -18,7 +18,7 @@ local function kv_is (t, k, expected, name)
end
end
plan(195)
plan(221)
local ctor = require 'Silva.template'
......@@ -165,6 +165,17 @@ capture = sme('/foo.1024.')
kv_is( capture, 'x', '1024' )
kv_is( capture, 'y', '' )
sme = ctor'/foo{.x}{.y}'
capture = sme('/foo.1024.768')
kv_is( capture, 'x', '1024' )
kv_is( capture, 'y', '768' )
capture = sme('/foo.1024')
kv_is( capture, 'x', '1024' )
kv_is( capture, 'y', nil )
capture = sme('/foo.1024.')
kv_is( capture, 'x', '1024' )
kv_is( capture, 'y', '' )
sme = ctor'/foo{.x,y}bar'
capture = sme('/foo.1024.768bar')
kv_is( capture, 'x', '1024' )
......@@ -176,6 +187,17 @@ capture = sme('/foo.1024.bar')
kv_is( capture, 'x', '1024' )
kv_is( capture, 'y', '' )
sme = ctor'/foo{.x}{.y}bar'
capture = sme('/foo.1024.768bar')
kv_is( capture, 'x', '1024' )
kv_is( capture, 'y', '768' )
capture = sme('/foo.1024bar')
kv_is( capture, 'x', '1024' )
kv_is( capture, 'y', nil )
capture = sme('/foo.1024.bar')
kv_is( capture, 'x', '1024' )
kv_is( capture, 'y', '' )
sme = ctor'/foo{/var}'
capture = sme('/foo/bar')
kv_is( capture, 'var', 'bar' )
......@@ -201,6 +223,23 @@ capture = sme('/foo/123')
kv_is( capture, 'x', '' )
kv_is( capture, 'y', nil )
sme = ctor'/foo{/x}{/y}123'
capture = sme('/foo/bar/baz123')
kv_is( capture, 'x', 'bar' )
kv_is( capture, 'y', 'baz' )
capture = sme('/foo/bar123')
kv_is( capture, 'x', 'bar' )
kv_is( capture, 'y', nil )
capture = sme('/foo/bar/123')
kv_is( capture, 'x', 'bar' )
kv_is( capture, 'y', '' )
capture = sme('/foo123')
kv_is( capture, 'x', nil )
kv_is( capture, 'y', nil )
capture = sme('/foo/123')
kv_is( capture, 'x', '' )
kv_is( capture, 'y', nil )
sme = ctor'/foo{/var,x}/here'
capture = sme('/foo/bar/1024/here')
kv_is( capture, 'var', 'bar' )
......@@ -209,6 +248,14 @@ capture = sme('/foo/bar//here')
kv_is( capture, 'var', 'bar' )
kv_is( capture, 'x', '' )
sme = ctor'/foo{/var}{/x}/here'
capture = sme('/foo/bar/1024/here')
kv_is( capture, 'var', 'bar' )
kv_is( capture, 'x', '1024' )
capture = sme('/foo/bar//here')
kv_is( capture, 'var', 'bar' )
kv_is( capture, 'x', '' )
sme = ctor'/foo{;x,y}'
capture = sme('/foo;x=1024;y=768')
kv_is( capture, 'x', '1024' )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment