[Space Lua] Fix: math.tointeger coerces strings like Lua; fix test

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
This commit is contained in:
Matouš Jan Fialka
2026-02-20 15:25:24 +01:00
parent c3b747b0d5
commit ef7b128793
2 changed files with 18 additions and 12 deletions
+7 -2
View File
@@ -189,8 +189,13 @@ do
assertEquals(math.tointeger(3.5), nil, "tointeger(3.5)")
assertEquals(math.tointeger(-0.1), nil, "tointeger(-0.1)")
-- non-numbers yields nil (no error)
assertEquals(math.tointeger("3"), nil, "tointeger(string)")
-- string coercion: integer-valued string yields integer
assertEquals(math.tointeger("3"), 3, "tointeger(string int)")
assertEquals(math.tointeger("3.0"), 3, "tointeger(string float whole)")
assertEquals(math.tointeger("3.5"), nil, "tointeger(string float frac)")
assertEquals(math.tointeger("x"), nil, "tointeger(non-numeric string)")
-- nil yields nil
assertEquals(math.tointeger(nil), nil, "tointeger(nil)")
-- inf and nan yields nil