Skip to content

Commit

Permalink
Added conflict test to unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
FPtje committed Dec 13, 2015
1 parent 0624b0c commit 318d725
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions gamemode/libraries/tablecheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,26 @@ function unitTests()
checkCorrect(withDefaultNoCheck({}))
checkCorrect(withDefaultNoCheck({value = "string"}))

--[[
Creating your own checker function that returns an error message
When both the function and the tc.assert define error messages, there's a conflict
]]
local function customCheck(val)
return false, "function error message", {"function hint"}
end

local customCheckSchema = tc.assertTable{
value = tc.assert(customCheck, "conflicting error message", {"conflicting hint"})
}
checkIncorrect(customCheckSchema{value = 1})
checkIncorrect(customCheckSchema{})

_, err, hints = customCheckSchema{value = 2}
if err ~= "function error message" or hints[1] ~= "function hint" then
print("Wrong conflict solution", err, hints[1])
else
print("Conflict solution OK!")
end

print("finished")
end

0 comments on commit 318d725

Please sign in to comment.