support multiple filters in ltn12.{sink,source}.chain()
This commit is contained in:
parent
22cd5833fc
commit
480a818bf0
2 changed files with 35 additions and 3 deletions
|
@ -191,6 +191,21 @@ assert(table.concat(t) == s, "mismatch")
|
|||
assert(filter(nil, 1), "filter not empty")
|
||||
print("ok")
|
||||
|
||||
--------------------------------
|
||||
io.write("testing source.chain (with several filters): ")
|
||||
local function double(x) -- filter turning "ABC" into "AABBCC"
|
||||
if not x then return end
|
||||
local b={}
|
||||
for k in x:gmatch'.' do table.insert(b, k..k) end
|
||||
return table.concat(b)
|
||||
end
|
||||
source = ltn12.source.string(s)
|
||||
source = ltn12.source.chain(source, double, double, double)
|
||||
sink, t = ltn12.sink.table()
|
||||
assert(ltn12.pump.all(source, sink), "returned error")
|
||||
assert(table.concat(t) == double(double(double(s))), "mismatch")
|
||||
print("ok")
|
||||
|
||||
--------------------------------
|
||||
io.write("testing source.chain (with split) and sink.chain (with merge): ")
|
||||
source = ltn12.source.string(s)
|
||||
|
@ -205,6 +220,15 @@ assert(filter(nil, 1), "filter not empty")
|
|||
assert(filter2(nil, 1), "filter2 not empty")
|
||||
print("ok")
|
||||
|
||||
--------------------------------
|
||||
io.write("testing sink.chain (with several filters): ")
|
||||
source = ltn12.source.string(s)
|
||||
sink, t = ltn12.sink.table()
|
||||
sink = ltn12.sink.chain(double, double, double, sink)
|
||||
assert(ltn12.pump.all(source, sink), "returned error")
|
||||
assert(table.concat(t) == double(double(double(s))), "mismatch")
|
||||
print("ok")
|
||||
|
||||
--------------------------------
|
||||
io.write("testing filter.chain (and sink.chain, with split, merge): ")
|
||||
source = ltn12.source.string(s)
|
||||
|
@ -272,3 +296,4 @@ assert(filter3(nil, 1), "filter3 not empty")
|
|||
assert(filter4(nil, 1), "filter4 not empty")
|
||||
assert(filter5(nil, 1), "filter5 not empty")
|
||||
print("ok")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue