aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2024-05-23 00:29:26 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2024-05-23 00:29:26 +0200
commitb3cd71ddf2bbadb63fa4dc4ef1147b5c4ae95994 (patch)
tree28224f6af3253f0ca9ee6b17980e4dc24b907cba
parente1a8aede05d3217882cf2de426f0a87a659e4308 (diff)
downloadluasystem-b3cd71ddf2bbadb63fa4dc4ef1147b5c4ae95994.tar.gz
luasystem-b3cd71ddf2bbadb63fa4dc4ef1147b5c4ae95994.tar.bz2
luasystem-b3cd71ddf2bbadb63fa4dc4ef1147b5c4ae95994.zip
add final (failing for now) tests, to be fixed
-rw-r--r--spec/04-term_spec.lua95
1 files changed, 91 insertions, 4 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua
index 3dc4660..c5b91e6 100644
--- a/spec/04-term_spec.lua
+++ b/spec/04-term_spec.lua
@@ -174,18 +174,97 @@ describe("Terminal:", function()
174 174
175 175
176 176
177 pending("tcgetattr()", function() 177 describe("tcgetattr()", function()
178 178
179 pending("sets the consoleflags, if called with flags", function() 179 pending("gets the terminal flags", function()
180 end)
181
182
183 win_it("gets the terminal flags, always 0", function()
184 local flags, err = system.tcgetattr(io.stdin)
185 assert.is_nil(err)
186 assert.is_table(flags)
187 assert.equals("bitflags:", tostring(flags.iflag):sub(1,9))
188 assert.equals("bitflags:", tostring(flags.oflag):sub(1,9))
189 assert.equals("bitflags:", tostring(flags.lflag):sub(1,9))
190 assert.equals("bitflags:", tostring(flags.cflag):sub(1,9))
191 assert.equals(0, flags.iflag:value())
192 assert.equals(0, flags.oflag:value())
193 assert.equals(0, flags.lflag:value())
194 assert.equals(0, flags.cflag:value())
195 assert.same({}, flags.cc)
196 end)
197
198
199 it("returns an error if called with an invalid argument", function()
200 assert.has.error(function()
201 system.tcgetattr("invalid")
202 end, "bad argument #1 to 'tcgetattr' (FILE* expected, got string)")
180 end) 203 end)
181 204
182 end) 205 end)
183 206
184 207
185 208
186 pending("tcsetattr()", function() 209 describe("tcsetattr()", function()
210
211 nix_it("sets the terminal flags, if called with flags", function()
212 assert.equal(true, false)
213 end)
214
215
216 win_it("sets the terminal flags, if called with flags, always succeeds", function()
217 local success, err = system.tcsetattr(io.stdin, system.TCSANOW, system.tcgetattr(io.stdin))
218 assert.is_nil(err)
219 assert.is_true(success)
220 end)
221
222
223 it("returns an error if called with an invalid first argument", function()
224 assert.has.error(function()
225 system.tcsetattr("invalid")
226 end, "bad argument #1 to 'tcsetattr' (FILE* expected, got string)")
227 end)
228
229
230 it("returns an error if called with an invalid second argument", function()
231 assert.has.error(function()
232 system.tcsetattr(io.stdin, "invalid")
233 end, "bad argument #2 to 'tcsetattr' (number expected, got string)")
234 end)
235
236
237 it("returns an error if called with an invalid third argument", function()
238 assert.has.error(function()
239 system.tcsetattr(io.stdin, system.TCSANOW, "invalid")
240 end, "bad argument #3 to 'tcsetattr' (table expected, got string)")
241 end)
242
243
244 it("returns an error if iflag is not a bitflags object", function()
245 local flags = assert(system.tcgetattr(io.stdin))
246 flags.iflag = 0
247 assert.has.error(function()
248 system.tcsetattr(io.stdin, system.TCSANOW, flags)
249 end, "bad argument #3 to 'tcsetattr' (table expected, got number)")
250 end)
251
252
253 it("returns an error if oflag is not a bitflags object", function()
254 local flags = assert(system.tcgetattr(io.stdin))
255 flags.oflag = 0
256 assert.has.error(function()
257 system.tcsetattr(io.stdin, system.TCSANOW, flags)
258 end, "bad argument #3 to 'tcsetattr' (table expected, got number)")
259 end)
260
187 261
188 pending("sets the consoleflags, if called with flags", function() 262 it("returns an error if lflag is not a bitflags object", function()
263 local flags = assert(system.tcgetattr(io.stdin))
264 flags.lflag = 0
265 assert.has.error(function()
266 system.tcsetattr(io.stdin, system.TCSANOW, flags)
267 end, "bad argument #3 to 'tcsetattr' (table expected, got number)")
189 end) 268 end)
190 269
191 end) 270 end)
@@ -314,12 +393,20 @@ describe("Terminal:", function()
314 assert.is_boolean(nb) 393 assert.is_boolean(nb)
315 end) 394 end)
316 395
396
317 win_it("gets the non-blocking flag, always false", function() 397 win_it("gets the non-blocking flag, always false", function()
318 local nb, err = system.getnonblock(io.stdin) 398 local nb, err = system.getnonblock(io.stdin)
319 assert.is_nil(err) 399 assert.is_nil(err)
320 assert.is_false(nb) 400 assert.is_false(nb)
321 end) 401 end)
322 402
403
404 it("returns an error if called with an invalid argument", function()
405 assert.has.error(function()
406 system.getnonblock("invalid")
407 end, "bad argument #1 to 'getnonblock' (FILE* expected, got string)")
408 end)
409
323 end) 410 end)
324 411
325 412