Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions spec/00-helpers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("Spec helpers", function()
it("returns bytes from the helper _readkey buffer", function()
helpers.load()

helpers._push_input("ab")
helpers.push_kb_input("ab")

local b1 = helpers._readkey()
local b2 = helpers._readkey()
Expand All @@ -99,7 +99,7 @@ describe("Spec helpers", function()
it("returns nil and error when pushing an error entry", function()
helpers.load()

helpers._push_input(nil, "some-error")
helpers.push_kb_input(nil, "some-error")

local b, err = helpers._readkey()
assert.is_nil(b)
Expand All @@ -110,7 +110,7 @@ describe("Spec helpers", function()
it("patches system._readkey to use the mock buffer", function()
helpers.load()

helpers._push_input("X")
helpers.push_kb_input("X")

local system = require("system")
local b = system._readkey()
Expand All @@ -122,7 +122,7 @@ describe("Spec helpers", function()
it("terminal.input.readansi() returns data read from the mock buffer", function()
local terminal = helpers.load()

helpers._push_input("X")
helpers.push_kb_input("X")

local rawkey, keytype = terminal.input.readansi(0.01)
assert.equals("X", rawkey)
Expand Down
54 changes: 13 additions & 41 deletions spec/02-input_spec.lua
Original file line number Diff line number Diff line change
@@ -1,42 +1,17 @@
describe("input:", function()

local t, sys, old_readkey
local keyboard_buffer

setup(function()
sys = require("system")

-- patch low level readkey, such that it won't block during tests
old_readkey = sys._readkey
sys._readkey = function()
if keyboard_buffer == "" then
return nil
end
local char = keyboard_buffer:sub(1, 1)
keyboard_buffer = keyboard_buffer:sub(2)
return string.byte(char)
end
end)
local helpers = require "spec.helpers"


teardown(function()
sys._readkey = old_readkey
end)
describe("input:", function()

local t

before_each(function()
keyboard_buffer = ""
t = require("terminal")
t = helpers.load()
end)


after_each(function()
-- forcefully unload module
for mod in pairs(package.loaded) do
if mod:match("^terminal") then
package.loaded[mod] = nil
end
end
helpers.unload()
end)


Expand All @@ -45,6 +20,7 @@ describe("input:", function()
describe("sys_readansi()", function()

it("matches system.readansi()", function()
local sys = require("system")
assert.are.equal(sys.readansi, t.input.sys_readansi)
end)

Expand All @@ -68,13 +44,13 @@ describe("input:", function()


it("reads a single character", function()
keyboard_buffer = "a"
helpers.push_kb_input("a")
assert.are.equal("a", t.input.readansi(0.01))
end)


it("reads from the buffer first", function()
keyboard_buffer = "a"
helpers.push_kb_input("a")
t.input.push_input("b", "key", nil)
assert.are.equal("b", t.input.readansi(0.01))
assert.are.equal("a", t.input.readansi(0.01))
Expand All @@ -87,10 +63,8 @@ describe("input:", function()
describe("preread()", function()

it("empties the keyboard-buffer into the preread-buffer", function()
keyboard_buffer = "abc"
helpers.push_kb_input("abc")
t.input.preread()
assert.are.equal("", keyboard_buffer)

assert.are.equal("a", t.input.readansi(0.01))
assert.are.equal("b", t.input.readansi(0.01))
assert.are.equal("c", t.input.readansi(0.01))
Expand All @@ -109,7 +83,7 @@ describe("input:", function()
setup(function()
-- returns an ANSWER sequence to the cursor-position query
add_cpos = function(row, col)
keyboard_buffer = keyboard_buffer .. ("\027[%d;%dR"):format(row, col)
helpers.push_kb_input(("\027[%d;%dR"):format(row, col))
end
cursor_answer_pattern = "^\27%[(%d+);(%d+)R$"
end)
Expand All @@ -124,11 +98,10 @@ describe("input:", function()


it("leaves other 'char' input in the buffers", function()
keyboard_buffer = "abc"
helpers.push_kb_input("abc")
add_cpos(12, 34)
keyboard_buffer = keyboard_buffer .. "123"
helpers.push_kb_input("123")
assert.are.same({{"12", "34"}}, t.input.read_query_answer(cursor_answer_pattern, 1))
assert.are.equal("123", keyboard_buffer)
assert.are.equal("a", t.input.readansi(0))
assert.are.equal("b", t.input.readansi(0))
assert.are.equal("c", t.input.readansi(0))
Expand All @@ -139,9 +112,8 @@ describe("input:", function()


it("leaves other 'ansi' input in the buffers", function()
keyboard_buffer = "\27[8;10;80t\027[12;34R\027[56;78R\027[90;12R"
helpers.push_kb_input("\27[8;10;80t\027[12;34R\027[56;78R\027[90;12R")
assert.are.same({{"12", "34"},{"56", "78"}}, t.input.read_query_answer(cursor_answer_pattern, 2))
assert.are.equal("\027[90;12R", keyboard_buffer)
local binstring = require("luassert.formatters.binarystring")
assert:add_formatter(binstring)
local r = {t.input.readansi(0)}
Expand Down
16 changes: 6 additions & 10 deletions spec/04-scroll_spec.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
local helpers = require "spec.helpers"


describe("Scroll Module Tests", function()

local scroll, old_sys_termsize
local scroll

setup(function()
local sys = require "system"
old_sys_termsize = sys.termsize
if os.getenv("GITHUB_ACTIONS") then
sys.termsize = function()
return 25, 80
end
end

helpers.load()
scroll = require "terminal.scroll"
end)


teardown(function()
require("system").termsize = old_sys_termsize
helpers.unload()
end)


Expand Down
11 changes: 7 additions & 4 deletions spec/09-editline-format_spec.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
local helpers = require "spec.helpers"


describe("EditLine:", function()

local EditLine

before_each(function()
_G._TEST = true
setup(function()
helpers.load()
EditLine = require("terminal.editline")
end)


after_each(function()
teardown(function()
EditLine = nil
_G._TEST = nil
helpers.unload()
end)


Expand Down
4 changes: 2 additions & 2 deletions spec/11-screen_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ describe("terminal.ui.screen", function()
local Panel
local terminal

before_each(function()
setup(function()
terminal = helpers.load()
Screen = require("terminal.ui.panel.screen")
Panel = require("terminal.ui.panel")
end)


after_each(function()
teardown(function()
helpers.unload()
end)

Expand Down
21 changes: 1 addition & 20 deletions spec/13-bar_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,15 @@ local helpers = require "spec.helpers"
describe("terminal.ui.panel.bar", function()

local Bar
local terminal

setup(function()
-- Load modules
terminal = helpers.load()
helpers.load()
Bar = require("terminal.ui.panel.bar")

-- Mock terminal functions for testing
terminal.cursor = {
position = {
set = function() end,
backup = function() end,
restore = function() end,
left_seq = function() return "" end,
down_seq = function() return "" end,
up_seq = function() return "" end
}
}
terminal.output = {
write = function() end
}
end)


teardown(function()
-- Unset modules for clean test isolation
Bar = nil
terminal = nil -- luacheck: ignore
helpers.unload()
end)

Expand Down
30 changes: 1 addition & 29 deletions spec/14-text_panel_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,16 @@ local helpers = require "spec.helpers"
describe("terminal.ui.panel.text", function()

local TextPanel
local terminal
local text

setup(function()
terminal = helpers.load()
helpers.load()
TextPanel = require("terminal.ui.panel.text")
text = require("terminal.text")

-- Mock terminal functions
terminal.cursor = {
position = {
set = function(row, col) end,
set_seq = function(row, col) return "pos_seq" end,
backup_seq = function() return "backup_seq" end,
restore_seq = function() return "restore_seq" end
}
}
terminal.output = {
write = function(text) end
}
terminal.text = {
stack = {
push_seq = function(attr) return "push_seq" end,
pop_seq = function() return "pop_seq" end
}
}
terminal.clear = {
box = function(row, col, height, width) end,
box_seq = function(row, col, height, width) return "clear_seq" end,
eol_seq = function() return "eol_seq" end
}
end)


teardown(function()
TextPanel = nil
terminal = nil -- luacheck: ignore
text = nil
helpers.unload()
end)

Expand Down
24 changes: 5 additions & 19 deletions spec/15-key_bar_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,18 @@ describe("terminal.ui.panel.key_bar", function()
local text

setup(function()
-- Load modules
terminal = helpers.load()
KeyBar = require("terminal.ui.panel.key_bar")
text = require("terminal.text")

-- Mock terminal functions for testing
terminal.cursor = {
position = {
set = function() end,
backup = function() end,
restore = function() end,
set_seq = function() return "" end,
backup_seq = function() return "" end,
restore_seq = function() return "" end,
}
}
terminal.output = {
write = function() end
}
end)


teardown(function()
-- Unset modules for clean test isolation
KeyBar = nil
terminal = nil -- luacheck: ignore
helpers.unload()
end)



describe("init()", function()

it("creates a key bar with default values", function()
Expand Down Expand Up @@ -96,6 +79,7 @@ describe("terminal.ui.panel.key_bar", function()
end)



describe("_build_lines()", function()

it("builds a single-row line with equal columns", function()
Expand Down Expand Up @@ -263,6 +247,7 @@ describe("terminal.ui.panel.key_bar", function()
end)



describe("render()", function()

it("calls _draw and respects panel inner coords", function()
Expand Down Expand Up @@ -299,6 +284,7 @@ describe("terminal.ui.panel.key_bar", function()
end)



describe("separator feature", function()

it("works correctly in two-row layout", function()
Expand Down
7 changes: 5 additions & 2 deletions spec/16-set_spec.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
local helpers = require "spec.helpers"


describe("terminal.ui.panel.set", function()

local Set
local Panel

setup(function()
helpers.load()
Set = require("terminal.ui.panel.set")
Panel = require("terminal.ui.panel.init")
end)


teardown(function()
Set = nil
Panel = nil -- luacheck: ignore
helpers.unload()
end)


Expand Down
Loading
Loading