diff options
author | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
---|---|---|
committer | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
commit | 5c4fc93d5f4137bf4c22ddf1a048c907a4a26727 (patch) | |
tree | a9a68e1f6a9c3bfe2b64fa1c3a4098865b7d3b5d /test/ltn12test.lua | |
parent | ccef3bc4e2aa6ee5b997a80aabb58f4ff0b0e98f (diff) | |
parent | 43a97b7f0053313b43906371dbdc226271e6c8ab (diff) | |
download | luasocket-hjelmeland-patch-1.tar.gz luasocket-hjelmeland-patch-1.tar.bz2 luasocket-hjelmeland-patch-1.zip |
Merge branch 'master' into hjelmeland-patch-1hjelmeland-patch-1
Diffstat (limited to 'test/ltn12test.lua')
-rw-r--r-- | test/ltn12test.lua | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/test/ltn12test.lua b/test/ltn12test.lua index e3f85fb..0cafbc9 100644 --- a/test/ltn12test.lua +++ b/test/ltn12test.lua | |||
@@ -38,7 +38,7 @@ local function named(f, name) | |||
38 | end | 38 | end |
39 | 39 | ||
40 | -------------------------------- | 40 | -------------------------------- |
41 | local function split(size) | 41 | local function split(size) |
42 | local buffer = "" | 42 | local buffer = "" |
43 | local last_out = "" | 43 | local last_out = "" |
44 | local last_in = "" | 44 | local last_in = "" |
@@ -50,12 +50,12 @@ local function split(size) | |||
50 | return last_out | 50 | return last_out |
51 | end | 51 | end |
52 | return function(chunk, done) | 52 | return function(chunk, done) |
53 | if done then | 53 | if done then |
54 | return not last_in and not last_out | 54 | return not last_in and not last_out |
55 | end | 55 | end |
56 | -- check if argument is consistent with state | 56 | -- check if argument is consistent with state |
57 | if not chunk then | 57 | if not chunk then |
58 | if last_in and last_in ~= "" and last_out ~= "" then | 58 | if last_in and last_in ~= "" and last_out ~= "" then |
59 | error("nil chunk following data chunk", 2) | 59 | error("nil chunk following data chunk", 2) |
60 | end | 60 | end |
61 | if not last_out then error("extra nil chunk", 2) end | 61 | if not last_out then error("extra nil chunk", 2) end |
@@ -67,8 +67,8 @@ local function split(size) | |||
67 | return output(chunk) | 67 | return output(chunk) |
68 | else | 68 | else |
69 | if not last_in then error("data chunk following nil chunk", 2) end | 69 | if not last_in then error("data chunk following nil chunk", 2) end |
70 | if last_in ~= "" and last_out ~= "" then | 70 | if last_in ~= "" and last_out ~= "" then |
71 | error("data chunk following data chunk", 2) | 71 | error("data chunk following data chunk", 2) |
72 | end | 72 | end |
73 | buffer = chunk | 73 | buffer = chunk |
74 | return output(chunk) | 74 | return output(chunk) |
@@ -85,7 +85,7 @@ local function format(chunk) | |||
85 | end | 85 | end |
86 | 86 | ||
87 | -------------------------------- | 87 | -------------------------------- |
88 | local function merge(size) | 88 | local function merge(size) |
89 | local buffer = "" | 89 | local buffer = "" |
90 | local last_out = "" | 90 | local last_out = "" |
91 | local last_in = "" | 91 | local last_in = "" |
@@ -102,12 +102,12 @@ local function merge(size) | |||
102 | return last_out | 102 | return last_out |
103 | end | 103 | end |
104 | return function(chunk, done) | 104 | return function(chunk, done) |
105 | if done then | 105 | if done then |
106 | return not last_in and not last_out | 106 | return not last_in and not last_out |
107 | end | 107 | end |
108 | -- check if argument is consistent with state | 108 | -- check if argument is consistent with state |
109 | if not chunk then | 109 | if not chunk then |
110 | if last_in and last_in ~= "" and last_out ~= "" then | 110 | if last_in and last_in ~= "" and last_out ~= "" then |
111 | error("nil chunk following data chunk", 2) | 111 | error("nil chunk following data chunk", 2) |
112 | end | 112 | end |
113 | if not last_out then error("extra nil chunk", 2) end | 113 | if not last_out then error("extra nil chunk", 2) end |
@@ -119,8 +119,8 @@ local function merge(size) | |||
119 | return output(chunk) | 119 | return output(chunk) |
120 | else | 120 | else |
121 | if not last_in then error("data chunk following nil chunk", 2) end | 121 | if not last_in then error("data chunk following nil chunk", 2) end |
122 | if last_in ~= "" and last_out ~= "" then | 122 | if last_in ~= "" and last_out ~= "" then |
123 | error("data chunk following data chunk", 2) | 123 | error("data chunk following data chunk", 2) |
124 | end | 124 | end |
125 | buffer = buffer .. chunk | 125 | buffer = buffer .. chunk |
126 | return output(chunk) | 126 | return output(chunk) |
@@ -181,6 +181,15 @@ assert(table.concat(t) == s, "mismatch") | |||
181 | print("ok") | 181 | print("ok") |
182 | 182 | ||
183 | -------------------------------- | 183 | -------------------------------- |
184 | io.write("testing source.table: ") | ||
185 | local inp = {'a','b','c','d','e'} | ||
186 | local source = ltn12.source.table(inp) | ||
187 | sink, t = ltn12.sink.table() | ||
188 | assert(ltn12.pump.all(source, sink), "returned error") | ||
189 | for i = 1, #inp do assert(t[i] == inp[i], "mismatch") end | ||
190 | print("ok") | ||
191 | |||
192 | -------------------------------- | ||
184 | io.write("testing source.chain (with split): ") | 193 | io.write("testing source.chain (with split): ") |
185 | source = ltn12.source.string(s) | 194 | source = ltn12.source.string(s) |
186 | filter = split(5) | 195 | filter = split(5) |