diff options
-rw-r--r-- | spec/04-term_spec.lua | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua index b6e0daf..ba58fde 100644 --- a/spec/04-term_spec.lua +++ b/spec/04-term_spec.lua | |||
@@ -404,7 +404,65 @@ describe("Terminal:", function() | |||
404 | 404 | ||
405 | 405 | ||
406 | 406 | ||
407 | pending("termwrap()", function() | 407 | describe("termwrap()", function() |
408 | |||
409 | local old_backup | ||
410 | local old_restore | ||
411 | local result | ||
412 | |||
413 | setup(function() | ||
414 | old_backup = system.termbackup | ||
415 | old_restore = system.termrestore | ||
416 | system.termbackup = function() | ||
417 | table.insert(result,"backup") | ||
418 | end | ||
419 | |||
420 | system.termrestore = function() | ||
421 | table.insert(result,"restore") | ||
422 | end | ||
423 | end) | ||
424 | |||
425 | |||
426 | before_each(function() | ||
427 | result = {} | ||
428 | end) | ||
429 | |||
430 | |||
431 | teardown(function() | ||
432 | system.termbackup = old_backup | ||
433 | system.termrestore = old_restore | ||
434 | end) | ||
435 | |||
436 | |||
437 | |||
438 | it("calls both backup and restore", function() | ||
439 | system.termwrap(function() | ||
440 | table.insert(result,"wrapped") | ||
441 | end)() | ||
442 | |||
443 | assert.are.same({"backup", "wrapped", "restore"}, result) | ||
444 | end) | ||
445 | |||
446 | |||
447 | it("passes all args", function() | ||
448 | system.termwrap(function(...) | ||
449 | table.insert(result,{...}) | ||
450 | end)(1, 2, 3) | ||
451 | |||
452 | assert.are.same({"backup", {1,2,3}, "restore"}, result) | ||
453 | end) | ||
454 | |||
455 | |||
456 | it("returns all results", function() | ||
457 | local a, b, c = system.termwrap(function(...) | ||
458 | return 1, nil, 3 -- ensure nil is passed as well | ||
459 | end)() | ||
460 | |||
461 | assert.are.same({"backup", "restore"}, result) | ||
462 | assert.equals(1, a) | ||
463 | assert.is_nil(b) | ||
464 | assert.equals(3, c) | ||
465 | end) | ||
408 | 466 | ||
409 | end) | 467 | end) |
410 | 468 | ||