Skip to content

Commit

Permalink
prettify code
Browse files Browse the repository at this point in the history
  • Loading branch information
EvandroLG committed Feb 5, 2023
1 parent 61691d3 commit cd9ad83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/simple_test/assertions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ local assertions = {
method(table.unpack(params))
end, function(err)
raised_error = err

if not raised_pattern or string.find(err, raised_pattern) then
matched = true
end
end)

if not raised_error then error(msg or 'should throw error') end
if not raised_error then
error(msg or 'should throw error')
end

if not matched then
error(format("threw error '%s' but did not contain pattern '%s'",
raised_error, raised_pattern))
error(
format("threw error '%s' but did not contain pattern '%s'", raised_error, raised_pattern)
)
end
end,

Expand Down
16 changes: 8 additions & 8 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,37 @@ test('assert.not_ok', function(a)
end)

test('assert.throw (no pattern)', function(a)
local method = function(a, b)
assert(a == b, 'invalid!')
local method = function(first, last)
assert(first == last, 'invalid!')
end

a.throw(method, { 'a', 'b' })
end)

test('assert.throw (with pattern)', function(a)
local method = function(a, b)
assert(a == b, 'invalid!')
local method = function(first, last)
assert(first == last, 'invalid!')
end

a.throw(method, { 'a', 'b' }, 'invalid!')
end)

test('assert.throw (pattern not matched)', function(a)
local method = function(a, b)
assert(a == b, 'invalid!')
local method = function(first, last)
assert(first == last, 'invalid!')
end

a.throw(method, { 'a', 'b' }, 'foo')
end, true)

test('assert.throw (does not throw)', function(a)
local method = function(a, b) end
local method = function(_, _) end

a.throw(method, { 'a', 'b' })
end, true)

test('assert.throw (does not throw but still has pattern arg)', function(a)
local method = function(a, b) end
local method = function(_, _) end

a.throw(method, { 'a', 'b' }, "foo")
end, true)
Expand Down

0 comments on commit cd9ad83

Please sign in to comment.