diff options
author | Fabien Fleutot <fleutot@gmail.com> | 2013-06-18 11:01:46 +0200 |
---|---|---|
committer | Fabien Fleutot <fleutot@gmail.com> | 2013-06-18 11:01:46 +0200 |
commit | 480a818bf0ef6de32527ba14fc2bb27e754d0612 (patch) | |
tree | 303513720855c252cad00d03fc17a012752f0f67 /test | |
parent | 22cd5833fcc0e272f26004a79c8545e959ba406b (diff) | |
download | luasocket-480a818bf0ef6de32527ba14fc2bb27e754d0612.tar.gz luasocket-480a818bf0ef6de32527ba14fc2bb27e754d0612.tar.bz2 luasocket-480a818bf0ef6de32527ba14fc2bb27e754d0612.zip |
support multiple filters in ltn12.{sink,source}.chain()
Diffstat (limited to 'test')
-rw-r--r-- | test/ltn12test.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ltn12test.lua b/test/ltn12test.lua index 74a45e8..e3f85fb 100644 --- a/test/ltn12test.lua +++ b/test/ltn12test.lua | |||
@@ -192,6 +192,21 @@ assert(filter(nil, 1), "filter not empty") | |||
192 | print("ok") | 192 | print("ok") |
193 | 193 | ||
194 | -------------------------------- | 194 | -------------------------------- |
195 | io.write("testing source.chain (with several filters): ") | ||
196 | local function double(x) -- filter turning "ABC" into "AABBCC" | ||
197 | if not x then return end | ||
198 | local b={} | ||
199 | for k in x:gmatch'.' do table.insert(b, k..k) end | ||
200 | return table.concat(b) | ||
201 | end | ||
202 | source = ltn12.source.string(s) | ||
203 | source = ltn12.source.chain(source, double, double, double) | ||
204 | sink, t = ltn12.sink.table() | ||
205 | assert(ltn12.pump.all(source, sink), "returned error") | ||
206 | assert(table.concat(t) == double(double(double(s))), "mismatch") | ||
207 | print("ok") | ||
208 | |||
209 | -------------------------------- | ||
195 | io.write("testing source.chain (with split) and sink.chain (with merge): ") | 210 | io.write("testing source.chain (with split) and sink.chain (with merge): ") |
196 | source = ltn12.source.string(s) | 211 | source = ltn12.source.string(s) |
197 | filter = split(5) | 212 | filter = split(5) |
@@ -206,6 +221,15 @@ assert(filter2(nil, 1), "filter2 not empty") | |||
206 | print("ok") | 221 | print("ok") |
207 | 222 | ||
208 | -------------------------------- | 223 | -------------------------------- |
224 | io.write("testing sink.chain (with several filters): ") | ||
225 | source = ltn12.source.string(s) | ||
226 | sink, t = ltn12.sink.table() | ||
227 | sink = ltn12.sink.chain(double, double, double, sink) | ||
228 | assert(ltn12.pump.all(source, sink), "returned error") | ||
229 | assert(table.concat(t) == double(double(double(s))), "mismatch") | ||
230 | print("ok") | ||
231 | |||
232 | -------------------------------- | ||
209 | io.write("testing filter.chain (and sink.chain, with split, merge): ") | 233 | io.write("testing filter.chain (and sink.chain, with split, merge): ") |
210 | source = ltn12.source.string(s) | 234 | source = ltn12.source.string(s) |
211 | filter = split(5) | 235 | filter = split(5) |
@@ -272,3 +296,4 @@ assert(filter3(nil, 1), "filter3 not empty") | |||
272 | assert(filter4(nil, 1), "filter4 not empty") | 296 | assert(filter4(nil, 1), "filter4 not empty") |
273 | assert(filter5(nil, 1), "filter5 not empty") | 297 | assert(filter5(nil, 1), "filter5 not empty") |
274 | print("ok") | 298 | print("ok") |
299 | |||