aboutsummaryrefslogtreecommitdiff
path: root/test/ltn12test.lua
diff options
context:
space:
mode:
authorCaleb Maclennan <caleb@alerque.com>2023-11-10 09:12:04 +0300
committerCaleb Maclennan <caleb@alerque.com>2023-11-10 09:12:04 +0300
commit5c4fc93d5f4137bf4c22ddf1a048c907a4a26727 (patch)
treea9a68e1f6a9c3bfe2b64fa1c3a4098865b7d3b5d /test/ltn12test.lua
parentccef3bc4e2aa6ee5b997a80aabb58f4ff0b0e98f (diff)
parent43a97b7f0053313b43906371dbdc226271e6c8ab (diff)
downloadluasocket-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.lua33
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)
38end 38end
39 39
40-------------------------------- 40--------------------------------
41local function split(size) 41local 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)
85end 85end
86 86
87-------------------------------- 87--------------------------------
88local function merge(size) 88local 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")
181print("ok") 181print("ok")
182 182
183-------------------------------- 183--------------------------------
184io.write("testing source.table: ")
185local inp = {'a','b','c','d','e'}
186local source = ltn12.source.table(inp)
187sink, t = ltn12.sink.table()
188assert(ltn12.pump.all(source, sink), "returned error")
189for i = 1, #inp do assert(t[i] == inp[i], "mismatch") end
190print("ok")
191
192--------------------------------
184io.write("testing source.chain (with split): ") 193io.write("testing source.chain (with split): ")
185source = ltn12.source.string(s) 194source = ltn12.source.string(s)
186filter = split(5) 195filter = split(5)