Skip to content

Commit

Permalink
feat: added false value tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgagnidze committed May 31, 2023
1 parent 2befef0 commit 3e09359
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ena/interpreter.lua
Expand Up @@ -187,7 +187,11 @@ function Interpreter:run(code)
self.stack[self.top] = -self.stack[self.top]
elseif code[pc] == "not" then
self:traceUnaryOp(code[pc])
self.stack[self.top] = not self.stack[self.top]
if self.stack[self.top] == 0 then
self.stack[self.top] = true
else
self.stack[self.top] = not self.stack[self.top]
end
elseif code[pc] == "load" then
self:traceTwoCodes(code, pc)
self.top = self.top + 1
Expand Down
27 changes: 27 additions & 0 deletions ena/spec/e2e.lua
Expand Up @@ -534,4 +534,31 @@ function module:testFunctionOrdering()
)
end

function module:testFalseValues()
lu.assertEquals(
self:endToEnd(
[[
function a() {
if !false {
return 1
}
}
function main() {
if !0 {
return a() + b()
}
}
function b() {
if !nil {
return 2
}
}
]]
),
3
)
end

return module

0 comments on commit 3e09359

Please sign in to comment.