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
2 changes: 1 addition & 1 deletion src/model/input/userInputModel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ end
function UserInputModel:set_error(errors)
self.error = nil
if type(errors) == "table" then
if type(errors[1] == "string") then
if type(errors[1]) == "string" then
self.error = errors
else
self.error = {}
Expand Down
2 changes: 1 addition & 1 deletion src/model/lang/md/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ local function parse(input, skip_posinfo)
end

local function is_lua_block(t)
if not type(t) == "table" then return false end
if type(t) ~= "table" then return false end
return t.t == 'code_block' and t.lang == 'lua'
end

Expand Down
6 changes: 3 additions & 3 deletions src/util/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ end
--- @param self table
--- @return boolean is_array
function table.is_array(self)
if not self or not type(self) == "table" then
if not self or type(self) ~= "table" then
return false
end
local is_array = true
Expand All @@ -215,7 +215,7 @@ end
--- @param depth integer?
--- @return table?
function table.flatten(self, depth)
if not self or not type(self) == "table" then
if not self or type(self) ~= "table" then
return
end
local d = depth or 1
Expand All @@ -236,7 +236,7 @@ end
--- @param self table
--- @return table?
function table.odds(self)
if not self or not type(self) == "table" then
if not self or type(self) ~= "table" then
return
end
local ret = {}
Expand Down
10 changes: 10 additions & 0 deletions tests/input/user_input_model_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ describe("input model spec #input", function()
-----------------
-- ASCII --
-----------------
describe('errors', function()
it('converts non-string errors', function()
local model = UserInputModel(mockConf, luaEval)
--- @diagnostic disable-next-line: invisible
model:set_error({ 42 })
--- @diagnostic disable-next-line: invisible
assert.same({ '42' }, model.error)
end)
end)

describe('basics', function()
local model = UserInputModel(mockConf, luaEval)

Expand Down
8 changes: 8 additions & 0 deletions tests/util/table_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('table utils #table', function()
assert.is_false(table.is_array(t3))
assert.is_false(table.is_array(t4))
end)
it('rejects non-tables', function()
assert.is_false(table.is_array('str'))
assert.is_false(table.is_array(42))
end)
end)

describe('odds', function()
Expand All @@ -26,6 +30,10 @@ describe('table utils #table', function()
end)

describe('flatten', function()
it('rejects non-tables', function()
assert.is_nil(table.flatten(42))
end)

it('one deep', function()
assert.same({}, table.flatten({}))

Expand Down
Loading