diff --git a/client/space_lua/arithmetic_test.lua b/client/space_lua/arithmetic_test.lua index 0ac06b34..e576cbc8 100644 --- a/client/space_lua/arithmetic_test.lua +++ b/client/space_lua/arithmetic_test.lua @@ -1,4 +1,4 @@ -local function assert_eq(actual, expected, message) +local function assertEquals(actual, expected, message) if actual ~= expected then error('Assertion failed: ' .. message) end @@ -25,29 +25,29 @@ end -- 1. Integer vs float zero divisors -- 1.1. Integer zeros collapse (no -0 for integers) -assert_eq(1/0 == 1/-0, true, 'int: 1/0 == 1/-0 (+Inf)') -assert_eq(-1/0 == 1/-0, false, 'int: -1/0 != 1/-0') +assertEquals(1/0 == 1/-0, true, 'int: 1/0 == 1/-0 (+Inf)') +assertEquals(-1/0 == 1/-0, false, 'int: -1/0 != 1/-0') -- 1.2. Float zeros sign preservation -assert_eq(1/0.0 == 1/-0.0, false, 'float: +Inf != -Inf') -assert_eq(1/0.0 == -1/-0.0, true, 'float: 1/0.0 == -1/-0.0') -assert_eq(-1/0.0 == 1/-0.0, true, 'float: -1/0.0 == 1/-0.0') +assertEquals(1/0.0 == 1/-0.0, false, 'float: +Inf != -Inf') +assertEquals(1/0.0 == -1/-0.0, true, 'float: 1/0.0 == -1/-0.0') +assertEquals(-1/0.0 == 1/-0.0, true, 'float: -1/0.0 == 1/-0.0') -- 1.3. Basic division -assert_eq(5/2, 2.5, 'div: 5/2 == 2.5') -assert_eq(-5/2, -2.5, 'div: -5/2 == -2.5') -assert_eq(5/-2, -2.5, 'div: 5/-2 == -2.5') -assert_eq(-5/-2, 2.5, 'div: -5/-2 == 2.5') +assertEquals(5/2, 2.5, 'div: 5/2 == 2.5') +assertEquals(-5/2, -2.5, 'div: -5/2 == -2.5') +assertEquals(5/-2, -2.5, 'div: 5/-2 == -2.5') +assertEquals(-5/-2, 2.5, 'div: -5/-2 == 2.5') -- 2. Unary minus literals and simple expressions -assert_eq(1/-(0) == 1/0, true, 'unary minus: int literal (+Inf)') -assert_eq(1/-(0.0) == -1/0.0, true, 'unary minus: float literal (-Inf)') -assert_eq(1/-(1-1) == 1/0, true, 'unary minus: int expr (+Inf)') -assert_eq(1/-(1.0-1.0) == -1/0.0, true, 'unary minus: float expr (-Inf)') +assertEquals(1/-(0) == 1/0, true, 'unary minus: int literal (+Inf)') +assertEquals(1/-(0.0) == -1/0.0, true, 'unary minus: float literal (-Inf)') +assertEquals(1/-(1-1) == 1/0, true, 'unary minus: int expr (+Inf)') +assertEquals(1/-(1.0-1.0) == -1/0.0, true, 'unary minus: float expr (-Inf)') -- 2.1. Unary minus coercion and precedence with power -assert_eq(-2^2, -4, 'precedence: -2^2 == -(2^2)') -assert_eq((-2)^2, 4, 'precedence: (-2)^2 == 4') +assertEquals(-2^2, -4, 'precedence: -2^2 == -(2^2)') +assertEquals((-2)^2, 4, 'precedence: (-2)^2 == 4') -- 2.1.1. Unary minus with float-typed exponentiation results do @@ -55,104 +55,104 @@ do return math.type(x) end - assert_eq(mt(-("1.0" ^ 1)), "float", "math.type(-('1.0'^1)) => float") - assert_eq(mt(-"1.0" ^ 1), "float", "math.type(-'1.0'^1) => float") - assert_eq(mt(-("2.0" ^ 1)), "float", "math.type(-('2.0'^1)) => float") - assert_eq(mt(-("2.0" ^ 2)), "float", "math.type(-('2.0'^2)) => float") + assertEquals(mt(-("1.0" ^ 1)), "float", "math.type(-('1.0'^1)) => float") + assertEquals(mt(-"1.0" ^ 1), "float", "math.type(-'1.0'^1) => float") + assertEquals(mt(-("2.0" ^ 1)), "float", "math.type(-('2.0'^1)) => float") + assertEquals(mt(-("2.0" ^ 2)), "float", "math.type(-('2.0'^2)) => float") end -- 2.2. Unary minus uses table metadata for dynamic keys local dyn_tbl = {} local dyn_key = 'zf' dyn_tbl[dyn_key] = 0.0 -assert_eq(1/-(dyn_tbl[dyn_key]) == -1/0.0, true, 'unary minus: table dyn key float (-Inf)') +assertEquals(1/-(dyn_tbl[dyn_key]) == -1/0.0, true, 'unary minus: table dyn key float (-Inf)') -- 2.3. Unary minus uses table metadata for property access local prop_tbl = { zf = 0.0, zi = 0 } -assert_eq(1/-(prop_tbl.zf) == -1/0.0, true, 'unary minus: table prop float (-Inf)') -assert_eq(1/-(prop_tbl.zi) == 1/0, true, 'unary minus: table prop int (+Inf)') +assertEquals(1/-(prop_tbl.zf) == -1/0.0, true, 'unary minus: table prop float (-Inf)') +assertEquals(1/-(prop_tbl.zi) == 1/0, true, 'unary minus: table prop int (+Inf)') -- 2.4. Unary minus uses env metadata for locals local u_zi, u_zf, u_zfn = 0, 0.0, -0.0 -assert_eq(1/-(u_zi) == 1/0, true, 'var: unary minus zi (+Inf)') -assert_eq(1/-(u_zfn) == 1/0.0, true, 'var: unary minus zfn (+Inf)') -assert_eq(1/u_zf == 1/0.0, true, 'var: zf (+Inf)') +assertEquals(1/-(u_zi) == 1/0, true, 'var: unary minus zi (+Inf)') +assertEquals(1/-(u_zfn) == 1/0.0, true, 'var: unary minus zfn (+Inf)') +assertEquals(1/u_zf == 1/0.0, true, 'var: zf (+Inf)') -- 3. Integer operations (must not produce -0) -assert_eq(1/(1-1) == 1/0, true, 'int: sub (+0)') -assert_eq(1/(0*-1) == 1/0, true, 'int: mul (+0)') -assert_eq(1/(0%1) == 1/0, true, 'int: mod (+0)') -assert_eq(1/(0%-1) == 1/0, true, 'int: mod neg divisor (+0)') +assertEquals(1/(1-1) == 1/0, true, 'int: sub (+0)') +assertEquals(1/(0*-1) == 1/0, true, 'int: mul (+0)') +assertEquals(1/(0%1) == 1/0, true, 'int: mod (+0)') +assertEquals(1/(0%-1) == 1/0, true, 'int: mod neg divisor (+0)') -- 4. Float operations (must preserve -0.0) -assert_eq(1/(0.0*-1.0) == -1/ 0.0, true, 'float: mul (-0.0)') -assert_eq(1/((-0.0)%1.0) == -1/ 0.0, true, 'float: mod (-0.0)') -assert_eq(1/((-0.0)%-1.0) == -1/ 0.0, true, 'float: mod neg divisor (-0.0)') +assertEquals(1/(0.0*-1.0) == -1/ 0.0, true, 'float: mul (-0.0)') +assertEquals(1/((-0.0)%1.0) == -1/ 0.0, true, 'float: mod (-0.0)') +assertEquals(1/((-0.0)%-1.0) == -1/ 0.0, true, 'float: mod neg divisor (-0.0)') -- 4.1. Zero result from float addition prefers +0.0 -assert_eq(1/((-0.0)+0.0) == 1/0.0, true, 'float: (-0.0)+0.0 yields +0.0') +assertEquals(1/((-0.0)+0.0) == 1/0.0, true, 'float: (-0.0)+0.0 yields +0.0') -- 4.2. Plain -0.0 handling in arithmetic do local nz = -0.0 -- Addition: -0.0 + 0 yields +0.0 (IEEE 754 rule) - assert_eq(1/(nz + 0), 1/0.0, 'plain -0.0: nz + 0 yields +0.0') - assert_eq(1/(0 + nz), 1/0.0, 'plain -0.0: 0 + nz yields +0.0') + assertEquals(1/(nz + 0), 1/0.0, 'plain -0.0: nz + 0 yields +0.0') + assertEquals(1/(0 + nz), 1/0.0, 'plain -0.0: 0 + nz yields +0.0') -- Multiplication preserves -0.0 - assert_eq(1/(nz * 1), -1/0.0, 'plain -0.0: nz * 1 yields -0.0') - assert_eq(1/(1 * nz), -1/0.0, 'plain -0.0: 1 * nz yields -0.0') + assertEquals(1/(nz * 1), -1/0.0, 'plain -0.0: nz * 1 yields -0.0') + assertEquals(1/(1 * nz), -1/0.0, 'plain -0.0: 1 * nz yields -0.0') -- Subtraction: -0.0 - 0 = -0.0 - assert_eq(1/(nz - 0), 1/0.0, 'plain -0.0: nz - 0 yields +0.0') + assertEquals(1/(nz - 0), 1/0.0, 'plain -0.0: nz - 0 yields +0.0') -- Subtraction: -0.0 - 0.0 = -0.0 (float) - assert_eq(1/(nz - 0.0), -1/0.0, 'plain -0.0: nz - 0.0 yields -0.0') + assertEquals(1/(nz - 0.0), -1/0.0, 'plain -0.0: nz - 0.0 yields -0.0') -- Subtraction: 0 - (-0.0) = +0.0 - assert_eq(1/(0 - nz), 1/0.0, 'plain -0.0: 0 - nz yields +0.0') + assertEquals(1/(0 - nz), 1/0.0, 'plain -0.0: 0 - nz yields +0.0') end -- 4.3. Expression-generated -0.0 do local r = 0.0 * -1.0 - assert_eq(1/r, -1/0.0, 'expr: 0.0 * -1.0 yields -0.0') + assertEquals(1/r, -1/0.0, 'expr: 0.0 * -1.0 yields -0.0') local s = -1.0 * 0.0 - assert_eq(1/s, -1/0.0, 'expr: -1.0 * 0.0 yields -0.0') + assertEquals(1/s, -1/0.0, 'expr: -1.0 * 0.0 yields -0.0') -- Division producing -0.0 local d = -0.0 / 1.0 - assert_eq(1/d, -1/0.0, 'expr: -0.0 / 1.0 yields -0.0') + assertEquals(1/d, -1/0.0, 'expr: -0.0 / 1.0 yields -0.0') end -- 5. Mixed arithmetic producing zero -assert_eq(1/(0*-1.0) == -1/0.0, true, 'mixed: mul int*float (-0.0)') -assert_eq(1/(0.0*-1 ) == -1/0.0, true, 'mixed: mul float*int (-0.0)') -assert_eq(1/(1.0+(-1)) == 1/0.0, true, 'mixed: add (+0.0)') -assert_eq(1/(-(1-1.0)) == -1/0.0, true, 'mixed: sub then unary minus (-0.0)') +assertEquals(1/(0*-1.0) == -1/0.0, true, 'mixed: mul int*float (-0.0)') +assertEquals(1/(0.0*-1 ) == -1/0.0, true, 'mixed: mul float*int (-0.0)') +assertEquals(1/(1.0+(-1)) == 1/0.0, true, 'mixed: add (+0.0)') +assertEquals(1/(-(1-1.0)) == -1/0.0, true, 'mixed: sub then unary minus (-0.0)') -- 5.1. Dynamic key table metadata affects binary ops local dyn_t, dyn_k = {}, 'zf' dyn_t[dyn_k] = 0.0 -assert_eq(1/dyn_t[dyn_k] == 1/0.0, true, 'binary: table dyn key float (+Inf)') +assertEquals(1/dyn_t[dyn_k] == 1/0.0, true, 'binary: table dyn key float (+Inf)') -- 6. Variables local zi, zf, zfn = 0, 0.0, -0.0 -assert_eq(1/zi == 1/0, true, 'var: zi (+Inf)') -assert_eq(1/zf == 1/0.0, true, 'var: zf (+Inf)') -assert_eq(1/zfn == -1/0.0, true, 'var: zfn (-Inf)') -assert_eq(1/-(zi) == 1/0, true, 'var: unary minus zi (+Inf)') -assert_eq(1/-(zfn) == 1/0.0, true, 'var: unary minus zfn (+Inf)') +assertEquals(1/zi == 1/0, true, 'var: zi (+Inf)') +assertEquals(1/zf == 1/0.0, true, 'var: zf (+Inf)') +assertEquals(1/zfn == -1/0.0, true, 'var: zfn (-Inf)') +assertEquals(1/-(zi) == 1/0, true, 'var: unary minus zi (+Inf)') +assertEquals(1/-(zfn) == 1/0.0, true, 'var: unary minus zfn (+Inf)') -- 6.1. Variables: metadata must flow through reassignment local zswap = 0.0 -assert_eq(1/zswap == 1/0.0, true, 'var: zswap float (+Inf)') +assertEquals(1/zswap == 1/0.0, true, 'var: zswap float (+Inf)') zswap = 0 -assert_eq(1/zswap == 1/0, true, 'var: zswap reassigned int (+Inf)') +assertEquals(1/zswap == 1/0, true, 'var: zswap reassigned int (+Inf)') zswap = 0.0 -assert_eq(1/zswap == 1/0.0, true, 'var: zswap reassigned float (+Inf)') +assertEquals(1/zswap == 1/0.0, true, 'var: zswap reassigned float (+Inf)') -- 7. Functions returning zeros and unary minus local function ret_zi() @@ -167,100 +167,100 @@ local function ret_zfn() return -0.0 end -assert_eq(1/ret_zi() == 1/0, true, 'fn: ret_zi (+Inf)') -assert_eq(1/ret_zf() == 1/0.0, true, 'fn: ret_zf (+Inf)') -assert_eq(1/ret_zfn() == -1/0.0, true, 'fn: ret_zfn (-Inf)') +assertEquals(1/ret_zi() == 1/0, true, 'fn: ret_zi (+Inf)') +assertEquals(1/ret_zf() == 1/0.0, true, 'fn: ret_zf (+Inf)') +assertEquals(1/ret_zfn() == -1/0.0, true, 'fn: ret_zfn (-Inf)') -assert_eq(1/-(ret_zi()) == 1/0, true, 'fn unary minus: ret_zi (+Inf)') -assert_eq(1/-(ret_zf()) == -1/0.0, true, 'fn unary minus: ret_zf (-Inf)') -assert_eq(1/-(ret_zfn()) == 1/0.0, true, 'fn unary minus: ret_zfn (+Inf)') +assertEquals(1/-(ret_zi()) == 1/0, true, 'fn unary minus: ret_zi (+Inf)') +assertEquals(1/-(ret_zf()) == -1/0.0, true, 'fn unary minus: ret_zf (-Inf)') +assertEquals(1/-(ret_zfn()) == 1/0.0, true, 'fn unary minus: ret_zfn (+Inf)') -- 8. Tables and arrays local t, arr = {zi=zi, zfn=zfn}, {zi, zfn} -- 8.1. Tables -assert_eq(1/t.zi == 1/0, true, 'table: t.zi (+Inf)') -assert_eq(1/t.zfn == -1/0.0, true, 'table: t.zfn (-Inf)') +assertEquals(1/t.zi == 1/0, true, 'table: t.zi (+Inf)') +assertEquals(1/t.zfn == -1/0.0, true, 'table: t.zfn (-Inf)') -- 8.2. Arrays -assert_eq(1/arr[1] == 1/0, true, 'array: arr[1]=zi (+Inf)') -assert_eq(1/arr[2] == -1/0.0, true, 'array: arr[2]=zfn (-Inf)') +assertEquals(1/arr[1] == 1/0, true, 'array: arr[1]=zi (+Inf)') +assertEquals(1/arr[2] == -1/0.0, true, 'array: arr[2]=zfn (-Inf)') -- 8.3. Arrays: dynamic numeric index key metadata local arr2 = {} local idx = 1 arr2[idx] = 0.0 -assert_eq(1/arr2[idx] == 1/0.0, true, 'array: dyn index float (+Inf)') +assertEquals(1/arr2[idx] == 1/0.0, true, 'array: dyn index float (+Inf)') -- 9. Deeply nested parentheses and expressions local xi, xf = 1-1, 1.0-1.0 local deepi = -((((0+0)-(1-1))+(zi-xi))) -- int path (+0) local deepf = -((((0.0+0.0)-(1.0-1.0))+(zf-xf))) -- float path (-0.0) -assert_eq(1/deepi == 1/0, true, 'nested: int (+Inf)') -assert_eq(1/deepf == -1/0.0, true, 'nested: float (-Inf)') +assertEquals(1/deepi == 1/0, true, 'nested: int (+Inf)') +assertEquals(1/deepf == -1/0.0, true, 'nested: float (-Inf)') -- 10. Floor division near zero -assert_eq(1/(0//1) == 1/0, true, 'floor div: int (+0)') -assert_eq(1/(0.0//1.0) == 1/0.0, true, 'floor div: float (+Inf)') -assert_eq(1/((-0.0)//1.0) == -1/0.0, true, 'floor div: float (-Inf)') -assert_eq(1/(0//1.0) == 1/0.0, true, 'floor div: mixed (+0.0)') +assertEquals(1/(0//1) == 1/0, true, 'floor div: int (+0)') +assertEquals(1/(0.0//1.0) == 1/0.0, true, 'floor div: float (+Inf)') +assertEquals(1/((-0.0)//1.0) == -1/0.0, true, 'floor div: float (-Inf)') +assertEquals(1/(0//1.0) == 1/0.0, true, 'floor div: mixed (+0.0)') -- 10.1. Modulo/division identity local function id_ok(a, b) return a == b * (a // b) + a % b end -assert_eq(id_ok(5, 2), true, 'identity: 5, 2') -assert_eq(id_ok(-5, 2), true, 'identity: -5, 2') -assert_eq(id_ok(5, -2), true, 'identity: 5, -2') -assert_eq(id_ok(-5, -2), true, 'identity: -5, -2') +assertEquals(id_ok(5, 2), true, 'identity: 5, 2') +assertEquals(id_ok(-5, 2), true, 'identity: -5, 2') +assertEquals(id_ok(5, -2), true, 'identity: 5, -2') +assertEquals(id_ok(-5, -2), true, 'identity: -5, -2') -- 10.2. Floor division signs -assert_eq(5//-2, -3, 'idiv: 5//-2 == -3') -assert_eq(-5//2, -3, 'idiv: -5//2 == -3') -assert_eq(-5//-2, 2, 'idiv: -5//-2 == 2') +assertEquals(5//-2, -3, 'idiv: 5//-2 == -3') +assertEquals(-5//2, -3, 'idiv: -5//2 == -3') +assertEquals(-5//-2, 2, 'idiv: -5//-2 == 2') -- 11. Ordering and NaN -assert_eq((-0.0) < (0.0), false, 'ordering: -0.0 < 0.0 is false') -assert_eq((0.0) < (-0.0), false, 'ordering: 0.0 < -0.0 is false') -assert_eq((-0.0) <= (0.0), true, 'ordering: -0.0 <= 0.0') -assert_eq((0.0) <= (-0.0), true, 'ordering: 0.0 <= -0.0') -assert_eq((0/0) == (0/0), false, 'NaN: never equals itself') +assertEquals((-0.0) < (0.0), false, 'ordering: -0.0 < 0.0 is false') +assertEquals((0.0) < (-0.0), false, 'ordering: 0.0 < -0.0 is false') +assertEquals((-0.0) <= (0.0), true, 'ordering: -0.0 <= 0.0') +assertEquals((0.0) <= (-0.0), true, 'ordering: 0.0 <= -0.0') +assertEquals((0/0) == (0/0), false, 'NaN: never equals itself') -- 12. Bitwise operators -assert_eq((~0) == -1, true, 'bitwise not on int ok') +assertEquals((~0) == -1, true, 'bitwise not on int ok') val = pcall( function() return ~0.0 end ) -assert_eq(val, true, 'bitwise not on float ok') +assertEquals(val, true, 'bitwise not on float ok') val = pcall( function() return 0<<1 end ) -assert_eq(val, true, 'shl int ok') +assertEquals(val, true, 'shl int ok') val = pcall( function() return 0.0<<1 end ) -assert_eq(val, true, 'shl float ok') +assertEquals(val, true, 'shl float ok') -- 12.1 Bitwise ops results -assert_eq((5&3) == 1, true, 'bitwise and result') -assert_eq((5|2) == 7, true, 'bitwise or result') -assert_eq((5~1) == 4, true, 'bitwise xor result') -assert_eq((1<<5) == 32, true, 'bitwise shl result') -assert_eq((32>>5) == 1, true, 'bitwise shr result') +assertEquals((5&3) == 1, true, 'bitwise and result') +assertEquals((5|2) == 7, true, 'bitwise or result') +assertEquals((5~1) == 4, true, 'bitwise xor result') +assertEquals((1<<5) == 32, true, 'bitwise shl result') +assertEquals((32>>5) == 1, true, 'bitwise shr result') -- 12.2 Bitwise with float values -assert_eq((~(-0.0)) == -1, true, 'bitwise not on -0.0 == -1') +assertEquals((~(-0.0)) == -1, true, 'bitwise not on -0.0 == -1') -- 13. Evaluation order (left-to-right) for binary ops local log, val @@ -278,33 +278,33 @@ end log = {} val = lhs_num()+rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: +') +assertEquals(table.concat(log, ''), 'LR', 'order: +') log = {} val = lhs_num()-rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: -') +assertEquals(table.concat(log, ''), 'LR', 'order: -') log = {} val = lhs_num()*rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: *') +assertEquals(table.concat(log, ''), 'LR', 'order: *') log = {} val = lhs_num()/rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: /') +assertEquals(table.concat(log, ''), 'LR', 'order: /') -- floor div and mod log = {} val = lhs_num()//rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: //') +assertEquals(table.concat(log, ''), 'LR', 'order: //') log = {} val = lhs_num()%rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: %') +assertEquals(table.concat(log, ''), 'LR', 'order: %') -- power and concatenation log = {} val = lhs_num()^rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: ^') +assertEquals(table.concat(log, ''), 'LR', 'order: ^') local function lhs_str() log[#log + 1] = 'L' @@ -318,53 +318,53 @@ end log = {} val = lhs_str()..rhs_str() -assert_eq(table.concat(log, ''), 'LR', 'order: ..') +assertEquals(table.concat(log, ''), 'LR', 'order: ..') -- relational log = {} val = (lhs_num() < rhs_num()) -assert_eq(table.concat(log, ''), 'LR', 'order: <') +assertEquals(table.concat(log, ''), 'LR', 'order: <') log = {} val = (lhs_num() <= rhs_num()) -assert_eq(table.concat(log, ''), 'LR', 'order: <=') +assertEquals(table.concat(log, ''), 'LR', 'order: <=') log = {} val = (lhs_num() > rhs_num()) -assert_eq(table.concat(log, ''), 'LR', 'order: >') +assertEquals(table.concat(log, ''), 'LR', 'order: >') log = {} val = (lhs_num() >= rhs_num()) -assert_eq(table.concat(log, ''), 'LR', 'order: >=') +assertEquals(table.concat(log, ''), 'LR', 'order: >=') log = {} val = (lhs_num() == rhs_num()) -assert_eq(table.concat(log, ''), 'LR', 'order: ==') +assertEquals(table.concat(log, ''), 'LR', 'order: ==') log = {} val = (lhs_num() ~= rhs_num()) -assert_eq(table.concat(log, ''), 'LR', 'order: ~=') +assertEquals(table.concat(log, ''), 'LR', 'order: ~=') -- bitwise log = {} val = lhs_num()&rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: &') +assertEquals(table.concat(log, ''), 'LR', 'order: &') log = {} val = lhs_num()|rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: |') +assertEquals(table.concat(log, ''), 'LR', 'order: |') log = {} val = lhs_num()~rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: ~ (xor)') +assertEquals(table.concat(log, ''), 'LR', 'order: ~ (xor)') log = {} val = lhs_num()<>rhs_num() -assert_eq(table.concat(log, ''), 'LR', 'order: >>') +assertEquals(table.concat(log, ''), 'LR', 'order: >>') -- 13.2. Nested expressions and associativity local function exp_a() @@ -384,24 +384,24 @@ end log = {} val = exp_a() ^ (exp_b() ^ exp_c()) -assert_eq(val, 512, 'nested expression result') -assert_eq(table.concat(log, ''), 'ABC', 'nested expression associativity') +assertEquals(val, 512, 'nested expression result') +assertEquals(table.concat(log, ''), 'ABC', 'nested expression associativity') -assert_eq(2^3^2, 512, 'power associativity') +assertEquals(2^3^2, 512, 'power associativity') -- 14. String-to-number coercion around zero -assert_eq(1/('0') == 1/0.0, true, 'str: ("0") (+Inf)') -assert_eq(1/('-0') == 1/0.0, true, 'str: ("-0") (+Inf)') -assert_eq(1/('0.0') == 1/0.0, true, 'str: ("0.0") (+Inf)') -assert_eq(1/('-0.0') == -1/0.0, true, 'str: ("-0.0") (-Inf)') -assert_eq(1/-('0') == 1/0.0, true, 'str: unary minus -("0") (+Inf)') -assert_eq(1/-('-0') == 1/0.0, true, 'str: unary minus -("-0") (+Inf)') +assertEquals(1/('0') == 1/0.0, true, 'str: ("0") (+Inf)') +assertEquals(1/('-0') == 1/0.0, true, 'str: ("-0") (+Inf)') +assertEquals(1/('0.0') == 1/0.0, true, 'str: ("0.0") (+Inf)') +assertEquals(1/('-0.0') == -1/0.0, true, 'str: ("-0.0") (-Inf)') +assertEquals(1/-('0') == 1/0.0, true, 'str: unary minus -("0") (+Inf)') +assertEquals(1/-('-0') == 1/0.0, true, 'str: unary minus -("-0") (+Inf)') -- 14.1. General arithmetic with numeric strings -assert_eq('1'+2, 3, 'str-num: "1"+2 == 3') -assert_eq(' -2 ' * '3', -6, 'str-num: " -2 " * "3" == -6') -assert_eq('0x10' + 1, 17, 'str-num: hex int string + 1 == 17') -assert_eq('0x1p4' + 0, 16, 'str-num: hex float string + 0 == 16') +assertEquals('1'+2, 3, 'str-num: "1"+2 == 3') +assertEquals(' -2 ' * '3', -6, 'str-num: " -2 " * "3" == -6') +assertEquals('0x10' + 1, 17, 'str-num: hex int string + 1 == 17') +assertEquals('0x1p4' + 0, 16, 'str-num: hex float string + 0 == 16') assertThrows("attempt to add a 'string' with a 'number'", function() return 'x1'+1 @@ -414,55 +414,55 @@ do return math.type(x) end - assert_eq(mt("0" + 0), "integer", "string '0' + 0 => integer") - assert_eq(mt("-0" + 0), "integer", "string '-0' + 0 => integer") + assertEquals(mt("0" + 0), "integer", "string '0' + 0 => integer") + assertEquals(mt("-0" + 0), "integer", "string '-0' + 0 => integer") - assert_eq(mt("0.0" + 0), "float", "string '0.0' + 0 => float") - assert_eq(mt("-0.0" + 0), "float", "string '-0.0' + 0 => float") + assertEquals(mt("0.0" + 0), "float", "string '0.0' + 0 => float") + assertEquals(mt("-0.0" + 0), "float", "string '-0.0' + 0 => float") - assert_eq(mt("0" + 0.0), "float", "string '0' + 0.0 => float") - assert_eq(mt("0.0" + 0.0), "float", "string '0.0' + 0.0 => float") + assertEquals(mt("0" + 0.0), "float", "string '0' + 0.0 => float") + assertEquals(mt("0.0" + 0.0), "float", "string '0.0' + 0.0 => float") - assert_eq(mt("0" + -0), "integer", "string '0' + -0 => integer") - assert_eq(mt("0" + -0.0), "float", "string '0' + -0.0 => float") + assertEquals(mt("0" + -0), "integer", "string '0' + -0 => integer") + assertEquals(mt("0" + -0.0), "float", "string '0' + -0.0 => float") -- Regression coverage: numeric strings for all arithmetic ops and operand order - assert_eq(mt("0" - 0), "integer", "string '0' - 0 => integer") - assert_eq(mt("0.0" - 0), "float", "string '0.0' - 0 => float") - assert_eq(mt("0" * 1), "integer", "string '0' * 1 => integer") - assert_eq(mt("0.0" * 1), "float", "string '0.0' * 1 => float") - assert_eq(mt("0" / 1), "float", "string '0' / 1 => float") - assert_eq(mt("0.0" / 1), "float", "string '0.0' / 1 => float") - assert_eq(mt("0" // 1), "integer", "string '0' // 1 => integer") - assert_eq(mt("0.0" // 1), "float", "string '0.0' // 1 => float") - assert_eq(mt("0" % 1), "integer", "string '0' % 1 => integer") - assert_eq(mt("0.0" % 1), "float", "string '0.0' % 1 => float") - assert_eq(mt("2" ^ 1), "float", "string '2' ^ 1 => float") - assert_eq(mt("2.0" ^ 1), "float", "string '2.0' ^ 1 => float") + assertEquals(mt("0" - 0), "integer", "string '0' - 0 => integer") + assertEquals(mt("0.0" - 0), "float", "string '0.0' - 0 => float") + assertEquals(mt("0" * 1), "integer", "string '0' * 1 => integer") + assertEquals(mt("0.0" * 1), "float", "string '0.0' * 1 => float") + assertEquals(mt("0" / 1), "float", "string '0' / 1 => float") + assertEquals(mt("0.0" / 1), "float", "string '0.0' / 1 => float") + assertEquals(mt("0" // 1), "integer", "string '0' // 1 => integer") + assertEquals(mt("0.0" // 1), "float", "string '0.0' // 1 => float") + assertEquals(mt("0" % 1), "integer", "string '0' % 1 => integer") + assertEquals(mt("0.0" % 1), "float", "string '0.0' % 1 => float") + assertEquals(mt("2" ^ 1), "float", "string '2' ^ 1 => float") + assertEquals(mt("2.0" ^ 1), "float", "string '2.0' ^ 1 => float") - assert_eq(mt(0 + "0"), "integer", "0 + string '0' => integer") - assert_eq(mt(0 + "0.0"), "float", "0 + string '0.0' => float") + assertEquals(mt(0 + "0"), "integer", "0 + string '0' => integer") + assertEquals(mt(0 + "0.0"), "float", "0 + string '0.0' => float") - assert_eq(mt(0 - "0"), "integer", "0 - string '0' => integer") - assert_eq(mt(0 - "0.0"), "float", "0 - string '0.0' => float") + assertEquals(mt(0 - "0"), "integer", "0 - string '0' => integer") + assertEquals(mt(0 - "0.0"), "float", "0 - string '0.0' => float") - assert_eq(mt(1 * "0"), "integer", "1 * string '0' => integer") - assert_eq(mt(1 * "0.0"), "float", "1 * string '0.0' => float") + assertEquals(mt(1 * "0"), "integer", "1 * string '0' => integer") + assertEquals(mt(1 * "0.0"), "float", "1 * string '0.0' => float") - assert_eq(mt(0 / "1"), "float", "0 / string '1' => float") - assert_eq(mt(0 / "1.0"), "float", "0 / string '1.0' => float") + assertEquals(mt(0 / "1"), "float", "0 / string '1' => float") + assertEquals(mt(0 / "1.0"), "float", "0 / string '1.0' => float") - assert_eq(mt(0 // "1"), "integer", "0 // string '1' => integer") - assert_eq(mt(0 // "1.0"), "float", "0 // string '1.0' => float") + assertEquals(mt(0 // "1"), "integer", "0 // string '1' => integer") + assertEquals(mt(0 // "1.0"), "float", "0 // string '1.0' => float") - assert_eq(mt(0 % "1"), "integer", "0 % string '1' => integer") - assert_eq(mt(0 % "1.0"), "float", "0 % string '1.0' => float") + assertEquals(mt(0 % "1"), "integer", "0 % string '1' => integer") + assertEquals(mt(0 % "1.0"), "float", "0 % string '1.0' => float") - assert_eq(mt(2 ^ "1"), "float", "2 ^ string '1' => float") - assert_eq(mt(2 ^ "1.0"), "float", "2 ^ string '1.0' => float") + assertEquals(mt(2 ^ "1"), "float", "2 ^ string '1' => float") + assertEquals(mt(2 ^ "1.0"), "float", "2 ^ string '1.0' => float") - assert_eq((1 // "2"), 0, "1 // '2' == 0") - assert_eq((1 // "2.0"), 0.0, "1 // '2.0' == 0.0") + assertEquals((1 // "2"), 0, "1 // '2' == 0") + assertEquals((1 // "2.0"), 0.0, "1 // '2.0' == 0.0") end -- 15. Recursive function producing int zero (and unary minus) @@ -473,10 +473,10 @@ local function rec_zero(n) return -rec_zero(n - 1) end -assert_eq(1/rec_zero(5) == 1/0, true, 'recursive: rec_zero (+Inf)') -assert_eq(1/(rec_zero(5)) == 1/0, true, 'recursive: (rec_zero) (+Inf)') -assert_eq(1/-(rec_zero(5)) == 1/0, true, 'recursive: -(rec_zero) (+Inf)') -assert_eq(1/-rec_zero(5) == 1/0, true, 'recursive: -(rec_zero) (+Inf)') +assertEquals(1/rec_zero(5) == 1/0, true, 'recursive: rec_zero (+Inf)') +assertEquals(1/(rec_zero(5)) == 1/0, true, 'recursive: (rec_zero) (+Inf)') +assertEquals(1/-(rec_zero(5)) == 1/0, true, 'recursive: -(rec_zero) (+Inf)') +assertEquals(1/-rec_zero(5) == 1/0, true, 'recursive: -(rec_zero) (+Inf)') -- 16. Modulo and integer division by zero @@ -492,21 +492,21 @@ val = pcall( return 1.0%0.0 end ) -assert_eq(val, true, 'float mod by zero ok (NaN)') +assertEquals(val, true, 'float mod by zero ok (NaN)') val = pcall( function() return 1.0%0 end ) -assert_eq(val, true, 'mixed (float,int) mod by zero ok (NaN)') +assertEquals(val, true, 'mixed (float,int) mod by zero ok (NaN)') val = pcall( function() return 1%0.0 end ) -assert_eq(val, true, 'mixed (int,float) mod by zero ok (NaN)') +assertEquals(val, true, 'mixed (int,float) mod by zero ok (NaN)') -- 16.2. Integer division by zero assertThrows('divide by zero', @@ -520,26 +520,26 @@ val = pcall( return 1.0//0.0 end ) -assert_eq(val, true, 'float idiv by zero ok (+Inf/-Inf)') +assertEquals(val, true, 'float idiv by zero ok (+Inf/-Inf)') val = pcall( function() return 1.0//0 end ) -assert_eq(val, true, 'mixed (float,int) idiv by zero ok (+Inf/-Inf)') +assertEquals(val, true, 'mixed (float,int) idiv by zero ok (+Inf/-Inf)') val = pcall( function() return 1//0.0 end ) -assert_eq(val, true, 'mixed (int,float) idiv by zero ok (+Inf/-Inf)') +assertEquals(val, true, 'mixed (int,float) idiv by zero ok (+Inf/-Inf)') -- 16.3. Modulo sign semantics (explicit) -assert_eq(5 % -2, -1, 'mod: 5 % -2 == -1') -assert_eq(-5 % 2, 1, 'mod: -5 % 2 == 1') -assert_eq(-5 % -2, -1, 'mod: -5 % -2 == -1') +assertEquals(5 % -2, -1, 'mod: 5 % -2 == -1') +assertEquals(-5 % 2, 1, 'mod: -5 % 2 == 1') +assertEquals(-5 % -2, -1, 'mod: -5 % -2 == -1') -- 17. Metamethod precedence: __add should dispatch local mt = { @@ -549,7 +549,7 @@ local mt = { } local tbl = setmetatable({}, mt) -assert_eq(tbl + tbl, 'added', '__add dispatched') +assertEquals(tbl + tbl, 'added', '__add dispatched') -- 17.1 Unary metamethod: __unm (negation) local mt_unm = { @@ -559,7 +559,7 @@ local mt_unm = { } local u = setmetatable({}, mt_unm) -assert_eq(-u, 'negated', '__unm dispatched') +assertEquals(-u, 'negated', '__unm dispatched') -- 17.2 Unary metamethod: __bnot (bitwise NOT) local bnot_calls = 0 @@ -571,8 +571,8 @@ local mt_bnot = { } local b = setmetatable({}, mt_bnot) -assert_eq(~b, 123, '__bnot dispatched') -assert_eq(bnot_calls, 1, '__bnot called exactly once') +assertEquals(~b, 123, '__bnot dispatched') +assertEquals(bnot_calls, 1, '__bnot called exactly once') -- 17.3. Unary metamethods multi-return (first return only) local mt_unm_mr = { @@ -582,7 +582,7 @@ local mt_unm_mr = { } local um = setmetatable({}, mt_unm_mr) -assert_eq(-um, 7, '__unm uses first return value') +assertEquals(-um, 7, '__unm uses first return value') local mt_bnot_mr = { __bnot = function(_) @@ -591,19 +591,19 @@ local mt_bnot_mr = { } local bm = setmetatable({}, mt_bnot_mr) -assert_eq(~bm, 9, '__bnot uses first return value') +assertEquals(~bm, 9, '__bnot uses first return value') -- 18. Multi-return in arithmetic (first return only) local function multi_ret() return 0, 1 end -assert_eq(1/(multi_ret()) == 1/0, true, 'multi-ret: 1st used (+Inf)') -assert_eq(1/-(multi_ret()) == 1/0, true, 'multi-ret: unary minus 1st used (+Inf)') +assertEquals(1/(multi_ret()) == 1/0, true, 'multi-ret: 1st used (+Inf)') +assertEquals(1/-(multi_ret()) == 1/0, true, 'multi-ret: unary minus 1st used (+Inf)') -- 18.1 Exponentiation zero edge cases -assert_eq(0^0 == 1, true, 'pow: 0^0 == 1') -assert_eq((-0.0)^0 == 1, true, 'pow: (-0.0)^0 == 1') +assertEquals(0^0 == 1, true, 'pow: 0^0 == 1') +assertEquals((-0.0)^0 == 1, true, 'pow: (-0.0)^0 == 1') -- 19. Error tests assertThrows('has no integer representation', @@ -844,49 +844,49 @@ assertThrows("attempt to divide by zero", -- 20. `tostring()` numeric formatting -- 20.1. Integers -assert_eq(tostring(0), '0', 'tostring: 0') -assert_eq(tostring(1), '1', 'tostring: 1') -assert_eq(tostring(-5), '-5', 'tostring: -5') -assert_eq(tostring(42), '42', 'tostring: 42') -assert_eq(tostring(-123), '-123', 'tostring: -123') +assertEquals(tostring(0), '0', 'tostring: 0') +assertEquals(tostring(1), '1', 'tostring: 1') +assertEquals(tostring(-5), '-5', 'tostring: -5') +assertEquals(tostring(42), '42', 'tostring: 42') +assertEquals(tostring(-123), '-123', 'tostring: -123') -- 20.2. Float zeros (positive and negative) -assert_eq(tostring(0.0), '0.0', 'tostring: 0.0') -assert_eq(tostring(-0.0), '-0.0', 'tostring: -0.0') +assertEquals(tostring(0.0), '0.0', 'tostring: 0.0') +assertEquals(tostring(-0.0), '-0.0', 'tostring: -0.0') -- 20.3. Integer-valued floats -assert_eq(tostring(1.0), '1.0', 'tostring: 1.0') -assert_eq(tostring(2.0), '2.0', 'tostring: 2.0') -assert_eq(tostring(-3.0), '-3.0', 'tostring: -3.0') -assert_eq(tostring(100.0), '100.0', 'tostring: 100.0') +assertEquals(tostring(1.0), '1.0', 'tostring: 1.0') +assertEquals(tostring(2.0), '2.0', 'tostring: 2.0') +assertEquals(tostring(-3.0), '-3.0', 'tostring: -3.0') +assertEquals(tostring(100.0), '100.0', 'tostring: 100.0') -- 20.4. Non-integer floats -assert_eq(tostring(0.5), '0.5', 'tostring: 0.5') -assert_eq(tostring(3.14), '3.14', 'tostring: 3.14') -assert_eq(tostring(-2.5), '-2.5', 'tostring: -2.5') +assertEquals(tostring(0.5), '0.5', 'tostring: 0.5') +assertEquals(tostring(3.14), '3.14', 'tostring: 3.14') +assertEquals(tostring(-2.5), '-2.5', 'tostring: -2.5') -- 20.5. Special float values -assert_eq(tostring(1/0.0), 'inf', 'tostring: +inf') -assert_eq(tostring(-1/0.0), '-inf', 'tostring: -inf') -assert_eq(tostring(0.0/0.0), '-nan', 'tostring: NaN') -assert_eq(tostring(1.0%0.0), '-nan', 'tostring: NaN from modulo') -assert_eq(tostring((-1.0)%0.0), '-nan', 'tostring: NaN from neg modulo') +assertEquals(tostring(1/0.0), 'inf', 'tostring: +inf') +assertEquals(tostring(-1/0.0), '-inf', 'tostring: -inf') +assertEquals(tostring(0.0/0.0), '-nan', 'tostring: NaN') +assertEquals(tostring(1.0%0.0), '-nan', 'tostring: NaN from modulo') +assertEquals(tostring((-1.0)%0.0), '-nan', 'tostring: NaN from neg modulo') -- 20.6. Results from tonumber() preserve type -assert_eq(tostring(tonumber('5')), '5', 'tonumber int: "5"') -assert_eq(tostring(tonumber('5.')), '5.0', 'tonumber float: "5."') -assert_eq(tostring(tonumber('.5')), '0.5', 'tonumber float: ".5"') -assert_eq(tostring(tonumber('5.0')), '5.0', 'tonumber float: "5.0"') -assert_eq(tostring(tonumber('0x10')), '16', 'tonumber hex int: "0x10"') -assert_eq(tostring(tonumber('0x10.0')), '16.0', 'tonumber hex float: "0x10.0"') -assert_eq(tostring(tonumber('0x1p4')), '16.0', 'tonumber hex float: "0x1p4"') +assertEquals(tostring(tonumber('5')), '5', 'tonumber int: "5"') +assertEquals(tostring(tonumber('5.')), '5.0', 'tonumber float: "5."') +assertEquals(tostring(tonumber('.5')), '0.5', 'tonumber float: ".5"') +assertEquals(tostring(tonumber('5.0')), '5.0', 'tonumber float: "5.0"') +assertEquals(tostring(tonumber('0x10')), '16', 'tonumber hex int: "0x10"') +assertEquals(tostring(tonumber('0x10.0')), '16.0', 'tonumber hex float: "0x10.0"') +assertEquals(tostring(tonumber('0x1p4')), '16.0', 'tonumber hex float: "0x1p4"') -- 20.7. Arithmetic results formatting -assert_eq(tostring(1+1), '2', 'int+int yields int') -assert_eq(tostring(1.0+1.0), '2.0', 'float+float yields float') -assert_eq(tostring(1+1.0), '2.0', 'int+float yields float') -assert_eq(tostring(5/2), '2.5', 'division yields float') -assert_eq(tostring(4/2), '2.0', 'division exact yields float') +assertEquals(tostring(1+1), '2', 'int+int yields int') +assertEquals(tostring(1.0+1.0), '2.0', 'float+float yields float') +assertEquals(tostring(1+1.0), '2.0', 'int+float yields float') +assertEquals(tostring(5/2), '2.5', 'division yields float') +assertEquals(tostring(4/2), '2.0', 'division exact yields float') -- 21. Numeric for loops: comprehensive type/mode coverage @@ -898,8 +898,8 @@ do table.insert(types, math.type(i)) table.insert(vals, tostring(i)) end - assert_eq(table.concat(types, ','), 'integer,integer,integer', 'for 1,3: types') - assert_eq(table.concat(vals, ','), '1,2,3', 'for 1,3: values') + assertEquals(table.concat(types, ','), 'integer,integer,integer', 'for 1,3: types') + assertEquals(table.concat(vals, ','), '1,2,3', 'for 1,3: values') end do @@ -907,7 +907,7 @@ do for i = 1, 3, 1 do table.insert(types, math.type(i)) end - assert_eq(types[1], 'integer', 'for 1,3,1: type') + assertEquals(types[1], 'integer', 'for 1,3,1: type') end do @@ -915,7 +915,7 @@ do for i = 3, 1, -1 do table.insert(vals, tostring(i)) end - assert_eq(table.concat(vals, ','), '3,2,1', 'for 3,1,-1: descending') + assertEquals(table.concat(vals, ','), '3,2,1', 'for 3,1,-1: descending') end do @@ -927,23 +927,23 @@ do zero_str = tostring(i) end end - assert_eq(found_zero, true, 'for -1,1: crosses zero') - assert_eq(zero_str, '0', 'for -1,1: zero is int') + assertEquals(found_zero, true, 'for -1,1: crosses zero') + assertEquals(zero_str, '0', 'for -1,1: zero is int') end do for i = 1, 3 do local zero = i - i - assert_eq(math.type(zero), 'integer', 'for 1,3: i-i is int') - assert_eq(tostring(zero), '0', 'for 1,3: i-i formats as int') + assertEquals(math.type(zero), 'integer', 'for 1,3: i-i is int') + assertEquals(tostring(zero), '0', 'for 1,3: i-i formats as int') end end do for i = 2, 4 do local expr = i * 2 - i - i - assert_eq(math.type(expr), 'integer', 'for 2,4: int expr is int') - assert_eq(expr, 0, 'for 2,4: int expr value') + assertEquals(math.type(expr), 'integer', 'for 2,4: int expr is int') + assertEquals(expr, 0, 'for 2,4: int expr value') end end @@ -955,8 +955,8 @@ do table.insert(types, math.type(i)) table.insert(vals, tostring(i)) end - assert_eq(table.concat(types, ','), 'float,float,float', 'for 1.0,3.0,1.0: types') - assert_eq(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1.0,3.0,1.0: values') + assertEquals(table.concat(types, ','), 'float,float,float', 'for 1.0,3.0,1.0: types') + assertEquals(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1.0,3.0,1.0: values') end do @@ -964,7 +964,7 @@ do for i = 0.5, 2.5, 0.5 do table.insert(vals, tostring(i)) end - assert_eq(table.concat(vals, ','), '0.5,1.0,1.5,2.0,2.5', 'for 0.5,2.5,0.5: values') + assertEquals(table.concat(vals, ','), '0.5,1.0,1.5,2.0,2.5', 'for 0.5,2.5,0.5: values') end do @@ -972,7 +972,7 @@ do for i = 3.0, 1.0, -1.0 do table.insert(vals, tostring(i)) end - assert_eq(table.concat(vals, ','), '3.0,2.0,1.0', 'for 3.0,1.0,-1.0: descending') + assertEquals(table.concat(vals, ','), '3.0,2.0,1.0', 'for 3.0,1.0,-1.0: descending') end do @@ -980,7 +980,7 @@ do for i = 2.5, 0.5, -0.5 do table.insert(vals, tostring(i)) end - assert_eq(table.concat(vals, ','), '2.5,2.0,1.5,1.0,0.5', 'for 2.5,0.5,-0.5: values') + assertEquals(table.concat(vals, ','), '2.5,2.0,1.5,1.0,0.5', 'for 2.5,0.5,-0.5: values') end do @@ -990,22 +990,22 @@ do zero_str = tostring(i) end end - assert_eq(zero_str, '0.0', 'for -1.0,1.0: zero is float') + assertEquals(zero_str, '0.0', 'for -1.0,1.0: zero is float') end do for i = 1.0, 3.0 do local zero = i - i - assert_eq(math.type(zero), 'float', 'for 1.0,3.0: i-i is float') - assert_eq(tostring(zero), '0.0', 'for 1.0,3.0: i-i formats as float') + assertEquals(math.type(zero), 'float', 'for 1.0,3.0: i-i is float') + assertEquals(tostring(zero), '0.0', 'for 1.0,3.0: i-i formats as float') end end do for i = 2.0, 4.0 do local expr = i * 2.0 - i - i - assert_eq(math.type(expr), 'float', 'for 2.0,4.0: float expr is float') - assert_eq(tostring(expr), '0.0', 'for 2.0,4.0: float expr formats') + assertEquals(math.type(expr), 'float', 'for 2.0,4.0: float expr is float') + assertEquals(tostring(expr), '0.0', 'for 2.0,4.0: float expr formats') end end @@ -1017,9 +1017,9 @@ do table.insert(types, math.type(i)) table.insert(vals, tostring(i)) end - assert_eq(types[1], 'integer', 'for 1,3.5: start int yields var int') - assert_eq(types[2], 'integer', 'for 1,3.5: var stays int') - assert_eq(table.concat(vals, ','), '1,2,3', 'for 1,3.5: int formatting') + assertEquals(types[1], 'integer', 'for 1,3.5: start int yields var int') + assertEquals(types[2], 'integer', 'for 1,3.5: var stays int') + assertEquals(table.concat(vals, ','), '1,2,3', 'for 1,3.5: int formatting') end do @@ -1028,9 +1028,9 @@ do table.insert(types, math.type(i)) table.insert(vals, tostring(i)) end - assert_eq(types[1], 'float', 'for 1.0,3: start float yields var float') - assert_eq(types[2], 'float', 'for 1.0,3: var stays float') - assert_eq(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1.0,3: float formatting') + assertEquals(types[1], 'float', 'for 1.0,3: start float yields var float') + assertEquals(types[2], 'float', 'for 1.0,3: var stays float') + assertEquals(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1.0,3: float formatting') end do @@ -1038,7 +1038,7 @@ do for i = 1, 3.0 do table.insert(types, math.type(i)) end - assert_eq(types[1], 'integer', 'for 1,3.0: end=3.0 but start int yields var int') + assertEquals(types[1], 'integer', 'for 1,3.0: end=3.0 but start int yields var int') end do @@ -1047,8 +1047,8 @@ do table.insert(types, math.type(i)) table.insert(vals, tostring(i)) end - assert_eq(types[1], 'float', 'for 1,3,1.0: step float yields var float') - assert_eq(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1,3,1.0: float formatting') + assertEquals(types[1], 'float', 'for 1,3,1.0: step float yields var float') + assertEquals(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1,3,1.0: float formatting') end do @@ -1057,8 +1057,8 @@ do table.insert(types, math.type(i)) table.insert(vals, tostring(i)) end - assert_eq(types[1], 'float', 'for 1.0,3.0,1: start float yields var float') - assert_eq(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1.0,3.0,1: float formatting') + assertEquals(types[1], 'float', 'for 1.0,3.0,1: start float yields var float') + assertEquals(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1.0,3.0,1: float formatting') end do @@ -1066,7 +1066,7 @@ do for i = 3.0, 1, -1 do table.insert(types, math.type(i)) end - assert_eq(types[1], 'float', 'for 3.0,1,-1: start float yields var float') + assertEquals(types[1], 'float', 'for 3.0,1,-1: start float yields var float') end -- Mixed mode: float step, integer start @@ -1076,8 +1076,8 @@ do table.insert(types, math.type(i)) table.insert(vals, tostring(i)) end - assert_eq(types[1], 'float', 'for 1,3,1.0: step float yields var float') - assert_eq(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1,3,1.0: float formatting') + assertEquals(types[1], 'float', 'for 1,3,1.0: step float yields var float') + assertEquals(table.concat(vals, ','), '1.0,2.0,3.0', 'for 1,3,1.0: float formatting') end -- Mixed mode: integer start, negative float step @@ -1087,21 +1087,21 @@ do table.insert(types, math.type(i)) table.insert(vals, tostring(i)) end - assert_eq(types[1], 'float', 'for 3,1,-1.0: step float yields var float') - assert_eq(table.concat(vals, ','), '3.0,2.0,1.0', 'for 3,1,-1.0: float formatting') + assertEquals(types[1], 'float', 'for 3,1,-1.0: step float yields var float') + assertEquals(table.concat(vals, ','), '3.0,2.0,1.0', 'for 3,1,-1.0: float formatting') end do for i = 1, 3.5 do local zero = i - i - assert_eq(math.type(zero), 'integer', 'for 1,3.5: start int yields i-i is int') + assertEquals(math.type(zero), 'integer', 'for 1,3.5: start int yields i-i is int') end end do for i = 1.0, 3 do local zero = i - i - assert_eq(math.type(zero), 'float', 'for 1.0,3: start float yields i-i is float') + assertEquals(math.type(zero), 'float', 'for 1.0,3: start float yields i-i is float') end end @@ -1111,9 +1111,9 @@ do local count = 0 for i = 5, 5 do count = count + 1 - assert_eq(i, 5, 'for 5,5: i=5') + assertEquals(i, 5, 'for 5,5: i=5') end - assert_eq(count, 1, 'for 5,5: one iteration') + assertEquals(count, 1, 'for 5,5: one iteration') end do @@ -1121,7 +1121,7 @@ do for i = 5, 3 do count = count + 1 end - assert_eq(count, 0, 'for 5,3: no iterations') + assertEquals(count, 0, 'for 5,3: no iterations') end do @@ -1129,7 +1129,7 @@ do for i = 3, 5, -1 do count = count + 1 end - assert_eq(count, 0, 'for 3,5,-1: no iterations') + assertEquals(count, 0, 'for 3,5,-1: no iterations') end do @@ -1137,7 +1137,7 @@ do for i = 1.0, 3.0 do last = i end - assert_eq(tostring(last), '3.0', 'for 1.0,3.0: exactly reaches end') + assertEquals(tostring(last), '3.0', 'for 1.0,3.0: exactly reaches end') end do @@ -1145,7 +1145,7 @@ do for i = 1, 10, 3 do last = i end - assert_eq(last, 10, 'for 1,10,3: reaches end exactly') + assertEquals(last, 10, 'for 1,10,3: reaches end exactly') end do @@ -1153,7 +1153,7 @@ do for i = 1, 9, 3 do last = i end - assert_eq(last, 7, 'for 1,9,3: stops before end') + assertEquals(last, 7, 'for 1,9,3: stops before end') end do @@ -1161,7 +1161,7 @@ do for i = 0.1, 0.3, 0.1 do table.insert(vals, i) end - assert_eq(#vals, 2, 'for 0.1,0.3,0.1: small float step iterations') + assertEquals(#vals, 2, 'for 0.1,0.3,0.1: small float step iterations') end do @@ -1170,7 +1170,7 @@ do for i = 0.5, 1.5, 0.5 do table.insert(vals, i) end - assert_eq(#vals, 3, 'for 0.5,1.5,0.5: small float step') + assertEquals(#vals, 3, 'for 0.5,1.5,0.5: small float step') end -- 21.5. Edge cases and errors @@ -1191,7 +1191,7 @@ do count = count + 1 if count > 5 then break end end - assert_eq(count, 6, 'for 1,1000000: large range with break') + assertEquals(count, 6, 'for 1,1000000: large range with break') end do @@ -1199,7 +1199,7 @@ do for i = 1, 5, 2 do sum = sum + i end - assert_eq(sum, 9, 'for 1,5,2: step>1 sum (1+3+5)') + assertEquals(sum, 9, 'for 1,5,2: step>1 sum (1+3+5)') end do @@ -1207,7 +1207,7 @@ do for i = 10, 1, -3 do sum = sum + i end - assert_eq(sum, 22, 'for 10,1,-3: negative step>1 sum (10+7+4+1)') + assertEquals(sum, 22, 'for 10,1,-3: negative step>1 sum (10+7+4+1)') end -- 22. Table numeric key equivalence @@ -1217,15 +1217,15 @@ end do local t = {} t[1] = 'one' - assert_eq(t[1.0], 'one', 'table: t[1] accessed via t[1.0]') - assert_eq(t[1], 'one', 'table: t[1] accessed via t[1]') + assertEquals(t[1.0], 'one', 'table: t[1] accessed via t[1.0]') + assertEquals(t[1], 'one', 'table: t[1] accessed via t[1]') end do local t = {} t[2.0] = 'two' - assert_eq(t[2], 'two', 'table: t[2.0] accessed via t[2]') - assert_eq(t[2.0], 'two', 'table: t[2.0] accessed via t[2.0]') + assertEquals(t[2], 'two', 'table: t[2.0] accessed via t[2]') + assertEquals(t[2.0], 'two', 'table: t[2.0] accessed via t[2.0]') end do @@ -1233,23 +1233,23 @@ do t[1] = 'a' t[2.0] = 'b' t[3] = 'c' - assert_eq(t[1.0], 'a', 'table: multi-key t[1.0]') - assert_eq(t[2], 'b', 'table: multi-key t[2]') - assert_eq(t[3.0], 'c', 'table: multi-key t[3.0]') + assertEquals(t[1.0], 'a', 'table: multi-key t[1.0]') + assertEquals(t[2], 'b', 'table: multi-key t[2]') + assertEquals(t[3.0], 'c', 'table: multi-key t[3.0]') end do local t = {} t[5] = 'first' t[5.0] = 'second' - assert_eq(t[5], 'second', 'table: overwrite int with float') - assert_eq(t[5.0], 'second', 'table: overwrite int with float (access)') + assertEquals(t[5], 'second', 'table: overwrite int with float') + assertEquals(t[5.0], 'second', 'table: overwrite int with float (access)') end do local t = {} t[100] = 'hundred' - assert_eq(t[100.0], 'hundred', 'table: large int t[100.0]') + assertEquals(t[100.0], 'hundred', 'table: large int t[100.0]') end -- 22.2. Zero normalization (both -0 and +0 map to same key) @@ -1257,24 +1257,24 @@ end do local t = {} t[0] = 'zero' - assert_eq(t[-0.0], 'zero', 'table: t[0] accessed via t[-0.0]') - assert_eq(t[0.0], 'zero', 'table: t[0] accessed via t[0.0]') - assert_eq(t[0], 'zero', 'table: t[0] accessed via t[0]') + assertEquals(t[-0.0], 'zero', 'table: t[0] accessed via t[-0.0]') + assertEquals(t[0.0], 'zero', 'table: t[0] accessed via t[0.0]') + assertEquals(t[0], 'zero', 'table: t[0] accessed via t[0]') end do local t = {} t[-0.0] = 'negzero' - assert_eq(t[0], 'negzero', 'table: t[-0.0] accessed via t[0]') - assert_eq(t[0.0], 'negzero', 'table: t[-0.0] accessed via t[0.0]') - assert_eq(t[-0.0], 'negzero', 'table: t[-0.0] accessed via t[-0.0]') + assertEquals(t[0], 'negzero', 'table: t[-0.0] accessed via t[0]') + assertEquals(t[0.0], 'negzero', 'table: t[-0.0] accessed via t[0.0]') + assertEquals(t[-0.0], 'negzero', 'table: t[-0.0] accessed via t[-0.0]') end do local t = {} t[0.0] = 'float_zero' - assert_eq(t[0], 'float_zero', 'table: t[0.0] accessed via t[0]') - assert_eq(t[-0.0], 'float_zero', 'table: t[0.0] accessed via t[-0.0]') + assertEquals(t[0], 'float_zero', 'table: t[0.0] accessed via t[0]') + assertEquals(t[-0.0], 'float_zero', 'table: t[0.0] accessed via t[-0.0]') end do @@ -1282,8 +1282,8 @@ do t[0] = 'first' t[-0.0] = 'second' t[0.0] = 'third' - assert_eq(t[0], 'third', 'table: zero overwrite final') - assert_eq(t[-0.0], 'third', 'table: zero overwrite via -0.0') + assertEquals(t[0], 'third', 'table: zero overwrite final') + assertEquals(t[-0.0], 'third', 'table: zero overwrite via -0.0') end -- 22.3. Non-integer floats are distinct keys @@ -1292,9 +1292,9 @@ do local t = {} t[1] = 'int_one' t[1.5] = 'one_point_five' - assert_eq(t[1], 'int_one', 'table: non-int float t[1]') - assert_eq(t[1.5], 'one_point_five', 'table: non-int float t[1.5]') - assert_eq(t[1.0], 'int_one', 'table: non-int float t[1.0] maps to int') + assertEquals(t[1], 'int_one', 'table: non-int float t[1]') + assertEquals(t[1.5], 'one_point_five', 'table: non-int float t[1.5]') + assertEquals(t[1.0], 'int_one', 'table: non-int float t[1.0] maps to int') end do @@ -1302,9 +1302,9 @@ do t[0.5] = 'half' t[1.5] = 'one_half' t[2.5] = 'two_half' - assert_eq(t[0.5], 'half', 'table: multi non-int t[0.5]') - assert_eq(t[1.5], 'one_half', 'table: multi non-int t[1.5]') - assert_eq(t[2.5], 'two_half', 'table: multi non-int t[2.5]') + assertEquals(t[0.5], 'half', 'table: multi non-int t[0.5]') + assertEquals(t[1.5], 'one_half', 'table: multi non-int t[1.5]') + assertEquals(t[2.5], 'two_half', 'table: multi non-int t[2.5]') end -- 22.4. Mixed integer and float keys @@ -1317,14 +1317,14 @@ do t[2.0] = 'two' t[-0.0] = 'neg_zero' - assert_eq(t[0], 'neg_zero', 'table: mixed t[0] (last zero)') - assert_eq(t[0.0], 'neg_zero', 'table: mixed t[0.0]') - assert_eq(t[-0.0], 'neg_zero', 'table: mixed t[-0.0]') - assert_eq(t[1], 'one', 'table: mixed t[1]') - assert_eq(t[1.0], 'one', 'table: mixed t[1.0]') - assert_eq(t[1.5], 'one_point_five', 'table: mixed t[1.5]') - assert_eq(t[2], 'two', 'table: mixed t[2]') - assert_eq(t[2.0], 'two', 'table: mixed t[2.0]') + assertEquals(t[0], 'neg_zero', 'table: mixed t[0] (last zero)') + assertEquals(t[0.0], 'neg_zero', 'table: mixed t[0.0]') + assertEquals(t[-0.0], 'neg_zero', 'table: mixed t[-0.0]') + assertEquals(t[1], 'one', 'table: mixed t[1]') + assertEquals(t[1.0], 'one', 'table: mixed t[1.0]') + assertEquals(t[1.5], 'one_point_five', 'table: mixed t[1.5]') + assertEquals(t[2], 'two', 'table: mixed t[2]') + assertEquals(t[2.0], 'two', 'table: mixed t[2.0]') end -- 22.5. Key equivalence with expressions @@ -1332,23 +1332,23 @@ end do local t = {} t[1+1] = 'two' - assert_eq(t[2.0], 'two', 'table: expr key t[1+1] via t[2.0]') - assert_eq(t[4/2], 'two', 'table: expr key t[4/2]') + assertEquals(t[2.0], 'two', 'table: expr key t[1+1] via t[2.0]') + assertEquals(t[4/2], 'two', 'table: expr key t[4/2]') end do local t = {} t[1-1] = 'int_zero' - assert_eq(t[0], 'int_zero', 'table: expr t[1-1] via t[0]') - assert_eq(t[0.0], 'int_zero', 'table: expr t[1-1] via t[0.0]') - assert_eq(t[-0.0], 'int_zero', 'table: expr t[1-1] via t[-0.0]') + assertEquals(t[0], 'int_zero', 'table: expr t[1-1] via t[0]') + assertEquals(t[0.0], 'int_zero', 'table: expr t[1-1] via t[0.0]') + assertEquals(t[-0.0], 'int_zero', 'table: expr t[1-1] via t[-0.0]') end do local t = {} t[1.0-1.0] = 'float_zero' - assert_eq(t[0], 'float_zero', 'table: expr t[1.0-1.0] via t[0]') - assert_eq(t[-0.0], 'float_zero', 'table: expr t[1.0-1.0] via t[-0.0]') + assertEquals(t[0], 'float_zero', 'table: expr t[1.0-1.0] via t[0]') + assertEquals(t[-0.0], 'float_zero', 'table: expr t[1.0-1.0] via t[-0.0]') end -- 22.6. Key equivalence with variables @@ -1358,7 +1358,7 @@ do local i = 1 local f = 1.0 t[i] = 'from_int' - assert_eq(t[f], 'from_int', 'table: var int key via float var') + assertEquals(t[f], 'from_int', 'table: var int key via float var') end do @@ -1366,7 +1366,7 @@ do local i = 1 local f = 1.0 t[f] = 'from_float' - assert_eq(t[i], 'from_float', 'table: var float key via int var') + assertEquals(t[i], 'from_float', 'table: var float key via int var') end do @@ -1375,25 +1375,25 @@ do local zf = 0.0 local zfn = -0.0 t[zi] = 'int_zero' - assert_eq(t[zf], 'int_zero', 'table: var zi via zf') - assert_eq(t[zfn], 'int_zero', 'table: var zi via zfn') + assertEquals(t[zf], 'int_zero', 'table: var zi via zf') + assertEquals(t[zfn], 'int_zero', 'table: var zi via zfn') end -- 22.7. Key equivalence in array part do local t = {10, 20, 30} - assert_eq(t[1.0], 10, 'table: array t[1.0]') - assert_eq(t[2.0], 20, 'table: array t[2.0]') - assert_eq(t[3.0], 30, 'table: array t[3.0]') + assertEquals(t[1.0], 10, 'table: array t[1.0]') + assertEquals(t[2.0], 20, 'table: array t[2.0]') + assertEquals(t[3.0], 30, 'table: array t[3.0]') end do local t = {} t[1.0] = 'first' t[2.0] = 'second' - assert_eq(t[1], 'first', 'table: array assign t[1.0] via t[1]') - assert_eq(t[2], 'second', 'table: array assign t[2.0] via t[2]') + assertEquals(t[1], 'first', 'table: array assign t[1.0] via t[1]') + assertEquals(t[2], 'second', 'table: array assign t[2.0] via t[2]') end -- 22.8. Key counting and iteration @@ -1409,7 +1409,7 @@ do for k, v in pairs(t) do count = count + 1 end - assert_eq(count, 2, 'table: normalized keys count as one') + assertEquals(count, 2, 'table: normalized keys count as one') end do @@ -1422,82 +1422,82 @@ do for k, v in pairs(t) do count = count + 1 end - assert_eq(count, 1, 'table: all zeros count as one key') + assertEquals(count, 1, 'table: all zeros count as one key') end -- 23. Type introspection: type() and math.type() -- 23.1. Basic type() function (returns general Lua types) -assert_eq(type(nil), 'nil', 'type(nil)') -assert_eq(type(true), 'boolean', 'type(true)') -assert_eq(type(false), 'boolean', 'type(false)') -assert_eq(type(0), 'number', 'type(0) is number') -assert_eq(type(1), 'number', 'type(1) is number') -assert_eq(type(0.0), 'number', 'type(0.0) is number') -assert_eq(type(1.0), 'number', 'type(1.0) is number') -assert_eq(type(-0.0), 'number', 'type(-0.0) is number') -assert_eq(type(1.5), 'number', 'type(1.5) is number') -assert_eq(type(1/0.0), 'number', 'type(inf) is number') -assert_eq(type(0.0/0.0), 'number', 'type(nan) is number') -assert_eq(type('hello'), 'string', 'type(string)') -assert_eq(type({}), 'table', 'type(table)') -assert_eq(type(function() end), 'function', 'type(function)') +assertEquals(type(nil), 'nil', 'type(nil)') +assertEquals(type(true), 'boolean', 'type(true)') +assertEquals(type(false), 'boolean', 'type(false)') +assertEquals(type(0), 'number', 'type(0) is number') +assertEquals(type(1), 'number', 'type(1) is number') +assertEquals(type(0.0), 'number', 'type(0.0) is number') +assertEquals(type(1.0), 'number', 'type(1.0) is number') +assertEquals(type(-0.0), 'number', 'type(-0.0) is number') +assertEquals(type(1.5), 'number', 'type(1.5) is number') +assertEquals(type(1/0.0), 'number', 'type(inf) is number') +assertEquals(type(0.0/0.0), 'number', 'type(nan) is number') +assertEquals(type('hello'), 'string', 'type(string)') +assertEquals(type({}), 'table', 'type(table)') +assertEquals(type(function() end), 'function', 'type(function)') -- 23.2. math.type() function (distinguishes integer vs float) -- Integers -assert_eq(math.type(0), 'integer', 'math.type(0)') -assert_eq(math.type(1), 'integer', 'math.type(1)') -assert_eq(math.type(-1), 'integer', 'math.type(-1)') -assert_eq(math.type(42), 'integer', 'math.type(42)') -assert_eq(math.type(-123), 'integer', 'math.type(-123)') -assert_eq(math.type(1000000), 'integer', 'math.type(1000000)') +assertEquals(math.type(0), 'integer', 'math.type(0)') +assertEquals(math.type(1), 'integer', 'math.type(1)') +assertEquals(math.type(-1), 'integer', 'math.type(-1)') +assertEquals(math.type(42), 'integer', 'math.type(42)') +assertEquals(math.type(-123), 'integer', 'math.type(-123)') +assertEquals(math.type(1000000), 'integer', 'math.type(1000000)') -- Floats (literals with decimal point) -assert_eq(math.type(0.0), 'float', 'math.type(0.0)') -assert_eq(math.type(-0.0), 'float', 'math.type(-0.0)') -assert_eq(math.type(1.0), 'float', 'math.type(1.0)') -assert_eq(math.type(2.0), 'float', 'math.type(2.0)') -assert_eq(math.type(-3.0), 'float', 'math.type(-3.0)') -assert_eq(math.type(100.0), 'float', 'math.type(100.0)') +assertEquals(math.type(0.0), 'float', 'math.type(0.0)') +assertEquals(math.type(-0.0), 'float', 'math.type(-0.0)') +assertEquals(math.type(1.0), 'float', 'math.type(1.0)') +assertEquals(math.type(2.0), 'float', 'math.type(2.0)') +assertEquals(math.type(-3.0), 'float', 'math.type(-3.0)') +assertEquals(math.type(100.0), 'float', 'math.type(100.0)') -- Floats (non-integer values) -assert_eq(math.type(0.5), 'float', 'math.type(0.5)') -assert_eq(math.type(1.5), 'float', 'math.type(1.5)') -assert_eq(math.type(3.14), 'float', 'math.type(3.14)') -assert_eq(math.type(-2.5), 'float', 'math.type(-2.5)') +assertEquals(math.type(0.5), 'float', 'math.type(0.5)') +assertEquals(math.type(1.5), 'float', 'math.type(1.5)') +assertEquals(math.type(3.14), 'float', 'math.type(3.14)') +assertEquals(math.type(-2.5), 'float', 'math.type(-2.5)') -- Special float values -assert_eq(math.type(1/0.0), 'float', 'math.type(inf)') -assert_eq(math.type(-1/0.0), 'float', 'math.type(-inf)') -assert_eq(math.type(0.0/0.0), 'float', 'math.type(nan)') +assertEquals(math.type(1/0.0), 'float', 'math.type(inf)') +assertEquals(math.type(-1/0.0), 'float', 'math.type(-inf)') +assertEquals(math.type(0.0/0.0), 'float', 'math.type(nan)') -- Non-numbers return nil -assert_eq(math.type(nil), nil, 'math.type(nil) yields nil') -assert_eq(math.type(true), nil, 'math.type(boolean) yields nil') -assert_eq(math.type('123'), nil, 'math.type(string) yields nil') -assert_eq(math.type({}), nil, 'math.type(table) yields nil') -assert_eq(math.type(function() end), nil, 'math.type(function) yields nil') +assertEquals(math.type(nil), nil, 'math.type(nil) yields nil') +assertEquals(math.type(true), nil, 'math.type(boolean) yields nil') +assertEquals(math.type('123'), nil, 'math.type(string) yields nil') +assertEquals(math.type({}), nil, 'math.type(table) yields nil') +assertEquals(math.type(function() end), nil, 'math.type(function) yields nil') -- 23.3. Integer arithmetic preserves integer type do local a = 1 local b = 2 - assert_eq(math.type(a + b), 'integer', 'int + int yields integer') - assert_eq(math.type(a - b), 'integer', 'int - int yields integer') - assert_eq(math.type(a * b), 'integer', 'int * int yields integer') - assert_eq(math.type(a // b), 'integer', 'int // int yields integer') - assert_eq(math.type(a % b), 'integer', 'int % int yields integer') + assertEquals(math.type(a + b), 'integer', 'int + int yields integer') + assertEquals(math.type(a - b), 'integer', 'int - int yields integer') + assertEquals(math.type(a * b), 'integer', 'int * int yields integer') + assertEquals(math.type(a // b), 'integer', 'int // int yields integer') + assertEquals(math.type(a % b), 'integer', 'int % int yields integer') end -- Integer operations producing zero do - assert_eq(math.type(1 - 1), 'integer', '1 - 1 yields integer zero') - assert_eq(math.type(0 * 5), 'integer', '0 * 5 yields integer zero') - assert_eq(math.type(0 % 1), 'integer', '0 % 1 yields integer zero') - assert_eq(math.type(0 // 1), 'integer', '0 // 1 yields integer zero') + assertEquals(math.type(1 - 1), 'integer', '1 - 1 yields integer zero') + assertEquals(math.type(0 * 5), 'integer', '0 * 5 yields integer zero') + assertEquals(math.type(0 % 1), 'integer', '0 % 1 yields integer zero') + assertEquals(math.type(0 // 1), 'integer', '0 // 1 yields integer zero') end -- 23.4. Float arithmetic preserves float type @@ -1505,98 +1505,98 @@ end do local a = 1.0 local b = 2.0 - assert_eq(math.type(a + b), 'float', 'float + float yields float') - assert_eq(math.type(a - b), 'float', 'float - float yields float') - assert_eq(math.type(a * b), 'float', 'float * float yields float') - assert_eq(math.type(a / b), 'float', 'float / float yields float') - assert_eq(math.type(a // b), 'float', 'float // float yields float') - assert_eq(math.type(a % b), 'float', 'float % float yields float') + assertEquals(math.type(a + b), 'float', 'float + float yields float') + assertEquals(math.type(a - b), 'float', 'float - float yields float') + assertEquals(math.type(a * b), 'float', 'float * float yields float') + assertEquals(math.type(a / b), 'float', 'float / float yields float') + assertEquals(math.type(a // b), 'float', 'float // float yields float') + assertEquals(math.type(a % b), 'float', 'float % float yields float') end -- Float operations producing zero do - assert_eq(math.type(1.0 - 1.0), 'float', '1.0 - 1.0 yields float zero') - assert_eq(math.type(0.0 * 5.0), 'float', '0.0 * 5.0 yields float zero') - assert_eq(math.type(0.0 % 1.0), 'float', '0.0 % 1.0 yields float zero') - assert_eq(math.type(0.0 // 1.0), 'float', '0.0 // 1.0 yields float zero') + assertEquals(math.type(1.0 - 1.0), 'float', '1.0 - 1.0 yields float zero') + assertEquals(math.type(0.0 * 5.0), 'float', '0.0 * 5.0 yields float zero') + assertEquals(math.type(0.0 % 1.0), 'float', '0.0 % 1.0 yields float zero') + assertEquals(math.type(0.0 // 1.0), 'float', '0.0 // 1.0 yields float zero') end -- 23.5. Mixed arithmetic promotes to float do - assert_eq(math.type(1 + 1.0), 'float', 'int + float yields float') - assert_eq(math.type(1.0 + 1), 'float', 'float + int yields float') - assert_eq(math.type(2 * 1.5), 'float', 'int * float yields float') - assert_eq(math.type(3.0 - 1), 'float', 'float - int yields float') - assert_eq(math.type(5 // 2.0), 'float', 'int // float yields float') - assert_eq(math.type(5.0 % 2), 'float', 'float % int yields float') + assertEquals(math.type(1 + 1.0), 'float', 'int + float yields float') + assertEquals(math.type(1.0 + 1), 'float', 'float + int yields float') + assertEquals(math.type(2 * 1.5), 'float', 'int * float yields float') + assertEquals(math.type(3.0 - 1), 'float', 'float - int yields float') + assertEquals(math.type(5 // 2.0), 'float', 'int // float yields float') + assertEquals(math.type(5.0 % 2), 'float', 'float % int yields float') end -- Mixed operations producing zero do - assert_eq(math.type(1 - 1.0), 'float', '1 - 1.0 yields float zero') - assert_eq(math.type(0 * 1.0), 'float', '0 * 1.0 yields float zero') - assert_eq(math.type(0.0 * 1), 'float', '0.0 * 1 yields float zero') + assertEquals(math.type(1 - 1.0), 'float', '1 - 1.0 yields float zero') + assertEquals(math.type(0 * 1.0), 'float', '0 * 1.0 yields float zero') + assertEquals(math.type(0.0 * 1), 'float', '0.0 * 1 yields float zero') end -- 23.6. Division and power always produce floats do - assert_eq(math.type(4 / 2), 'float', '4 / 2 yields float (2.0)') - assert_eq(math.type(5 / 2), 'float', '5 / 2 yields float (2.5)') - assert_eq(math.type(1 / 1), 'float', '1 / 1 yields float (1.0)') + assertEquals(math.type(4 / 2), 'float', '4 / 2 yields float (2.0)') + assertEquals(math.type(5 / 2), 'float', '5 / 2 yields float (2.5)') + assertEquals(math.type(1 / 1), 'float', '1 / 1 yields float (1.0)') - assert_eq(math.type(2 ^ 3), 'float', '2 ^ 3 yields float (8.0)') - assert_eq(math.type(2 ^ 0), 'float', '2 ^ 0 yields float (1.0)') - assert_eq(math.type(10 ^ 2), 'float', '10 ^ 2 yields float (100.0)') + assertEquals(math.type(2 ^ 3), 'float', '2 ^ 3 yields float (8.0)') + assertEquals(math.type(2 ^ 0), 'float', '2 ^ 0 yields float (1.0)') + assertEquals(math.type(10 ^ 2), 'float', '10 ^ 2 yields float (100.0)') end -- Division producing zero do - assert_eq(math.type(0 / 1), 'float', '0 / 1 yields float zero') - assert_eq(math.type(0.0 / 1.0), 'float', '0.0 / 1.0 yields float zero') + assertEquals(math.type(0 / 1), 'float', '0 / 1 yields float zero') + assertEquals(math.type(0.0 / 1.0), 'float', '0.0 / 1.0 yields float zero') end -- 23.7. Unary minus preserves type do - assert_eq(math.type(-5), 'integer', '-5 is integer') - assert_eq(math.type(-0), 'integer', '-0 is integer') + assertEquals(math.type(-5), 'integer', '-5 is integer') + assertEquals(math.type(-0), 'integer', '-0 is integer') - assert_eq(math.type(-5.0), 'float', '-5.0 is float') - assert_eq(math.type(-0.0), 'float', '-0.0 is float') + assertEquals(math.type(-5.0), 'float', '-5.0 is float') + assertEquals(math.type(-0.0), 'float', '-0.0 is float') end -- Unary minus on variables do local i = 5 local f = 5.0 - assert_eq(math.type(-i), 'integer', 'unary minus int var') - assert_eq(math.type(-f), 'float', 'unary minus float var') + assertEquals(math.type(-i), 'integer', 'unary minus int var') + assertEquals(math.type(-f), 'float', 'unary minus float var') end -- Unary minus on expressions do - assert_eq(math.type(-(1 + 1)), 'integer', 'unary minus int expr') - assert_eq(math.type(-(1.0 + 1.0)), 'float', 'unary minus float expr') + assertEquals(math.type(-(1 + 1)), 'integer', 'unary minus int expr') + assertEquals(math.type(-(1.0 + 1.0)), 'float', 'unary minus float expr') end -- 23.8. String coercion preserves type (tonumber) do - assert_eq(math.type(tonumber('5')), 'integer', 'tonumber("5") yields integer') - assert_eq(math.type(tonumber('5.')), 'float', 'tonumber("5.") yields float') - assert_eq(math.type(tonumber('.5')), 'float', 'tonumber(".5") yields float') - assert_eq(math.type(tonumber('5.0')), 'float', 'tonumber("5.0") yields float') - assert_eq(math.type(tonumber('-0')), 'integer', 'tonumber("-0") yields integer') - assert_eq(math.type(tonumber('-0.0')), 'float', 'tonumber("-0.0") yields float') + assertEquals(math.type(tonumber('5')), 'integer', 'tonumber("5") yields integer') + assertEquals(math.type(tonumber('5.')), 'float', 'tonumber("5.") yields float') + assertEquals(math.type(tonumber('.5')), 'float', 'tonumber(".5") yields float') + assertEquals(math.type(tonumber('5.0')), 'float', 'tonumber("5.0") yields float') + assertEquals(math.type(tonumber('-0')), 'integer', 'tonumber("-0") yields integer') + assertEquals(math.type(tonumber('-0.0')), 'float', 'tonumber("-0.0") yields float') end -- Hexadecimal literals do - assert_eq(math.type(tonumber('0x10')), 'integer', 'tonumber("0x10") yields integer') - assert_eq(math.type(tonumber('0x10.0')), 'float', 'tonumber("0x10.0") yields float') - assert_eq(math.type(tonumber('0x1p4')), 'float', 'tonumber("0x1p4") yields float') + assertEquals(math.type(tonumber('0x10')), 'integer', 'tonumber("0x10") yields integer') + assertEquals(math.type(tonumber('0x10.0')), 'float', 'tonumber("0x10.0") yields float') + assertEquals(math.type(tonumber('0x1p4')), 'float', 'tonumber("0x1p4") yields float') end -- 23.9. Variables preserve type through assignment @@ -1605,14 +1605,14 @@ do local i = 5 local f = 5.0 - assert_eq(math.type(i), 'integer', 'int variable') - assert_eq(math.type(f), 'float', 'float variable') + assertEquals(math.type(i), 'integer', 'int variable') + assertEquals(math.type(f), 'float', 'float variable') local i2 = i local f2 = f - assert_eq(math.type(i2), 'integer', 'int variable copy') - assert_eq(math.type(f2), 'float', 'float variable copy') + assertEquals(math.type(i2), 'integer', 'int variable copy') + assertEquals(math.type(f2), 'float', 'float variable copy') end -- 23.10. Function returns preserve type @@ -1626,8 +1626,8 @@ do return 42.0 end - assert_eq(math.type(ret_int()), 'integer', 'function returns integer') - assert_eq(math.type(ret_float()), 'float', 'function returns float') + assertEquals(math.type(ret_int()), 'integer', 'function returns integer') + assertEquals(math.type(ret_float()), 'float', 'function returns float') end -- 23.11. Table values preserve type @@ -1640,10 +1640,10 @@ do [2] = 20.0 } - assert_eq(math.type(t.i), 'integer', 'table int value (string key)') - assert_eq(math.type(t.f), 'float', 'table float value (string key)') - assert_eq(math.type(t[1]), 'integer', 'table int value (int key)') - assert_eq(math.type(t[2]), 'float', 'table float value (int key)') + assertEquals(math.type(t.i), 'integer', 'table int value (string key)') + assertEquals(math.type(t.f), 'float', 'table float value (string key)') + assertEquals(math.type(t[1]), 'integer', 'table int value (int key)') + assertEquals(math.type(t[2]), 'float', 'table float value (int key)') end -- 23.12. For-loop variable type tracking @@ -1651,19 +1651,19 @@ end do -- Integer loop for i = 1, 3 do - assert_eq(math.type(i), 'integer', 'for 1,3: var is integer') + assertEquals(math.type(i), 'integer', 'for 1,3: var is integer') break -- Just test first iteration end -- Float loop (start is float) for i = 1.0, 3 do - assert_eq(math.type(i), 'float', 'for 1.0,3: var is float') + assertEquals(math.type(i), 'float', 'for 1.0,3: var is float') break end -- Float loop (step is float) for i = 1, 3, 1.0 do - assert_eq(math.type(i), 'float', 'for 1,3,1.0: var is float') + assertEquals(math.type(i), 'float', 'for 1,3,1.0: var is float') break end end @@ -1671,39 +1671,39 @@ end -- 23.13. Bitwise operations require integers (input & output) do - assert_eq(math.type(5 & 3), 'integer', 'bitwise and yields integer') - assert_eq(math.type(5 | 2), 'integer', 'bitwise or yields integer') - assert_eq(math.type(5 ~ 1), 'integer', 'bitwise xor yields integer') - assert_eq(math.type(1 << 5), 'integer', 'left shift yields integer') - assert_eq(math.type(32 >> 2), 'integer', 'right shift yields integer') - assert_eq(math.type(~0), 'integer', 'bitwise not yields integer') + assertEquals(math.type(5 & 3), 'integer', 'bitwise and yields integer') + assertEquals(math.type(5 | 2), 'integer', 'bitwise or yields integer') + assertEquals(math.type(5 ~ 1), 'integer', 'bitwise xor yields integer') + assertEquals(math.type(1 << 5), 'integer', 'left shift yields integer') + assertEquals(math.type(32 >> 2), 'integer', 'right shift yields integer') + assertEquals(math.type(~0), 'integer', 'bitwise not yields integer') end -- Bitwise operations convert float operands to integer do - assert_eq(math.type(5.0 & 3), 'integer', 'float & int yields integer') - assert_eq(math.type(5 | 2.0), 'integer', 'int | float yields integer') - assert_eq(math.type(5.0 ~ 1.0), 'integer', 'float ~ float yields integer') + assertEquals(math.type(5.0 & 3), 'integer', 'float & int yields integer') + assertEquals(math.type(5 | 2.0), 'integer', 'int | float yields integer') + assertEquals(math.type(5.0 ~ 1.0), 'integer', 'float ~ float yields integer') end -- 23.14. Edge cases: zero types do -- Positive integer zero - assert_eq(math.type(0), 'integer', '0 is integer') - assert_eq(math.type(1 - 1), 'integer', '1 - 1 is integer') - assert_eq(math.type(0 * 1), 'integer', '0 * 1 is integer') + assertEquals(math.type(0), 'integer', '0 is integer') + assertEquals(math.type(1 - 1), 'integer', '1 - 1 is integer') + assertEquals(math.type(0 * 1), 'integer', '0 * 1 is integer') -- Positive float zero - assert_eq(math.type(0.0), 'float', '0.0 is float') - assert_eq(math.type(1.0 - 1.0), 'float', '1.0 - 1.0 is float') + assertEquals(math.type(0.0), 'float', '0.0 is float') + assertEquals(math.type(1.0 - 1.0), 'float', '1.0 - 1.0 is float') -- Negative float zero - assert_eq(math.type(-0.0), 'float', '-0.0 is float') - assert_eq(math.type(0.0 * -1.0), 'float', '0.0 * -1.0 is float') + assertEquals(math.type(-0.0), 'float', '-0.0 is float') + assertEquals(math.type(0.0 * -1.0), 'float', '0.0 * -1.0 is float') -- Integer operations never produce -0 - assert_eq(math.type(0 * -1), 'integer', '0 * -1 is integer (not -0)') + assertEquals(math.type(0 * -1), 'integer', '0 * -1 is integer (not -0)') end -- 23.15. Special float values @@ -1713,13 +1713,13 @@ do local neginf = -1.0 / 0.0 local nan = 0.0 / 0.0 - assert_eq(type(inf), 'number', 'inf has type number') - assert_eq(type(neginf), 'number', '-inf has type number') - assert_eq(type(nan), 'number', 'nan has type number') + assertEquals(type(inf), 'number', 'inf has type number') + assertEquals(type(neginf), 'number', '-inf has type number') + assertEquals(type(nan), 'number', 'nan has type number') - assert_eq(math.type(inf), 'float', 'inf has math.type float') - assert_eq(math.type(neginf), 'float', '-inf has math.type float') - assert_eq(math.type(nan), 'float', 'nan has math.type float') + assertEquals(math.type(inf), 'float', 'inf has math.type float') + assertEquals(math.type(neginf), 'float', '-inf has math.type float') + assertEquals(math.type(nan), 'float', 'nan has math.type float') end -- 23.16. Type consistency across operations @@ -1730,7 +1730,7 @@ do for n = 1, 5 do sum_i = sum_i + n - assert_eq(math.type(sum_i), 'integer', 'integer sum stays integer') + assertEquals(math.type(sum_i), 'integer', 'integer sum stays integer') end local f = 10.0 @@ -1738,6 +1738,6 @@ do for n = 1.0, 5.0 do sum_f = sum_f + n - assert_eq(math.type(sum_f), 'float', 'float sum stays float') + assertEquals(math.type(sum_f), 'float', 'float sum stays float') end end diff --git a/client/space_lua/len_test.lua b/client/space_lua/len_test.lua index d9d9f3fb..e18dde24 100644 --- a/client/space_lua/len_test.lua +++ b/client/space_lua/len_test.lua @@ -1,6 +1,6 @@ -local function assert_eq(actual, expected, msg) +local function assertEquals(actual, expected, msg) if actual ~= expected then - error('assert_eq failed: ' .. msg) + error('assertEquals failed: ' .. msg) end end @@ -17,12 +17,12 @@ local function assertThrows(substr, fn) end -- 1. Strings: raw length, ignore metamethods -assert_eq(#"", 0, "empty string length") -assert_eq(#"abc", 3, "string length") +assertEquals(#"", 0, "empty string length") +assertEquals(#"abc", 3, "string length") -- 2. Tables (raw length for sequence or `__len`) -assert_eq(#{}, 0, "empty table length") -assert_eq(#{1,2,3}, 3, "array length") +assertEquals(#{}, 0, "empty table length") +assertEquals(#{1,2,3}, 3, "array length") do local t = {} @@ -34,7 +34,7 @@ do end, }) - assert_eq(#t, 42, "__len should override raw table length") + assertEquals(#t, 42, "__len should override raw table length") end -- 2.1. Metamethod result handling @@ -48,7 +48,7 @@ do end, }) - assert_eq(#t, 42, "__len must use only first return value") + assertEquals(#t, 42, "__len must use only first return value") end -- 2.2. Raw length when no array part @@ -58,7 +58,7 @@ do b = 2, } - assert_eq(#t, 0, "table with only non-integer keys has length 0") + assertEquals(#t, 0, "table with only non-integer keys has length 0") end -- 2.3. Length when both array and key-value parts @@ -72,7 +72,7 @@ do 3, } - assert_eq(#t, 3, "table with mixed non-integer and integer keys") + assertEquals(#t, 3, "table with mixed non-integer and integer keys") end -- 3. Non-strings and non-tables @@ -113,26 +113,26 @@ do __len = function(_) return 99 end, }) - assert_eq(#t, 99, "#t uses __len") - assert_eq(rawlen(t), 3, "rawlen(t) ignores __len") + assertEquals(#t, 99, "#t uses __len") + assertEquals(rawlen(t), 3, "rawlen(t) ignores __len") end -- 5. Trailing-nil shrinking behavior do local t = { 1, 2, 3 } - assert_eq(#t, 3, "initial sequence length") + assertEquals(#t, 3, "initial sequence length") t[3] = nil - assert_eq(#t, 2, "sequence length shrinks when last element is set to nil") - assert_eq(rawlen(t), 2, "rawlen shrinks with trailing nil (array part shrinks)") + assertEquals(#t, 2, "sequence length shrinks when last element is set to nil") + assertEquals(rawlen(t), 2, "rawlen shrinks with trailing nil (array part shrinks)") t[2] = nil - assert_eq(#t, 1, "sequence length shrinks again after removing new last element") - assert_eq(rawlen(t), 1, "rawlen shrinks again after trailing nil") + assertEquals(#t, 1, "sequence length shrinks again after removing new last element") + assertEquals(rawlen(t), 1, "rawlen shrinks again after trailing nil") end -- 6. rawlen on strings -assert_eq(rawlen("abc"), 3, "rawlen on strings") +assertEquals(rawlen("abc"), 3, "rawlen on strings") -- 7. rawlen(t) must ignore the __len metamethod local t = {1,2,3} diff --git a/client/space_lua/metamethods_test.lua b/client/space_lua/metamethods_test.lua index 9978f6fb..bdbb17d0 100644 --- a/client/space_lua/metamethods_test.lua +++ b/client/space_lua/metamethods_test.lua @@ -1,4 +1,4 @@ -local function assert_eq(actual, expected, message) +local function assertEquals(actual, expected, message) if actual ~= expected then error('Assertion failed: ' .. message .. ' (expected ' .. tostring(expected) @@ -6,13 +6,13 @@ local function assert_eq(actual, expected, message) end end -local function assert_true(v, message) +local function assertTrue(v, message) if v ~= true then error('Assertion failed: ' .. message .. ' (expected true)') end end -local function assert_false(v, message) +local function assertFalse(v, message) if v ~= false then error('Assertion failed: ' .. message .. ' (expected false)') end @@ -36,11 +36,6 @@ local function assertThrows(msg_substr, fn) end end -local function assert_first_only(expr_fn, expected, message) - local v = expr_fn() - assert_eq(v, expected, message) -end - -- 1. Arithmetic + bitwise metamethods: values + multi-return trimming do local mt = {} @@ -63,22 +58,22 @@ do local a = setmetatable({ tag = 'A' }, mt) local b = setmetatable({ tag = 'B' }, mt) - assert_eq(a + b, 'A+B', '__add produced correct value') - assert_eq(a - b, 'A-B', '__sub produced correct value') - assert_eq(a * b, 'A*B', '__mul produced correct value') - assert_eq(a / b, 'A/B', '__div produced correct value') - assert_eq(a ^ b, 'A^B', '__pow produced correct value') - assert_eq(a // b, 'A//B', '__idiv produced correct value') - assert_eq(a % b, 'A%B', '__mod produced correct value') + assertEquals(a + b, 'A+B', '__add produced correct value') + assertEquals(a - b, 'A-B', '__sub produced correct value') + assertEquals(a * b, 'A*B', '__mul produced correct value') + assertEquals(a / b, 'A/B', '__div produced correct value') + assertEquals(a ^ b, 'A^B', '__pow produced correct value') + assertEquals(a // b, 'A//B', '__idiv produced correct value') + assertEquals(a % b, 'A%B', '__mod produced correct value') - assert_eq(-a, '(-A)', '__unm produced correct value') - assert_eq(~a, '(~A)', '__bnot produced correct value') + assertEquals(-a, '(-A)', '__unm produced correct value') + assertEquals(~a, '(~A)', '__bnot produced correct value') - assert_eq(a & b, 'A&B', '__band produced correct value') - assert_eq(a | b, 'A|B', '__bor produced correct value') - assert_eq(a ~ b, 'A~B', '__bxor produced correct value') - assert_eq(a << b, 'A<> b, 'A>>B', '__shr produced correct value') + assertEquals(a & b, 'A&B', '__band produced correct value') + assertEquals(a | b, 'A|B', '__bor produced correct value') + assertEquals(a ~ b, 'A~B', '__bxor produced correct value') + assertEquals(a << b, 'A<> b, 'A>>B', '__shr produced correct value') -- Multi-return from metamethod: must take only the first return do @@ -92,11 +87,11 @@ do local x = setmetatable({}, mt_mr) - assert_eq(x + x, 'first', 'binary operator uses first return value') - assert_eq(-x, 7, 'unary operator uses first return value') - assert_eq(~x, 9, 'unary operator uses first return value') - assert_eq(x .. x, "c1", 'concat uses first return value') - assert_eq(#x, 123, 'len uses first return value') + assertEquals(x + x, 'first', 'binary operator uses first return value') + assertEquals(-x, 7, 'unary operator uses first return value') + assertEquals(~x, 9, 'unary operator uses first return value') + assertEquals(x .. x, "c1", 'concat uses first return value') + assertEquals(#x, 123, 'len uses first return value') end end @@ -116,18 +111,18 @@ do } local function O(v) return setmetatable({ v = v }, mt) end - assert_true(O(1) < O(2), "__lt true") - assert_false(O(2) < O(1), "__lt false") - assert_true(O(2) <= O(2), "__le true") - assert_false(O(3) <= O(2), "__le false") + assertTrue(O(1) < O(2), "__lt true") + assertFalse(O(2) < O(1), "__lt false") + assertTrue(O(2) <= O(2), "__le true") + assertFalse(O(3) <= O(2), "__le false") end -- 2.3. `__eq` semantics do do local a, b = {}, {} - assert_false(a == b, "raw equality for distinct tables without __eq is false") - assert_true(a == a, "raw equality for same table is true") + assertFalse(a == b, "raw equality for distinct tables without __eq is false") + assertTrue(a == a, "raw equality for same table is true") end do @@ -141,23 +136,23 @@ do local x = setmetatable({}, mt) local y = {} -- no metatable - assert_true(x == y, "__eq may be used from left operand metatable") - assert_true(y == x, "__eq may be used from right operand metatable") - assert_true(calls >= 1, "__eq was called at least once") + assertTrue(x == y, "__eq may be used from left operand metatable") + assertTrue(y == x, "__eq may be used from right operand metatable") + assertTrue(calls >= 1, "__eq was called at least once") end do local a = setmetatable({ v = 1 }, { __eq = function() return true end }) local b = setmetatable({ v = 2 }, { __eq = function() return true end }) - assert_true(a == b, "__eq true/true => true") - assert_false(a ~= b, "~= is negation of ==") + assertTrue(a == b, "__eq true/true => true") + assertFalse(a ~= b, "~= is negation of ==") end do local a = setmetatable({ v = 1 }, { __eq = function() return false end }) local b = setmetatable({ v = 2 }, { __eq = function() return false end }) - assert_false(a == b, "__eq false/false => false") - assert_true(a ~= b, "~= is negation of ==") + assertFalse(a == b, "__eq false/false => false") + assertTrue(a ~= b, "~= is negation of ==") end end @@ -169,9 +164,9 @@ do local a = P(3) local b = P(2) - assert_true(b < a, "sanity: b < a uses __lt") - assert_true(a > b, '">" uses swapped __lt') - assert_false(b > a, '">" uses swapped __lt (false case)') + assertTrue(b < a, "sanity: b < a uses __lt") + assertTrue(a > b, '">" uses swapped __lt') + assertFalse(b > a, '">" uses swapped __lt (false case)') end do @@ -181,9 +176,9 @@ do local a = P(3) local b = P(2) - assert_true(b <= a, "sanity: b <= a uses __le") - assert_true(a >= b, '">=" uses swapped __le') - assert_false(b >= a, '">=" uses swapped __le (false case)') + assertTrue(b <= a, "sanity: b <= a uses __le") + assertTrue(a >= b, '">=" uses swapped __le') + assertFalse(b >= a, '">=" uses swapped __le (false case)') end -- 2.5. No `__le` fallback via `__lt` in Lua for metamethod comparisons @@ -194,7 +189,7 @@ do local a = P(2) local b = P(2) - assert_false(a < b, "sanity: 2 < 2 is false via __lt") + assertFalse(a < b, "sanity: 2 < 2 is false via __lt") assertThrows("attempt to compare", function() return a <= b end) end @@ -206,29 +201,29 @@ do local function P(v) return setmetatable({ v = v }, mt) end local a = P(2) local b = P(2) - assert_true(a <= b, "__le works when provided") + assertTrue(a <= b, "__le works when provided") end end -- 3. `rawlen` vs `#` when `__len` exists do local t = setmetatable({ 1, 2, 3 }, { __len = function() return 10 end }) - assert_eq(#t, 10, '# uses __len') - assert_eq(rawlen(t), 3, 'rawlen ignores __len on tables') - assert_eq(rawlen("abc"), 3, 'rawlen works on strings') + assertEquals(#t, 10, '# uses __len') + assertEquals(rawlen(t), 3, 'rawlen ignores __len on tables') + assertEquals(rawlen("abc"), 3, 'rawlen works on strings') end -- 4. `__len`: tables use metamethod; strings are raw length do local t = setmetatable({ x = 20 }, { __len = function(tt) return tt.x end }) - assert_eq(#t, 20, '__len dispatched for tables') + assertEquals(#t, 20, '__len dispatched for tables') t.x = "234" - assert_eq(#t, "234", '__len can return non-number') + assertEquals(#t, "234", '__len can return non-number') end do local s = "abc" - assert_eq(#s, 3, 'strings ignore __len metamethod') + assertEquals(#s, 3, 'strings ignore __len metamethod') end -- 5. `__concat`: produced value and number/table interop @@ -236,7 +231,7 @@ do local a = setmetatable({ x = "u" }, { __concat = function(l, r) return l.x .. "." .. r.x end }) - assert_eq(a .. a, "u.u", '__concat dispatched') + assertEquals(a .. a, "u.u", '__concat dispatched') end do @@ -244,27 +239,27 @@ do setmetatable(c, { __concat = function(a, b) if type(a) == "number" then - assert_eq(b, c, '__concat rhs is c when lhs number') + assertEquals(b, c, '__concat rhs is c when lhs number') return "n..c" else - assert_eq(a, c, '__concat lhs is c when rhs number') + assertEquals(a, c, '__concat lhs is c when rhs number') return "c..n" end end }) - assert_eq(c .. 5, "c..n", "__concat handles table .. number") - assert_eq(5 .. c, "n..c", "__concat handles number .. table") + assertEquals(c .. 5, "c..n", "__concat handles table .. number") + assertEquals(5 .. c, "n..c", "__concat handles number .. table") end -- 6. `__call`: produced values do local t = setmetatable({}, { __call = function(self, a, b) - assert_eq(type(self), 'table', '__call self is table') + assertEquals(type(self), 'table', '__call self is table') return a + b end }) - assert_eq(t(2, 3), 5, '__call dispatched') + assertEquals(t(2, 3), 5, '__call dispatched') end do @@ -274,9 +269,9 @@ do end }) local a, b, n = t(10, 20) - assert_eq(a, "a", "__call multi-return first") - assert_eq(b, "b", "__call multi-return second") - assert_eq(n, 2, "__call sees arguments") + assertEquals(a, "a", "__call multi-return first") + assertEquals(b, "b", "__call multi-return second") + assertEquals(n, 2, "__call sees arguments") end do @@ -292,7 +287,7 @@ do f = setmetatable({}, { __call = f }) end - assert_eq(f(), 1023, 'chain of __call metamethods works') + assertEquals(f(), 1023, 'chain of __call metamethods works') end do @@ -310,10 +305,10 @@ do local c = setmetatable({ f = b }, tt) local x = c(3, 4, 5) - assert_eq(i, 3, "__call nested chain increments i") - assert_eq(x[1], 3, "__call nested chain arg1") - assert_eq(x[2], 4, "__call nested chain arg2") - assert_eq(x[3], 5, "__call nested chain arg3") + assertEquals(i, 3, "__call nested chain increments i") + assertEquals(x[1], 3, "__call nested chain arg1") + assertEquals(x[2], 4, "__call nested chain arg2") + assertEquals(x[3], 5, "__call nested chain arg3") end do @@ -331,17 +326,17 @@ do __newindex = function(_, k, v) backing[k] = v end, }) - assert_eq(t.x, 10, '__index function dispatched') + assertEquals(t.x, 10, '__index function dispatched') t.y = 20 - assert_eq(backing.y, 20, '__newindex function dispatched') + assertEquals(backing.y, 20, '__newindex function dispatched') end do local backing = { a = 1, b = 2 } local t = setmetatable({}, { __index = backing }) - assert_eq(t.a, 1, '__index table dispatched (a)') - assert_eq(t.b, 2, '__index table dispatched (b)') - assert_eq(t.c, nil, '__index table missing key yields nil') + assertEquals(t.a, 1, '__index table dispatched (a)') + assertEquals(t.b, 2, '__index table dispatched (b)') + assertEquals(t.c, nil, '__index table missing key yields nil') end do @@ -349,7 +344,7 @@ do local backing = {} local t = setmetatable({}, { __newindex = backing }) t.k = 99 - assert_eq(backing.k, 99, '__newindex table dispatched') + assertEquals(backing.k, 99, '__newindex table dispatched') end do @@ -363,11 +358,11 @@ do }) t.present = 2 - assert_eq(calls, 0, '__newindex not called for existing key') + assertEquals(calls, 0, '__newindex not called for existing key') t.absent = 3 - assert_eq(calls, 1, '__newindex called for absent key') - assert_eq(t.absent, 3, '__newindex stored value') + assertEquals(calls, 1, '__newindex called for absent key') + assertEquals(t.absent, 3, '__newindex stored value') end do @@ -391,7 +386,7 @@ do local out = {} local function foo(e, i) - assert_eq(e, a, "__pairs sees original table") + assertEquals(e, a, "__pairs sees original table") if i < 10 then return i + 1, i + 2 end @@ -405,11 +400,11 @@ do out[i] = { k, v } end - assert_eq(i, 10, "__pairs loop count") - assert_eq(out[1][1], 1, "__pairs k1") - assert_eq(out[1][2], 2, "__pairs v1") - assert_eq(out[10][1], 10, "__pairs k10") - assert_eq(out[10][2], 11, "__pairs v10") + assertEquals(i, 10, "__pairs loop count") + assertEquals(out[1][1], 1, "__pairs k1") + assertEquals(out[1][2], 2, "__pairs v1") + assertEquals(out[10][1], 10, "__pairs k10") + assertEquals(out[10][2], 11, "__pairs v10") end do @@ -427,9 +422,9 @@ do out[#out + 1] = k .. ":" .. v end - assert_eq(#out, 5, "ipairs iterates n entries via __index") - assert_eq(out[1], "1:10", "ipairs entry 1") - assert_eq(out[5], "5:50", "ipairs entry 5") + assertEquals(#out, 5, "ipairs iterates n entries via __index") + assertEquals(out[1], "1:10", "ipairs entry 1") + assertEquals(out[5], "5:50", "ipairs entry 5") end -- 9. `table` library interaction with metamethods @@ -438,31 +433,31 @@ do for i = 1, 10 do table.insert(proxy, 1, i) end - assert_eq(#proxy, 10, "proxy length after inserts") - assert_eq(#backing, 10, "backing length after inserts") + assertEquals(#proxy, 10, "proxy length after inserts") + assertEquals(#backing, 10, "backing length after inserts") for i = 1, 10 do - assert_eq(backing[i], 11 - i, "backing reversed insert " .. i) + assertEquals(backing[i], 11 - i, "backing reversed insert " .. i) end table.sort(proxy) for i = 1, 10 do - assert_eq(backing[i], i, "backing sorted " .. i) - assert_eq(proxy[i], i, "proxy sorted " .. i) + assertEquals(backing[i], i, "backing sorted " .. i) + assertEquals(proxy[i], i, "proxy sorted " .. i) end - assert_eq(table.concat(proxy, ","), "1,2,3,4,5,6,7,8,9,10", "table.concat(proxy)") + assertEquals(table.concat(proxy, ","), "1,2,3,4,5,6,7,8,9,10", "table.concat(proxy)") for i = 1, 8 do - assert_eq(table.remove(proxy, 1), i, "table.remove(proxy,1) yields i") + assertEquals(table.remove(proxy, 1), i, "table.remove(proxy,1) yields i") end - assert_eq(#proxy, 2, "proxy length after removes") - assert_eq(#backing, 2, "backing length after removes") + assertEquals(#proxy, 2, "proxy length after removes") + assertEquals(#backing, 2, "backing length after removes") local a, b, c = table.unpack(proxy) - assert_eq(a, 9, "table.unpack(proxy) first") - assert_eq(b, 10, "table.unpack(proxy) second") - assert_eq(c, nil, "table.unpack(proxy) third nil") + assertEquals(a, 9, "table.unpack(proxy) first") + assertEquals(b, 10, "table.unpack(proxy) second") + assertEquals(c, nil, "table.unpack(proxy) third nil") end local backing = {} @@ -485,9 +480,9 @@ do local c = setmetatable({}, mt1) local d = setmetatable({}, mt1) - assert_true(c == d, "comparison compat: __eq true (same mt)") - assert_true(c < d, "comparison compat: __lt true (same mt)") - assert_false(d <= c, "comparison compat: __le false (same mt)") + assertTrue(c == d, "comparison compat: __eq true (same mt)") + assertTrue(c < d, "comparison compat: __lt true (same mt)") + assertFalse(d <= c, "comparison compat: __le false (same mt)") local mt2 = { __eq = mt1.__eq, @@ -497,9 +492,9 @@ do local e = setmetatable({}, mt1) local f = setmetatable({}, mt2) - assert_true(e == f, "comparison compat across metatables: __eq") - assert_true(e < f, "comparison compat across metatables: __lt") - assert_false(f <= e, "comparison compat across metatables: __le") + assertTrue(e == f, "comparison compat across metatables: __eq") + assertTrue(e < f, "comparison compat across metatables: __lt") + assertFalse(f <= e, "comparison compat across metatables: __le") end -- 11. Concat chain associativity + returning table from `__concat` @@ -515,8 +510,8 @@ do local d = setmetatable({ val = "d" }, t) local x = c .. d .. c .. d - assert_eq(type(x), "table", "__concat chain returns table") - assert_eq(x.val, "cdcd", "__concat chain value") + assertEquals(type(x), "table", "__concat chain returns table") + assertEquals(x.val, "cdcd", "__concat chain value") end -- 12. `__eq` is not used for table indexing / hashing @@ -533,14 +528,14 @@ do local k1 = Set{1, 2, 3} local k2 = Set{1, 2, 3} - assert_true(k1 == k2, "__eq says equal") - assert_false(rawequal(k1, k2), "not the same object") + assertTrue(k1 == k2, "__eq says equal") + assertFalse(rawequal(k1, k2), "not the same object") local t = {} t[k1] = 123 - assert_eq(t[k2], nil, "table indexing ignores __eq") - assert_eq(t[k1], 123, "table indexing by same object works") + assertEquals(t[k2], nil, "table indexing ignores __eq") + assertEquals(t[k1], 123, "table indexing by same object works") end -- 13. operator metamethod lookup must be raw (no `__index` involvement) @@ -563,7 +558,7 @@ do local m = setmetatable({ name = "NAME" }, { __tostring = function(x) return x.name end }) - assert_eq(tostring(m), "NAME", "__tostring used by tostring()") + assertEquals(tostring(m), "NAME", "__tostring used by tostring()") end do diff --git a/client/space_lua/query_test.lua b/client/space_lua/query_test.lua index 7cc056fc..f60107a5 100644 --- a/client/space_lua/query_test.lua +++ b/client/space_lua/query_test.lua @@ -1,4 +1,4 @@ -local function assert_equal(a, b) +local function assertEquals(a, b) if a ~= b then error("Assertion failed: " .. a .. " is not equal to " .. b) end @@ -9,39 +9,39 @@ local data = { { name = "John", lastModified = 1, age = 20 }, { name = "Jane", l -- Basic limit query local r = query [[from p = data limit 1]] -assert_equal(#r, 1) -assert_equal(r[1].name, "John") -assert_equal(r[1].lastModified, 1) +assertEquals(#r, 1) +assertEquals(r[1].name, "John") +assertEquals(r[1].lastModified, 1) -- Order by descending local r = query [[from p = data order by p.lastModified desc]] -assert_equal(#r, 2) -assert_equal(r[1].name, "Jane") -assert_equal(r[1].lastModified, 2) -assert_equal(r[2].name, "John") -assert_equal(r[2].lastModified, 1) +assertEquals(#r, 2) +assertEquals(r[1].name, "Jane") +assertEquals(r[1].lastModified, 2) +assertEquals(r[2].name, "John") +assertEquals(r[2].lastModified, 1) -- Order by ascending local r = query [[from p = data order by p.lastModified]] -assert_equal(#r, 2) -assert_equal(r[1].name, "John") -assert_equal(r[1].lastModified, 1) -assert_equal(r[2].name, "Jane") -assert_equal(r[2].lastModified, 2) +assertEquals(#r, 2) +assertEquals(r[1].name, "John") +assertEquals(r[1].lastModified, 1) +assertEquals(r[2].name, "Jane") +assertEquals(r[2].lastModified, 2) -- Select specific fields local r = query [[from p = data order by p.age select {name=p.name, age=p.age}]] -assert_equal(#r, 2) -assert_equal(r[1].name, "John") -assert_equal(r[1].age, 20) -assert_equal(r[2].name, "Jane") -assert_equal(r[2].age, 21) -assert_equal(r[1].lastModified, nil) -assert_equal(r[2].lastModified, nil) +assertEquals(#r, 2) +assertEquals(r[1].name, "John") +assertEquals(r[1].age, 20) +assertEquals(r[2].name, "Jane") +assertEquals(r[2].age, 21) +assertEquals(r[1].lastModified, nil) +assertEquals(r[2].lastModified, nil) -- Array transformation local r = query [[from {1, 2, 3} select _ + 1]] -assert_equal(#r, 3) -assert_equal(r[1], 2) -assert_equal(r[2], 3) -assert_equal(r[3], 4) \ No newline at end of file +assertEquals(#r, 3) +assertEquals(r[1], 2) +assertEquals(r[2], 3) +assertEquals(r[3], 4) \ No newline at end of file diff --git a/client/space_lua/stdlib/format_test.lua b/client/space_lua/stdlib/format_test.lua index dc5220d3..bae48055 100644 --- a/client/space_lua/stdlib/format_test.lua +++ b/client/space_lua/stdlib/format_test.lua @@ -1,4 +1,4 @@ -local function assert_eq(actual, expected, message) +local function assertEquals(actual, expected, message) if actual ~= expected then error('Assertion failed: ' .. message .. '\n actual: ' .. tostring(actual) @@ -22,357 +22,357 @@ local function assertThrows(msg_substr, fn) end -- %%: literal percent -assert_eq(string.format("%%"), "%", "%%: literal") -assert_eq(string.format("100%%"), "100%", "%%: 100%%") -assert_eq(string.format("%%%%"), "%%", "%%: %%%%") -assert_eq(string.format("a%%b%%c"), "a%b%c", "%%: a%%b%%c") +assertEquals(string.format("%%"), "%", "%%: literal") +assertEquals(string.format("100%%"), "100%", "%%: 100%%") +assertEquals(string.format("%%%%"), "%%", "%%: %%%%") +assertEquals(string.format("a%%b%%c"), "a%b%c", "%%: a%%b%%c") -- %d: basic integers -assert_eq(string.format("%d", 0), "0", "%d: 0") -assert_eq(string.format("%d", 1), "1", "%d: 1") -assert_eq(string.format("%d", -1), "-1", "%d: -1") -assert_eq(string.format("%d", 42), "42", "%d: 42") -assert_eq(string.format("%d", -42), "-42", "%d: -42") -assert_eq(string.format("%d", 2147483647), "2147483647", "%d: INT_MAX") -assert_eq(string.format("%d", -2147483648), "-2147483648", "%d: INT_MIN") +assertEquals(string.format("%d", 0), "0", "%d: 0") +assertEquals(string.format("%d", 1), "1", "%d: 1") +assertEquals(string.format("%d", -1), "-1", "%d: -1") +assertEquals(string.format("%d", 42), "42", "%d: 42") +assertEquals(string.format("%d", -42), "-42", "%d: -42") +assertEquals(string.format("%d", 2147483647), "2147483647", "%d: INT_MAX") +assertEquals(string.format("%d", -2147483648), "-2147483648", "%d: INT_MIN") -- %i: alias for %d -assert_eq(string.format("%i", 42), "42", "%i: 42") -assert_eq(string.format("%i", -7), "-7", "%i: -7") +assertEquals(string.format("%i", 42), "42", "%i: 42") +assertEquals(string.format("%i", -7), "-7", "%i: -7") -- %d: width -assert_eq(string.format("%5d", 42), " 42", "%d: width 5") -assert_eq(string.format("%5d", -42), " -42", "%d: width 5 neg") -assert_eq(string.format("%1d", 42), "42", "%d: width 1 no pad") +assertEquals(string.format("%5d", 42), " 42", "%d: width 5") +assertEquals(string.format("%5d", -42), " -42", "%d: width 5 neg") +assertEquals(string.format("%1d", 42), "42", "%d: width 1 no pad") -- %d: left-justify -assert_eq(string.format("%-5d", 42), "42 ", "%d: left 42") -assert_eq(string.format("%-5d", -42), "-42 ", "%d: left -42") +assertEquals(string.format("%-5d", 42), "42 ", "%d: left 42") +assertEquals(string.format("%-5d", -42), "-42 ", "%d: left -42") -- %d: zero-pad -assert_eq(string.format("%05d", 42), "00042", "%d: zero-pad 42") -assert_eq(string.format("%05d", -42), "-0042", "%d: zero-pad -42") -assert_eq(string.format("%05d", 0), "00000", "%d: zero-pad 0") +assertEquals(string.format("%05d", 42), "00042", "%d: zero-pad 42") +assertEquals(string.format("%05d", -42), "-0042", "%d: zero-pad -42") +assertEquals(string.format("%05d", 0), "00000", "%d: zero-pad 0") -- %d: plus flag -assert_eq(string.format("%+d", 42), "+42", "%d: +42") -assert_eq(string.format("%+d", -42), "-42", "%d: + -42") -assert_eq(string.format("%+d", 0), "+0", "%d: +0") +assertEquals(string.format("%+d", 42), "+42", "%d: +42") +assertEquals(string.format("%+d", -42), "-42", "%d: + -42") +assertEquals(string.format("%+d", 0), "+0", "%d: +0") -- %d: space flag -assert_eq(string.format("% d", 42), " 42", "%d: space 42") -assert_eq(string.format("% d", -42), "-42", "%d: space -42") -assert_eq(string.format("% d", 0), " 0", "%d: space 0") +assertEquals(string.format("% d", 42), " 42", "%d: space 42") +assertEquals(string.format("% d", -42), "-42", "%d: space -42") +assertEquals(string.format("% d", 0), " 0", "%d: space 0") -- %d: precision -assert_eq(string.format("%.5d", 42), "00042", "%d: prec5 42") -assert_eq(string.format("%.5d", -42), "-00042", "%d: prec5 -42") -assert_eq(string.format("%.0d", 0), "", "%d: prec0 0") -assert_eq(string.format("%.0d", 1), "1", "%d: prec0 1") -assert_eq(string.format("%.1d", 0), "0", "%d: prec1 0") +assertEquals(string.format("%.5d", 42), "00042", "%d: prec5 42") +assertEquals(string.format("%.5d", -42), "-00042", "%d: prec5 -42") +assertEquals(string.format("%.0d", 0), "", "%d: prec0 0") +assertEquals(string.format("%.0d", 1), "1", "%d: prec0 1") +assertEquals(string.format("%.1d", 0), "0", "%d: prec1 0") -- %d: width and precision -assert_eq(string.format("%8.5d", 42), " 00042", "%d: w8 p5 42") -assert_eq(string.format("%-8.5d", 42), "00042 ", "%d: left w8 p5 42") +assertEquals(string.format("%8.5d", 42), " 00042", "%d: w8 p5 42") +assertEquals(string.format("%-8.5d", 42), "00042 ", "%d: left w8 p5 42") -- %u: unsigned integers -assert_eq(string.format("%u", 0), "0", "%u: 0") -assert_eq(string.format("%u", 42), "42", "%u: 42") -assert_eq(string.format("%u", -1), "18446744073709551615", "%u: -1") -assert_eq(string.format("%u", -42), "18446744073709551574", "%u: -42") +assertEquals(string.format("%u", 0), "0", "%u: 0") +assertEquals(string.format("%u", 42), "42", "%u: 42") +assertEquals(string.format("%u", -1), "18446744073709551615", "%u: -1") +assertEquals(string.format("%u", -42), "18446744073709551574", "%u: -42") -- %o: octal -assert_eq(string.format("%o", 0), "0", "%o: 0") -assert_eq(string.format("%o", 8), "10", "%o: 8") -assert_eq(string.format("%o", 255), "377", "%o: 255") -assert_eq(string.format("%o", -1), "1777777777777777777777", "%o: -1") +assertEquals(string.format("%o", 0), "0", "%o: 0") +assertEquals(string.format("%o", 8), "10", "%o: 8") +assertEquals(string.format("%o", 255), "377", "%o: 255") +assertEquals(string.format("%o", -1), "1777777777777777777777", "%o: -1") -- %o: alt flag -assert_eq(string.format("%#o", 0), "0", "%#o: 0") -assert_eq(string.format("%#o", 8), "010", "%#o: 8") -assert_eq(string.format("%#o", 255), "0377", "%#o: 255") +assertEquals(string.format("%#o", 0), "0", "%#o: 0") +assertEquals(string.format("%#o", 8), "010", "%#o: 8") +assertEquals(string.format("%#o", 255), "0377", "%#o: 255") -- %x: hex lowercase -assert_eq(string.format("%x", 0), "0", "%x: 0") -assert_eq(string.format("%x", 255), "ff", "%x: 255") -assert_eq(string.format("%x", 4095), "fff", "%x: 4095") -assert_eq(string.format("%x", -1), "ffffffffffffffff", "%x: -1") +assertEquals(string.format("%x", 0), "0", "%x: 0") +assertEquals(string.format("%x", 255), "ff", "%x: 255") +assertEquals(string.format("%x", 4095), "fff", "%x: 4095") +assertEquals(string.format("%x", -1), "ffffffffffffffff", "%x: -1") -- %X: hex uppercase -assert_eq(string.format("%X", 255), "FF", "%X: 255") -assert_eq(string.format("%X", -1), "FFFFFFFFFFFFFFFF", "%X: -1") +assertEquals(string.format("%X", 255), "FF", "%X: 255") +assertEquals(string.format("%X", -1), "FFFFFFFFFFFFFFFF", "%X: -1") -- %x: alt flag -assert_eq(string.format("%#x", 0), "0", "%#x: 0") -assert_eq(string.format("%#x", 255), "0xff", "%#x: 255") -assert_eq(string.format("%#X", 255), "0XFF", "%#X: 255") +assertEquals(string.format("%#x", 0), "0", "%#x: 0") +assertEquals(string.format("%#x", 255), "0xff", "%#x: 255") +assertEquals(string.format("%#X", 255), "0XFF", "%#X: 255") -- %x: width and zero-pad -assert_eq(string.format("%08x", 255), "000000ff", "%x: zero-pad 255") -assert_eq(string.format("%#08x", 255), "0x0000ff", "%#x: zero-pad 255") +assertEquals(string.format("%08x", 255), "000000ff", "%x: zero-pad 255") +assertEquals(string.format("%#08x", 255), "0x0000ff", "%#x: zero-pad 255") -- %c: character -assert_eq(string.format("%c", 65), "A", "%c: 65") -assert_eq(string.format("%c", 97), "a", "%c: 97") -assert_eq(string.format("%c", 48), "0", "%c: 48") +assertEquals(string.format("%c", 65), "A", "%c: 65") +assertEquals(string.format("%c", 97), "a", "%c: 97") +assertEquals(string.format("%c", 48), "0", "%c: 48") -- %c: width -assert_eq(string.format("%3c", 65), " A", "%c: width 3") -assert_eq(string.format("%-3c", 65), "A ", "%c: left width 3") +assertEquals(string.format("%3c", 65), " A", "%c: width 3") +assertEquals(string.format("%-3c", 65), "A ", "%c: left width 3") -- %s: strings -assert_eq(string.format("%s", "hello"), "hello", "%s: hello") -assert_eq(string.format("%s", ""), "", "%s: empty") -assert_eq(string.format("%s %s", "hello", "world"), "hello world", "%s: two") +assertEquals(string.format("%s", "hello"), "hello", "%s: hello") +assertEquals(string.format("%s", ""), "", "%s: empty") +assertEquals(string.format("%s %s", "hello", "world"), "hello world", "%s: two") -- %s: width -assert_eq(string.format("%10s", "hello"), " hello", "%s: width 10") -assert_eq(string.format("%-10s", "hello"), "hello ", "%s: left width 10") +assertEquals(string.format("%10s", "hello"), " hello", "%s: width 10") +assertEquals(string.format("%-10s", "hello"), "hello ", "%s: left width 10") -- %s: precision truncates -assert_eq(string.format("%.3s", "hello"), "hel", "%s: prec3") -assert_eq(string.format("%.10s", "hello"), "hello", "%s: prec10") -assert_eq(string.format("%.0s", "hello"), "", "%s: prec0") +assertEquals(string.format("%.3s", "hello"), "hel", "%s: prec3") +assertEquals(string.format("%.10s", "hello"), "hello", "%s: prec10") +assertEquals(string.format("%.0s", "hello"), "", "%s: prec0") -- %s: width and precision -assert_eq(string.format("%10.3s", "hello"), " hel", "%s: w10 p3") -assert_eq(string.format("%-10.3s", "hello"), "hel ", "%s: left w10 p3") +assertEquals(string.format("%10.3s", "hello"), " hel", "%s: w10 p3") +assertEquals(string.format("%-10.3s", "hello"), "hel ", "%s: left w10 p3") -- %f: basic floats -assert_eq(string.format("%f", 0), "0.000000", "%f: 0") -assert_eq(string.format("%f", 1), "1.000000", "%f: 1") -assert_eq(string.format("%f", -1), "-1.000000", "%f: -1") -assert_eq(string.format("%f", 3.14), "3.140000", "%f: 3.14") -assert_eq(string.format("%f", 0.1), "0.100000", "%f: 0.1") +assertEquals(string.format("%f", 0), "0.000000", "%f: 0") +assertEquals(string.format("%f", 1), "1.000000", "%f: 1") +assertEquals(string.format("%f", -1), "-1.000000", "%f: -1") +assertEquals(string.format("%f", 3.14), "3.140000", "%f: 3.14") +assertEquals(string.format("%f", 0.1), "0.100000", "%f: 0.1") -- %f: precision -assert_eq(string.format("%.2f", 3.14159), "3.14", "%f: prec2") -assert_eq(string.format("%.0f", 3.14159), "3", "%f: prec0") -assert_eq(string.format("%.10f", 1.0), "1.0000000000", "%f: prec10") +assertEquals(string.format("%.2f", 3.14159), "3.14", "%f: prec2") +assertEquals(string.format("%.0f", 3.14159), "3", "%f: prec0") +assertEquals(string.format("%.10f", 1.0), "1.0000000000", "%f: prec10") -- %f: width and precision -assert_eq(string.format("%10.2f", 3.14), " 3.14", "%f: w10 p2") -assert_eq(string.format("%-10.2f", 3.14), "3.14 ", "%f: left w10 p2") -assert_eq(string.format("%010.2f", 3.14), "0000003.14", "%f: zero-pad w10 p2") +assertEquals(string.format("%10.2f", 3.14), " 3.14", "%f: w10 p2") +assertEquals(string.format("%-10.2f", 3.14), "3.14 ", "%f: left w10 p2") +assertEquals(string.format("%010.2f", 3.14), "0000003.14", "%f: zero-pad w10 p2") -- %f: sign flags -assert_eq(string.format("%+f", 3.14), "+3.140000", "%f: +3.14") -assert_eq(string.format("%+f", -3.14), "-3.140000", "%f: + -3.14") -assert_eq(string.format("% f", 3.14), " 3.140000", "%f: space 3.14") -assert_eq(string.format("% f", -3.14), "-3.140000", "%f: space -3.14") +assertEquals(string.format("%+f", 3.14), "+3.140000", "%f: +3.14") +assertEquals(string.format("%+f", -3.14), "-3.140000", "%f: + -3.14") +assertEquals(string.format("% f", 3.14), " 3.140000", "%f: space 3.14") +assertEquals(string.format("% f", -3.14), "-3.140000", "%f: space -3.14") -- %f: non-finite -assert_eq(string.format("%f", 1/0), "inf", "%f: inf") -assert_eq(string.format("%f", -1/0), "-inf", "%f: -inf") -assert_eq(string.format("%f", 0/0), "-nan", "%f: nan") -assert_eq(string.format("%+f", 1/0), "+inf", "%f: +inf") +assertEquals(string.format("%f", 1/0), "inf", "%f: inf") +assertEquals(string.format("%f", -1/0), "-inf", "%f: -inf") +assertEquals(string.format("%f", 0/0), "-nan", "%f: nan") +assertEquals(string.format("%+f", 1/0), "+inf", "%f: +inf") -- %f: width with non-finite -assert_eq(string.format("%10f", 1/0), " inf", "%f: w10 inf") -assert_eq(string.format("%-10f", 1/0), "inf ", "%f: left w10 inf") +assertEquals(string.format("%10f", 1/0), " inf", "%f: w10 inf") +assertEquals(string.format("%-10f", 1/0), "inf ", "%f: left w10 inf") -- %e: basic -assert_eq(string.format("%e", 0), "0.000000e+00", "%e: 0") -assert_eq(string.format("%e", 1), "1.000000e+00", "%e: 1") -assert_eq(string.format("%e", 100), "1.000000e+02", "%e: 100") -assert_eq(string.format("%e", 0.001), "1.000000e-03", "%e: 0.001") -assert_eq(string.format("%e", -42), "-4.200000e+01", "%e: -42") +assertEquals(string.format("%e", 0), "0.000000e+00", "%e: 0") +assertEquals(string.format("%e", 1), "1.000000e+00", "%e: 1") +assertEquals(string.format("%e", 100), "1.000000e+02", "%e: 100") +assertEquals(string.format("%e", 0.001), "1.000000e-03", "%e: 0.001") +assertEquals(string.format("%e", -42), "-4.200000e+01", "%e: -42") -- %E: uppercase -assert_eq(string.format("%E", 100), "1.000000E+02", "%E: 100") +assertEquals(string.format("%E", 100), "1.000000E+02", "%E: 100") -- %e: precision -assert_eq(string.format("%.2e", 100), "1.00e+02", "%e: prec2") -assert_eq(string.format("%.0e", 100), "1e+02", "%e: prec0") -assert_eq(string.format("%.14e", 1), "1.00000000000000e+00", "%e: prec14") +assertEquals(string.format("%.2e", 100), "1.00e+02", "%e: prec2") +assertEquals(string.format("%.0e", 100), "1e+02", "%e: prec0") +assertEquals(string.format("%.14e", 1), "1.00000000000000e+00", "%e: prec14") -- %e: non-finite -assert_eq(string.format("%e", 1/0), "inf", "%e: inf") -assert_eq(string.format("%e", -1/0), "-inf", "%e: -inf") -assert_eq(string.format("%e", 0/0), "-nan", "%e: nan") +assertEquals(string.format("%e", 1/0), "inf", "%e: inf") +assertEquals(string.format("%e", -1/0), "-inf", "%e: -inf") +assertEquals(string.format("%e", 0/0), "-nan", "%e: nan") -- %e: width and flags -assert_eq(string.format("%15e", 100), " 1.000000e+02", "%e: w15") -assert_eq(string.format("%-15e", 100), "1.000000e+02 ", "%e: left w15") -assert_eq(string.format("%+e", 100), "+1.000000e+02", "%e: +100") +assertEquals(string.format("%15e", 100), " 1.000000e+02", "%e: w15") +assertEquals(string.format("%-15e", 100), "1.000000e+02 ", "%e: left w15") +assertEquals(string.format("%+e", 100), "+1.000000e+02", "%e: +100") -- %g: basic -assert_eq(string.format("%g", 0), "0", "%g: 0") -assert_eq(string.format("%g", 1), "1", "%g: 1") -assert_eq(string.format("%g", 100), "100", "%g: 100") -assert_eq(string.format("%g", 100000), "100000", "%g: 100000") -assert_eq(string.format("%g", 1000000), "1e+06", "%g: 1000000") -assert_eq(string.format("%g", 0.0001), "0.0001", "%g: 0.0001") -assert_eq(string.format("%g", 0.00001), "1e-05", "%g: 0.00001") -assert_eq(string.format("%g", -42), "-42", "%g: -42") +assertEquals(string.format("%g", 0), "0", "%g: 0") +assertEquals(string.format("%g", 1), "1", "%g: 1") +assertEquals(string.format("%g", 100), "100", "%g: 100") +assertEquals(string.format("%g", 100000), "100000", "%g: 100000") +assertEquals(string.format("%g", 1000000), "1e+06", "%g: 1000000") +assertEquals(string.format("%g", 0.0001), "0.0001", "%g: 0.0001") +assertEquals(string.format("%g", 0.00001), "1e-05", "%g: 0.00001") +assertEquals(string.format("%g", -42), "-42", "%g: -42") -- %G: uppercase -assert_eq(string.format("%G", 1e6), "1E+06", "%G: 1e6") -assert_eq(string.format("%G", 1e-5), "1E-05", "%G: 1e-5") +assertEquals(string.format("%G", 1e6), "1E+06", "%G: 1e6") +assertEquals(string.format("%G", 1e-5), "1E-05", "%G: 1e-5") -- %g: precision -assert_eq(string.format("%.1g", 3.14), "3", "%g: prec1") -assert_eq(string.format("%.2g", 3.14), "3.1", "%g: prec2") -assert_eq(string.format("%.4g", 3.14159), "3.142", "%g: prec4") -assert_eq(string.format("%.0g", 3.14), "3", "%g: prec0") -assert_eq(string.format("%.10g", 1), "1", "%g: prec10 int") +assertEquals(string.format("%.1g", 3.14), "3", "%g: prec1") +assertEquals(string.format("%.2g", 3.14), "3.1", "%g: prec2") +assertEquals(string.format("%.4g", 3.14159), "3.142", "%g: prec4") +assertEquals(string.format("%.0g", 3.14), "3", "%g: prec0") +assertEquals(string.format("%.10g", 1), "1", "%g: prec10 int") -- %g: strips trailing zeros -assert_eq(string.format("%.6g", 1.0), "1", "%g: strip 1.0") -assert_eq(string.format("%.6g", 1.5), "1.5", "%g: strip 1.5") -assert_eq(string.format("%.6g", 1.50), "1.5", "%g: strip 1.50") -assert_eq(string.format("%.14g", 1.0), "1", "%g: strip prec14 1.0") -assert_eq(string.format("%.14g", 1.5), "1.5", "%g: strip prec14 1.5") +assertEquals(string.format("%.6g", 1.0), "1", "%g: strip 1.0") +assertEquals(string.format("%.6g", 1.5), "1.5", "%g: strip 1.5") +assertEquals(string.format("%.6g", 1.50), "1.5", "%g: strip 1.50") +assertEquals(string.format("%.14g", 1.0), "1", "%g: strip prec14 1.0") +assertEquals(string.format("%.14g", 1.5), "1.5", "%g: strip prec14 1.5") -- %g: alt flag keeps trailing zeros and dot -assert_eq(string.format("%#g", 1.0), "1.00000", "%#g: 1.0") -assert_eq(string.format("%#.2g", 1.0), "1.0", "%#g: prec2 1.0") -assert_eq(string.format("%#.4g", 100), "100.0", "%#g: prec4 100") +assertEquals(string.format("%#g", 1.0), "1.00000", "%#g: 1.0") +assertEquals(string.format("%#.2g", 1.0), "1.0", "%#g: prec2 1.0") +assertEquals(string.format("%#.4g", 100), "100.0", "%#g: prec4 100") -- %g: non-finite -assert_eq(string.format("%g", 1/0), "inf", "%g: inf") -assert_eq(string.format("%g", -1/0), "-inf", "%g: -inf") -assert_eq(string.format("%g", 0/0), "-nan", "%g: nan") -assert_eq(string.format("%+g", 1/0), "+inf", "%g: +inf") +assertEquals(string.format("%g", 1/0), "inf", "%g: inf") +assertEquals(string.format("%g", -1/0), "-inf", "%g: -inf") +assertEquals(string.format("%g", 0/0), "-nan", "%g: nan") +assertEquals(string.format("%+g", 1/0), "+inf", "%g: +inf") -- %g: width and flags -assert_eq(string.format("%10g", 42), " 42", "%g: w10 42") -assert_eq(string.format("%-10g", 42), "42 ", "%g: left w10 42") -assert_eq(string.format("%010g", 42), "0000000042", "%g: zero-pad w10 42") -assert_eq(string.format("%+g", 42), "+42", "%g: +42") -assert_eq(string.format("% g", 42), " 42", "%g: space 42") +assertEquals(string.format("%10g", 42), " 42", "%g: w10 42") +assertEquals(string.format("%-10g", 42), "42 ", "%g: left w10 42") +assertEquals(string.format("%010g", 42), "0000000042", "%g: zero-pad w10 42") +assertEquals(string.format("%+g", 42), "+42", "%g: +42") +assertEquals(string.format("% g", 42), " 42", "%g: space 42") -- %g: Lua 5.4 %.14g reference values -assert_eq(string.format("%.14g", 0.0), "0", "%.14g: 0.0") -assert_eq(string.format("%.14g", 1.0), "1", "%.14g: 1.0") -assert_eq(string.format("%.14g", 1/3), "0.33333333333333", "%.14g: 1/3") -assert_eq(string.format("%.14g", math.pi), "3.1415926535898", "%.14g: pi") -assert_eq(string.format("%.14g", 1e-10), "1e-10", "%.14g: 1e-10") -assert_eq(string.format("%.14g", 1e18), "1e+18", "%.14g: 1e18") -assert_eq(string.format("%.14g", 2^63), "9.2233720368548e+18", "%.14g: 2^63") -assert_eq(string.format("%.14g", 2^53), "9.007199254741e+15", "%.14g: 2^53") -assert_eq(string.format("%.14g", 1.7976931348623e+308), "1.7976931348623e+308", "%.14g: max") -assert_eq(string.format("%.14g", 5e-324), "4.9406564584125e-324", "%.14g: min subnormal") -assert_eq(string.format("%.14g", 0/0), "-nan", "%.14g: nan") -assert_eq(string.format("%.14g", 1/0), "inf", "%.14g: inf") -assert_eq(string.format("%.14g", -1/0), "-inf", "%.14g: -inf") +assertEquals(string.format("%.14g", 0.0), "0", "%.14g: 0.0") +assertEquals(string.format("%.14g", 1.0), "1", "%.14g: 1.0") +assertEquals(string.format("%.14g", 1/3), "0.33333333333333", "%.14g: 1/3") +assertEquals(string.format("%.14g", math.pi), "3.1415926535898", "%.14g: pi") +assertEquals(string.format("%.14g", 1e-10), "1e-10", "%.14g: 1e-10") +assertEquals(string.format("%.14g", 1e18), "1e+18", "%.14g: 1e18") +assertEquals(string.format("%.14g", 2^63), "9.2233720368548e+18", "%.14g: 2^63") +assertEquals(string.format("%.14g", 2^53), "9.007199254741e+15", "%.14g: 2^53") +assertEquals(string.format("%.14g", 1.7976931348623e+308), "1.7976931348623e+308", "%.14g: max") +assertEquals(string.format("%.14g", 5e-324), "4.9406564584125e-324", "%.14g: min subnormal") +assertEquals(string.format("%.14g", 0/0), "-nan", "%.14g: nan") +assertEquals(string.format("%.14g", 1/0), "inf", "%.14g: inf") +assertEquals(string.format("%.14g", -1/0), "-inf", "%.14g: -inf") -- mixed: multiple specifiers -assert_eq(string.format("%d + %d = %d", 1, 2, 3), "1 + 2 = 3", "mixed: d+d=d") -assert_eq(string.format("%s is %d", "age", 42), "age is 42", "mixed: s is d") -assert_eq(string.format("[%05d] %s (%.2f)", 7, "test", 3.14), "[00007] test (3.14)", "mixed: complex") +assertEquals(string.format("%d + %d = %d", 1, 2, 3), "1 + 2 = 3", "mixed: d+d=d") +assertEquals(string.format("%s is %d", "age", 42), "age is 42", "mixed: s is d") +assertEquals(string.format("[%05d] %s (%.2f)", 7, "test", 3.14), "[00007] test (3.14)", "mixed: complex") -- mixed: no specifiers -assert_eq(string.format("hello world"), "hello world", "mixed: no spec") -assert_eq(string.format(""), "", "mixed: empty") +assertEquals(string.format("hello world"), "hello world", "mixed: no spec") +assertEquals(string.format(""), "", "mixed: empty") -- error: invalid specifier (Lua 5.4 says "invalid conversion", 5.5 may differ) do local ok = pcall(string.format, "%z", 1) - assert_eq(ok, false, "%z: should error") + assertEquals(ok, false, "%z: should error") end -- error: trailing percent do local ok = pcall(string.format, "abc%") - assert_eq(ok, false, "trailing %%: should error") + assertEquals(ok, false, "trailing %%: should error") end -- %f: negative zero -assert_eq(string.format("%f", -0.0), "-0.000000", "%f: -0.0") -assert_eq(string.format("%e", -0.0), "-0.000000e+00", "%e: -0.0") -assert_eq(string.format("%g", -0.0), "-0", "%g: -0.0") +assertEquals(string.format("%f", -0.0), "-0.000000", "%f: -0.0") +assertEquals(string.format("%e", -0.0), "-0.000000e+00", "%e: -0.0") +assertEquals(string.format("%g", -0.0), "-0", "%g: -0.0") -- %f: large precision do local s = string.format("%.20f", 1.0) - assert_eq(string.find(s, "%.") ~= nil, true, "%f: large prec has dot") - assert_eq(#s, 22, "%f: large prec length") + assertEquals(string.find(s, "%.") ~= nil, true, "%f: large prec has dot") + assertEquals(#s, 22, "%f: large prec length") end -- zero width is no-op -assert_eq(string.format("%0d", 42), "42", "%0d: no-op") +assertEquals(string.format("%0d", 42), "42", "%0d: no-op") -- %a: basic hex floats -assert_eq(string.format("%a", 0), "0x0p+0", "%a: 0") -assert_eq(string.format("%a", 1), "0x1p+0", "%a: 1") -assert_eq(string.format("%a", -1), "-0x1p+0", "%a: -1") -assert_eq(string.format("%a", 2), "0x1p+1", "%a: 2") -assert_eq(string.format("%a", 0.5), "0x1p-1", "%a: 0.5") -assert_eq(string.format("%a", 1.5), "0x1.8p+0", "%a: 1.5") -assert_eq(string.format("%a", -0.0), "-0x0p+0", "%a: -0.0") +assertEquals(string.format("%a", 0), "0x0p+0", "%a: 0") +assertEquals(string.format("%a", 1), "0x1p+0", "%a: 1") +assertEquals(string.format("%a", -1), "-0x1p+0", "%a: -1") +assertEquals(string.format("%a", 2), "0x1p+1", "%a: 2") +assertEquals(string.format("%a", 0.5), "0x1p-1", "%a: 0.5") +assertEquals(string.format("%a", 1.5), "0x1.8p+0", "%a: 1.5") +assertEquals(string.format("%a", -0.0), "-0x0p+0", "%a: -0.0") -- %A: uppercase -assert_eq(string.format("%A", 1.5), "0X1.8P+0", "%A: 1.5") -assert_eq(string.format("%A", 255), "0X1.FEP+7", "%A: 255") +assertEquals(string.format("%A", 1.5), "0X1.8P+0", "%A: 1.5") +assertEquals(string.format("%A", 255), "0X1.FEP+7", "%A: 255") -- %a: precision -assert_eq(string.format("%.0a", 1.5), "0x2p+0", "%a: prec0 1.5") -assert_eq(string.format("%.1a", 1.5), "0x1.8p+0", "%a: prec1 1.5") -assert_eq(string.format("%.4a", 1.5), "0x1.8000p+0", "%a: prec4 1.5") -assert_eq(string.format("%.4a", 1), "0x1.0000p+0", "%a: prec4 1") +assertEquals(string.format("%.0a", 1.5), "0x2p+0", "%a: prec0 1.5") +assertEquals(string.format("%.1a", 1.5), "0x1.8p+0", "%a: prec1 1.5") +assertEquals(string.format("%.4a", 1.5), "0x1.8000p+0", "%a: prec4 1.5") +assertEquals(string.format("%.4a", 1), "0x1.0000p+0", "%a: prec4 1") -- %a: width and flags -assert_eq(string.format("%20a", 1.5), " 0x1.8p+0", "%a: w20 1.5") -assert_eq(string.format("%-20a", 1.5), "0x1.8p+0 ", "%a: left w20 1.5") -assert_eq(string.format("%+a", 1.5), "+0x1.8p+0", "%a: +1.5") -assert_eq(string.format("% a", 1.5), " 0x1.8p+0", "%a: space 1.5") +assertEquals(string.format("%20a", 1.5), " 0x1.8p+0", "%a: w20 1.5") +assertEquals(string.format("%-20a", 1.5), "0x1.8p+0 ", "%a: left w20 1.5") +assertEquals(string.format("%+a", 1.5), "+0x1.8p+0", "%a: +1.5") +assertEquals(string.format("% a", 1.5), " 0x1.8p+0", "%a: space 1.5") -- %a: non-finite -assert_eq(string.format("%a", 1/0), "inf", "%a: inf") -assert_eq(string.format("%a", -1/0), "-inf", "%a: -inf") -assert_eq(string.format("%a", 0/0), "-nan", "%a: nan") -assert_eq(string.format("%A", 1/0), "INF", "%A: inf") +assertEquals(string.format("%a", 1/0), "inf", "%a: inf") +assertEquals(string.format("%a", -1/0), "-inf", "%a: -inf") +assertEquals(string.format("%a", 0/0), "-nan", "%a: nan") +assertEquals(string.format("%A", 1/0), "INF", "%A: inf") -- %a: Math.PI -assert_eq(string.format("%a", math.pi), "0x1.921fb54442d18p+1", "%a: pi") +assertEquals(string.format("%a", math.pi), "0x1.921fb54442d18p+1", "%a: pi") -- %a: 0.1 -assert_eq(string.format("%a", 0.1), "0x1.999999999999ap-4", "%a: 0.1") +assertEquals(string.format("%a", 0.1), "0x1.999999999999ap-4", "%a: 0.1") -- %q: nil and booleans -assert_eq(string.format("%q", nil), "nil", "%q: nil") -assert_eq(string.format("%q", true), "true", "%q: true") -assert_eq(string.format("%q", false), "false", "%q: false") +assertEquals(string.format("%q", nil), "nil", "%q: nil") +assertEquals(string.format("%q", true), "true", "%q: true") +assertEquals(string.format("%q", false), "false", "%q: false") -- %q: integers -assert_eq(string.format("%q", 0), "0", "%q: 0") -assert_eq(string.format("%q", 1), "1", "%q: 1") -assert_eq(string.format("%q", -1), "-1", "%q: -1") -assert_eq(string.format("%q", 42), "42", "%q: 42") -assert_eq(string.format("%q", -42), "-42", "%q: -42") +assertEquals(string.format("%q", 0), "0", "%q: 0") +assertEquals(string.format("%q", 1), "1", "%q: 1") +assertEquals(string.format("%q", -1), "-1", "%q: -1") +assertEquals(string.format("%q", 42), "42", "%q: 42") +assertEquals(string.format("%q", -42), "-42", "%q: -42") -- %q: floats as hex -assert_eq(string.format("%q", 1.5), "0x1.8p+0", "%q: 1.5") -assert_eq(string.format("%q", 0.1), "0x1.999999999999ap-4", "%q: 0.1") -assert_eq(string.format("%q", math.pi), "0x1.921fb54442d18p+1", "%q: pi") -assert_eq(string.format("%q", -0.5), "-0x1p-1", "%q: -0.5") -assert_eq(string.format("%q", -0.0), "-0x0p+0", "%q: -0.0") +assertEquals(string.format("%q", 1.5), "0x1.8p+0", "%q: 1.5") +assertEquals(string.format("%q", 0.1), "0x1.999999999999ap-4", "%q: 0.1") +assertEquals(string.format("%q", math.pi), "0x1.921fb54442d18p+1", "%q: pi") +assertEquals(string.format("%q", -0.5), "-0x1p-1", "%q: -0.5") +assertEquals(string.format("%q", -0.0), "-0x0p+0", "%q: -0.0") -- %q: non-finite numbers -assert_eq(string.format("%q", 0/0), "(0/0)", "%q: nan") -assert_eq(string.format("%q", 1/0), "1e9999", "%q: inf") -assert_eq(string.format("%q", -1/0), "-1e9999", "%q: -inf") +assertEquals(string.format("%q", 0/0), "(0/0)", "%q: nan") +assertEquals(string.format("%q", 1/0), "1e9999", "%q: inf") +assertEquals(string.format("%q", -1/0), "-1e9999", "%q: -inf") -- %q: simple strings -assert_eq(string.format("%q", "hello"), '"hello"', "%q: hello") -assert_eq(string.format("%q", ""), '""', "%q: empty") +assertEquals(string.format("%q", "hello"), '"hello"', "%q: hello") +assertEquals(string.format("%q", ""), '""', "%q: empty") -- %q: strings with special characters -assert_eq(string.format("%q", 'say "hi"'), '"say \\"hi\\""', '%q: quotes') -assert_eq(string.format("%q", "back\\slash"), '"back\\\\slash"', "%q: backslash") -assert_eq(string.format("%q", "line\nbreak"), '"line\\\nbreak"', "%q: newline") -assert_eq(string.format("%q", "cr\rreturn"), '"cr\\13return"', "%q: cr") -assert_eq(string.format("%q", "tab\there"), '"tab\\9here"', "%q: tab") +assertEquals(string.format("%q", 'say "hi"'), '"say \\"hi\\""', '%q: quotes') +assertEquals(string.format("%q", "back\\slash"), '"back\\\\slash"', "%q: backslash") +assertEquals(string.format("%q", "line\nbreak"), '"line\\\nbreak"', "%q: newline") +assertEquals(string.format("%q", "cr\rreturn"), '"cr\\13return"', "%q: cr") +assertEquals(string.format("%q", "tab\there"), '"tab\\9here"', "%q: tab") -- %q: Lua reference example do local result = string.format("%q", 'a string with "quotes" and \n new line') - assert_eq(result, '"a string with \\"quotes\\" and \\\n new line"', "%q: reference") + assertEquals(result, '"a string with \\"quotes\\" and \\\n new line"', "%q: reference") end -- %q: mixed with other specifiers -assert_eq( +assertEquals( string.format("name=%q age=%d", "Alice", 30), 'name="Alice" age=30', "%q: mixed" @@ -385,11 +385,11 @@ do local s1 = string.format("%p", t1) local s2 = string.format("%p", t2) -- starts with 0x - assert_eq(s1:sub(1, 2), "0x", "%p: table prefix") + assertEquals(s1:sub(1, 2), "0x", "%p: table prefix") -- same object gives same result - assert_eq(string.format("%p", t1), s1, "%p: stable identity") + assertEquals(string.format("%p", t1), s1, "%p: stable identity") -- different objects give different results - assert_eq(s1 ~= s2, true, "%p: distinct tables differ") + assertEquals(s1 ~= s2, true, "%p: distinct tables differ") end -- %p: functions get an identity too @@ -398,35 +398,35 @@ do local f2 = function() end local s1 = string.format("%p", f1) local s2 = string.format("%p", f2) - assert_eq(s1:sub(1, 2), "0x", "%p: function prefix") - assert_eq(s1 ~= s2, true, "%p: distinct functions differ") + assertEquals(s1:sub(1, 2), "0x", "%p: function prefix") + assertEquals(s1 ~= s2, true, "%p: distinct functions differ") end -- %p: nil and primitives yield (null) -assert_eq(string.format("%p", nil), "(null)", "%p: nil") -assert_eq(string.format("%p", true), "(null)", "%p: boolean") -assert_eq(string.format("%p", 42), "(null)", "%p: number") +assertEquals(string.format("%p", nil), "(null)", "%p: nil") +assertEquals(string.format("%p", true), "(null)", "%p: boolean") +assertEquals(string.format("%p", 42), "(null)", "%p: number") -- %p: strings get an identity (they are GC objects in Lua) do local s = string.format("%p", "hello") - assert_eq(s:sub(1, 2), "0x", "%p: string prefix") + assertEquals(s:sub(1, 2), "0x", "%p: string prefix") end -- %p: width do local t = {} local s = string.format("%20p", t) - assert_eq(#s >= 20, true, "%p: width pads") + assertEquals(#s >= 20, true, "%p: width pads") end -- %p: left-justify do local t = {} local s = string.format("%-20p", t) - assert_eq(#s >= 20, true, "%p: left width pads") + assertEquals(#s >= 20, true, "%p: left width pads") -- trailing spaces - assert_eq(s:sub(#s, #s), " ", "%p: left-justify trailing space") + assertEquals(s:sub(#s, #s), " ", "%p: left-justify trailing space") end -- %p: pointer-like identity for tables @@ -435,9 +435,9 @@ do local t2 = {} local s1 = string.format("%p", t1) local s2 = string.format("%p", t2) - assert_eq(s1:sub(1, 2), "0x", "%p: table prefix") - assert_eq(string.format("%p", t1), s1, "%p: table stable identity") - assert_eq(s1 ~= s2, true, "%p: distinct tables differ") + assertEquals(s1:sub(1, 2), "0x", "%p: table prefix") + assertEquals(string.format("%p", t1), s1, "%p: table stable identity") + assertEquals(s1 ~= s2, true, "%p: distinct tables differ") end -- %p: functions get an identity too @@ -446,9 +446,9 @@ do local f2 = function() end local s1 = string.format("%p", f1) local s2 = string.format("%p", f2) - assert_eq(s1:sub(1, 2), "0x", "%p: function prefix") - assert_eq(string.format("%p", f1), s1, "%p: function stable identity") - assert_eq(s1 ~= s2, true, "%p: distinct functions differ") + assertEquals(s1:sub(1, 2), "0x", "%p: function prefix") + assertEquals(string.format("%p", f1), s1, "%p: function stable identity") + assertEquals(s1 ~= s2, true, "%p: distinct functions differ") end -- %p: strings get an identity (interned: same content = same id) @@ -456,15 +456,15 @@ do local s1 = string.format("%p", "hello") local s2 = string.format("%p", "hello") local s3 = string.format("%p", "world") - assert_eq(s1:sub(1, 2), "0x", "%p: string prefix") - assert_eq(s1, s2, "%p: same string content = same id") - assert_eq(s1 ~= s3, true, "%p: different string content differs") + assertEquals(s1:sub(1, 2), "0x", "%p: string prefix") + assertEquals(s1, s2, "%p: same string content = same id") + assertEquals(s1 ~= s3, true, "%p: different string content differs") end -- %p: nil and primitives yield (null) -assert_eq(string.format("%p", nil), "(null)", "%p: nil") -assert_eq(string.format("%p", true), "(null)", "%p: boolean") -assert_eq(string.format("%p", 42), "(null)", "%p: number") +assertEquals(string.format("%p", nil), "(null)", "%p: nil") +assertEquals(string.format("%p", true), "(null)", "%p: boolean") +assertEquals(string.format("%p", 42), "(null)", "%p: number") -- %p: repeated calls on same table are stable do @@ -474,7 +474,7 @@ do ids[i] = string.format("%p", t) end for i = 2, 5 do - assert_eq(ids[i], ids[1], "%p: repeated call #" .. i .. " stable") + assertEquals(ids[i], ids[1], "%p: repeated call #" .. i .. " stable") end end @@ -484,20 +484,20 @@ do local outer = { ref = inner } local s1 = string.format("%p", inner) local s2 = string.format("%p", outer.ref) - assert_eq(s1, s2, "%p: table via reference stable") + assertEquals(s1, s2, "%p: table via reference stable") end -- %p: width do local t = {} local s = string.format("%20p", t) - assert_eq(#s >= 20, true, "%p: width pads") + assertEquals(#s >= 20, true, "%p: width pads") end -- %p: left-justify do local t = {} local s = string.format("%-20p", t) - assert_eq(#s >= 20, true, "%p: left width pads") - assert_eq(s:sub(#s, #s), " ", "%p: left-justify trailing space") + assertEquals(#s >= 20, true, "%p: left width pads") + assertEquals(s:sub(#s, #s), " ", "%p: left-justify trailing space") end diff --git a/client/space_lua/stdlib/js_test.lua b/client/space_lua/stdlib/js_test.lua index 05426cf8..1de8de90 100644 --- a/client/space_lua/stdlib/js_test.lua +++ b/client/space_lua/stdlib/js_test.lua @@ -1,4 +1,4 @@ -local function assert_equal(a, b) +local function assertEquals(a, b) if a ~= b then error("Assertion failed: " .. a .. " is not equal to " .. b) end @@ -8,9 +8,9 @@ end -- local lodash = js.import("https://esm.sh/lodash@4.17.21") --- assert_equal(js.stringify(lodash.chunk({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 3)), '[[1,2,3],[4,5,6],[7,8,9],[10]]') +-- assertEquals(js.stringify(lodash.chunk({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 3)), '[[1,2,3],[4,5,6],[7,8,9],[10]]') -- local moment = js.import("https://esm.sh/moment@2.30.1") -- local day = moment("1995-12-25"); --- assert_equal(day.format("DD-MM-YYYY"), "25-12-1995") +-- assertEquals(day.format("DD-MM-YYYY"), "25-12-1995") diff --git a/client/space_lua/stdlib/load_test.lua b/client/space_lua/stdlib/load_test.lua index 85d8cf2e..ef3c1ed7 100644 --- a/client/space_lua/stdlib/load_test.lua +++ b/client/space_lua/stdlib/load_test.lua @@ -1,18 +1,18 @@ -local function assert_eq(actual, expected, msg) +local function assertEquals(actual, expected, msg) if actual ~= expected then - error('assert_eq failed: ' .. msg) + error('assertEquals failed: ' .. msg) end end -local function assert_true(cond, msg) +local function assertTrue(cond, msg) if not cond then - error('assert_true failed: ' .. msg) + error('assertTrue failed: ' .. msg) end end -local function assert_false(cond, msg) +local function assertFalse(cond, msg) if cond then - error('assert_false failed: ' .. msg) + error('assertFalse failed: ' .. msg) end end @@ -21,9 +21,9 @@ end do local f, err = load("return 40 + 2") - assert_eq(type(f), "function", "load must return function on success") - assert_eq(err, nil, "load must not return error on success") - assert_eq(f(), 42, "loaded chunk executes and returns") + assertEquals(type(f), "function", "load must return function on success") + assertEquals(err, nil, "load must not return error on success") + assertEquals(f(), 42, "loaded chunk executes and returns") end -- 2. No explicit return -> nil on call @@ -31,9 +31,9 @@ end do local f, err = load("local x = 1; x = x + 1") - assert_eq(type(f), "function", "load returns function even without returns") - assert_eq(err, nil, "no error expected") - assert_eq(f(), nil, "chunk without return yields nil") + assertEquals(type(f), "function", "load returns function even without returns") + assertEquals(err, nil, "no error expected") + assertEquals(f(), nil, "chunk without return yields nil") end -- 3. Syntax error -> (nil, "error message"), no throw on load @@ -41,8 +41,8 @@ end do local f, err = load("return 1 +") - assert_eq(f, nil, "syntax error: first result is nil") - assert_eq(type(err), "string", "syntax error: second result is error string") + assertEquals(f, nil, "syntax error: first result is nil") + assertEquals(type(err), "string", "syntax error: second result is error string") end -- 4. Runtime error when calling the returned function @@ -51,8 +51,8 @@ do local f = load("return 1 + {}") -- arithmetic on non-number at runtime local ok, res = pcall(f) - assert_false(ok, "pcall must be false on runtime error") - assert_eq(type(res), "string", "pcall error message is string") + assertFalse(ok, "pcall must be false on runtime error") + assertEquals(type(res), "string", "pcall error message is string") end -- 5. Global reads are visible in loaded chunk @@ -61,7 +61,7 @@ do g = 41 local f = load("return g + 1") - assert_eq(f(), 42, "loaded chunk sees global env (read)") + assertEquals(f(), 42, "loaded chunk sees global env (read)") end -- 6. Global writes from loaded chunk update globals @@ -69,6 +69,6 @@ do h = 0 local f = load("h = 9") - assert_eq(f(), nil, "no explicit return") - assert_eq(h, 9, "global updated by loaded chunk (write)") + assertEquals(f(), nil, "no explicit return") + assertEquals(h, 9, "global updated by loaded chunk (write)") end diff --git a/client/space_lua/stdlib/math_test.lua b/client/space_lua/stdlib/math_test.lua index 5c74eb9f..c6e4c7f7 100644 --- a/client/space_lua/stdlib/math_test.lua +++ b/client/space_lua/stdlib/math_test.lua @@ -1,16 +1,16 @@ -local function assert_eq(a, b, msg) +local function assertEquals(a, b, msg) if a ~= b then - error((msg or "assert_eq failed") .. ": expected " .. tostring(b) .. " got " .. tostring(a)) + error((msg or "assertEquals failed") .. ": expected " .. tostring(b) .. " got " .. tostring(a)) end end -local function assert_true(v, msg) +local function assertTrue(v, msg) if not v then - error(msg or "assert_true failed") + error(msg or "assertTrue failed") end end -local function assert_close(a, b, eps, msg) +local function assertClose(a, b, eps, msg) eps = eps or 1e-12 if a ~= a and b ~= b then return @@ -21,122 +21,122 @@ local function assert_close(a, b, eps, msg) local d = a - b if d < 0 then d = -d end if d > eps then - error((msg or "assert_close failed") .. ": expected " .. tostring(b) .. " got " .. tostring(a)) + error((msg or "assertClose failed") .. ": expected " .. tostring(b) .. " got " .. tostring(a)) end end -- math.type (basic) do - assert_eq(math.type(0), "integer", "math.type(0)") - assert_eq(math.type(1), "integer", "math.type(1)") - assert_eq(math.type(0.0), "float", "math.type(0.0)") - assert_eq(math.type(-0.0), "float", "math.type(-0.0)") - assert_eq(math.type(1.5), "float", "math.type(1.5)") + assertEquals(math.type(0), "integer", "math.type(0)") + assertEquals(math.type(1), "integer", "math.type(1)") + assertEquals(math.type(0.0), "float", "math.type(0.0)") + assertEquals(math.type(-0.0), "float", "math.type(-0.0)") + assertEquals(math.type(1.5), "float", "math.type(1.5)") end -- constants do - assert_true(type(math.pi) == "number", "math.pi exists") - assert_true(type(math.huge) == "number", "math.huge exists") + assertTrue(type(math.pi) == "number", "math.pi exists") + assertTrue(type(math.huge) == "number", "math.huge exists") end -- abs do - assert_eq(math.abs(-5), 5, "abs(-5)") - assert_eq(math.abs(-3), 3, "abs(-3)") - assert_eq(math.abs(3), 3, "abs(3)") - assert_close(math.abs(-3.25), 3.25, 1e-12, "abs(-3.25)") + assertEquals(math.abs(-5), 5, "abs(-5)") + assertEquals(math.abs(-3), 3, "abs(-3)") + assertEquals(math.abs(3), 3, "abs(3)") + assertClose(math.abs(-3.25), 3.25, 1e-12, "abs(-3.25)") end -- floor/ceil (rounding correctness) do - assert_eq(math.floor(3.7), 3, "floor(3.7)") - assert_eq(math.floor(3), 3, "floor(3)") - assert_eq(math.floor(3.0), 3, "floor(3.0)") - assert_eq(math.floor(3.1), 3, "floor(3.1)") - assert_eq(math.floor(3.9), 3, "floor(3.9)") - assert_eq(math.floor(-3.1), -4, "floor(-3.1)") - assert_eq(math.floor(-3.9), -4, "floor(-3.9)") + assertEquals(math.floor(3.7), 3, "floor(3.7)") + assertEquals(math.floor(3), 3, "floor(3)") + assertEquals(math.floor(3.0), 3, "floor(3.0)") + assertEquals(math.floor(3.1), 3, "floor(3.1)") + assertEquals(math.floor(3.9), 3, "floor(3.9)") + assertEquals(math.floor(-3.1), -4, "floor(-3.1)") + assertEquals(math.floor(-3.9), -4, "floor(-3.9)") - assert_eq(math.ceil(3.3), 4, "ceil(3.3)") - assert_eq(math.ceil(3), 3, "ceil(3)") - assert_eq(math.ceil(3.0), 3, "ceil(3.0)") - assert_eq(math.ceil(3.1), 4, "ceil(3.1)") - assert_eq(math.ceil(3.9), 4, "ceil(3.9)") - assert_eq(math.ceil(-3.1), -3, "ceil(-3.1)") - assert_eq(math.ceil(-3.9), -3, "ceil(-3.9)") + assertEquals(math.ceil(3.3), 4, "ceil(3.3)") + assertEquals(math.ceil(3), 3, "ceil(3)") + assertEquals(math.ceil(3.0), 3, "ceil(3.0)") + assertEquals(math.ceil(3.1), 4, "ceil(3.1)") + assertEquals(math.ceil(3.9), 4, "ceil(3.9)") + assertEquals(math.ceil(-3.1), -3, "ceil(-3.1)") + assertEquals(math.ceil(-3.9), -3, "ceil(-3.9)") end -- min/max do - assert_eq(math.max(1, 2, 3, 4), 4, "max(1,2,3,4)") - assert_eq(math.min(1, 2, 3, 4), 1, "min(1,2,3,4)") + assertEquals(math.max(1, 2, 3, 4), 4, "max(1,2,3,4)") + assertEquals(math.min(1, 2, 3, 4), 1, "min(1,2,3,4)") - assert_eq(math.max(1, 2, 3), 3, "max") - assert_eq(math.min(1, 2, 3), 1, "min") - assert_eq(math.max(-1, -2), -1, "max negative") - assert_eq(math.min(-1, -2), -2, "min negative") + assertEquals(math.max(1, 2, 3), 3, "max") + assertEquals(math.min(1, 2, 3), 1, "min") + assertEquals(math.max(-1, -2), -1, "max negative") + assertEquals(math.min(-1, -2), -2, "min negative") end -- modf do local i, f = math.modf(3.5) - assert_eq(i, 3, "modf(3.5) int") - assert_close(f, 0.5, 1e-12, "modf(3.5) frac") + assertEquals(i, 3, "modf(3.5) int") + assertClose(f, 0.5, 1e-12, "modf(3.5) frac") local i2, f2 = math.modf(-3.5) - assert_eq(i2, -3, "modf(-3.5) int") - assert_close(f2, -0.5, 1e-12, "modf(-3.5) frac") + assertEquals(i2, -3, "modf(-3.5) int") + assertClose(f2, -0.5, 1e-12, "modf(-3.5) frac") end -- sqrt/exp/log/pow do - assert_eq(math.exp(0), 1, "exp(0)") - assert_close(math.log(math.exp(1)), 1, 1e-12, "log(exp(1))") - assert_close(math.log(8, 2), 3, 1e-12, "log base 2 of 8") - assert_eq(math.pow(2, 3), 8, "pow(2,3)") - assert_eq(math.sqrt(9), 3, "sqrt(9)") + assertEquals(math.exp(0), 1, "exp(0)") + assertClose(math.log(math.exp(1)), 1, 1e-12, "log(exp(1))") + assertClose(math.log(8, 2), 3, 1e-12, "log base 2 of 8") + assertEquals(math.pow(2, 3), 8, "pow(2,3)") + assertEquals(math.sqrt(9), 3, "sqrt(9)") end -- trigonomic do - assert_eq(math.cos(0), 1, "cos(0)") - assert_eq(math.sin(0), 0, "sin(0)") - assert_eq(math.tan(0), 0, "tan(0)") - assert_eq(math.acos(1), 0, "acos(1)") - assert_eq(math.asin(0), 0, "asin(0)") - assert_eq(math.atan(0), 0, "atan(0)") - assert_eq(math.atan(0, 1), 0, "atan(0,1)") + assertEquals(math.cos(0), 1, "cos(0)") + assertEquals(math.sin(0), 0, "sin(0)") + assertEquals(math.tan(0), 0, "tan(0)") + assertEquals(math.acos(1), 0, "acos(1)") + assertEquals(math.asin(0), 0, "asin(0)") + assertEquals(math.atan(0), 0, "atan(0)") + assertEquals(math.atan(0, 1), 0, "atan(0,1)") end -- hyperbolic do - assert_eq(math.cosh(0), 1, "cosh(0)") - assert_eq(math.sinh(0), 0, "sinh(0)") - assert_eq(math.tanh(0), 0, "tanh(0)") + assertEquals(math.cosh(0), 1, "cosh(0)") + assertEquals(math.sinh(0), 0, "sinh(0)") + assertEquals(math.tanh(0), 0, "tanh(0)") end -- remainder do - assert_eq(math.fmod(7, 3), 1, "fmod(7,3)") + assertEquals(math.fmod(7, 3), 1, "fmod(7,3)") end -- random do local a1 = math.random() - assert_true(a1 >= 0 and a1 < 1, "random() range") + assertTrue(a1 >= 0 and a1 < 1, "random() range") local aN = math.random(10) - assert_true(aN >= 1 and aN <= 10, "random(10) range") + assertTrue(aN >= 1 and aN <= 10, "random(10) range") local aR = math.random(5, 10) - assert_true(aR >= 5 and aR <= 10, "random(5,10) range") + assertTrue(aR >= 5 and aR <= 10, "random(5,10) range") end -- unsigned less-than do - assert_eq(math.ult(1, 2), true, "ult(1,2)") - assert_eq(math.ult(2, 1), false, "ult(2,1)") + assertEquals(math.ult(1, 2), true, "ult(1,2)") + assertEquals(math.ult(2, 1), false, "ult(2,1)") end -- reported regression @@ -145,19 +145,19 @@ do local x2 = 8 * 0.49 local x3 = 9 * 0.5 - assert_close(x1, 4.0, 0, "8*0.5 == 4.0") - assert_close(x2, 3.92, 1e-12, "8*0.49 == 3.92") - assert_close(x3, 4.5, 1e-12, "9*0.5 == 4.5") + assertClose(x1, 4.0, 0, "8*0.5 == 4.0") + assertClose(x2, 3.92, 1e-12, "8*0.49 == 3.92") + assertClose(x3, 4.5, 1e-12, "9*0.5 == 4.5") local f1 = math.floor(x1) local f2 = math.floor(x2) local f3 = math.floor(x3) - assert_true(f1 == f1, "floor(8*0.5) not NaN") - assert_true(f2 == f2, "floor(8*0.49) not NaN") - assert_true(f3 == f3, "floor(9*0.5) not NaN") + assertTrue(f1 == f1, "floor(8*0.5) not NaN") + assertTrue(f2 == f2, "floor(8*0.49) not NaN") + assertTrue(f3 == f3, "floor(9*0.5) not NaN") - assert_eq(f1, 4, "floor(8*0.5)") - assert_eq(f2, 3, "floor(8*0.49)") - assert_eq(f3, 4, "floor(9*0.5)") + assertEquals(f1, 4, "floor(8*0.5)") + assertEquals(f2, 3, "floor(8*0.49)") + assertEquals(f3, 4, "floor(9*0.5)") end diff --git a/client/space_lua/stdlib/os_test.lua b/client/space_lua/stdlib/os_test.lua index 3734f921..6d731b49 100644 --- a/client/space_lua/stdlib/os_test.lua +++ b/client/space_lua/stdlib/os_test.lua @@ -1,4 +1,4 @@ -local function assert_equal(a, b) +local function assertEquals(a, b) if a ~= b then error("Assertion failed: " .. tostring(a) .. " ~= " .. tostring(b)) end @@ -17,114 +17,114 @@ assert(os.difftime(t, t) == 0) assert(type(os.date()) == "string") -- Empty format returns empty string -assert_equal(os.date(""), "") +assertEquals(os.date(""), "") -- "!" alone returns empty string -assert_equal(os.date("!"), "") +assertEquals(os.date("!"), "") -- Literal %% -assert_equal(os.date("%%"), "%") -assert_equal(os.date("%%%%"), "%%") +assertEquals(os.date("%%"), "%") +assertEquals(os.date("%%%%"), "%%") -- Reference time: 2006-01-02 15:04:05 UTC (Go reference time) -- All fields are distinct: Y=2006 m=01 d=02 H=15 M=04 S=05 wday=Mon local ts = 1136214245 -- Basic date specifiers (UTC) -assert_equal(os.date("!%Y", ts), "2006") -assert_equal(os.date("!%m", ts), "01") -assert_equal(os.date("!%d", ts), "02") -assert_equal(os.date("!%H", ts), "15") -assert_equal(os.date("!%M", ts), "04") -assert_equal(os.date("!%S", ts), "05") +assertEquals(os.date("!%Y", ts), "2006") +assertEquals(os.date("!%m", ts), "01") +assertEquals(os.date("!%d", ts), "02") +assertEquals(os.date("!%H", ts), "15") +assertEquals(os.date("!%M", ts), "04") +assertEquals(os.date("!%S", ts), "05") -- %y (2-digit year) -assert_equal(os.date("!%y", ts), "06") +assertEquals(os.date("!%y", ts), "06") -- %C (century) -assert_equal(os.date("!%C", ts), "20") +assertEquals(os.date("!%C", ts), "20") -- %I (12-hour clock): 15 -> 03 -assert_equal(os.date("!%I", ts), "03") +assertEquals(os.date("!%I", ts), "03") -- %p (AM/PM): hour 15 -> PM -assert_equal(os.date("!%p", ts), "PM") +assertEquals(os.date("!%p", ts), "PM") -- AM case: 2006-01-02 03:04:05 UTC = ts - 12*3600 local ts_am = ts - 12 * 3600 -assert_equal(os.date("!%p", ts_am), "AM") -assert_equal(os.date("!%I", ts_am), "03") -assert_equal(os.date("!%H", ts_am), "03") +assertEquals(os.date("!%p", ts_am), "AM") +assertEquals(os.date("!%I", ts_am), "03") +assertEquals(os.date("!%H", ts_am), "03") -- %w (weekday, 0=Sunday..6=Saturday); 2006-01-02 is Monday=1 -assert_equal(os.date("!%w", ts), "1") +assertEquals(os.date("!%w", ts), "1") -- %u (weekday, 1=Monday..7=Sunday); Monday=1 -assert_equal(os.date("!%u", ts), "1") +assertEquals(os.date("!%u", ts), "1") -- Sunday: 2006-01-01 is Sunday local ts_sun = ts - 86400 -assert_equal(os.date("!%w", ts_sun), "0") -assert_equal(os.date("!%u", ts_sun), "7") +assertEquals(os.date("!%w", ts_sun), "0") +assertEquals(os.date("!%u", ts_sun), "7") -- %j (day of year, 001-366); Jan 2 = 002 -assert_equal(os.date("!%j", ts), "002") +assertEquals(os.date("!%j", ts), "002") -- %e (day of month, space-padded); 2 -> " 2" -assert_equal(os.date("!%e", ts), " 2") +assertEquals(os.date("!%e", ts), " 2") -- Composite: %F (ISO date) -assert_equal(os.date("!%F", ts), "2006-01-02") +assertEquals(os.date("!%F", ts), "2006-01-02") -- Composite: %D (MM/DD/YY) -assert_equal(os.date("!%D", ts), "01/02/06") +assertEquals(os.date("!%D", ts), "01/02/06") -- Composite: %T (HH:MM:SS) -assert_equal(os.date("!%T", ts), "15:04:05") +assertEquals(os.date("!%T", ts), "15:04:05") -- Composite: %R (HH:MM) -assert_equal(os.date("!%R", ts), "15:04") +assertEquals(os.date("!%R", ts), "15:04") -- Composite: %r (12-hour with AM/PM) -assert_equal(os.date("!%r", ts), "03:04:05 PM") +assertEquals(os.date("!%r", ts), "03:04:05 PM") -- %n and %t -assert_equal(os.date("!%n"), "\n") -assert_equal(os.date("!%t"), "\t") +assertEquals(os.date("!%n"), "\n") +assertEquals(os.date("!%t"), "\t") -- %s (epoch seconds) -- -- Note: POSIX extension; comment out to run with standard Lua -- interpreters. -assert_equal(os.date("!%s", ts), "1136214245") +assertEquals(os.date("!%s", ts), "1136214245") -- %z and %Z in UTC/GMT mode -- -- Note: Uncomment the "GMT" variant to run with standard Lua interpreter -- and comment out the "UTC" variant. -assert_equal(os.date("!%z", ts), "+0000") ---assert_equal(os.date("!%Z", ts), "GMT") -- on most platforms -assert_equal(os.date("!%Z", ts), "UTC") -- in Space Lua +assertEquals(os.date("!%z", ts), "+0000") +--assertEquals(os.date("!%Z", ts), "GMT") -- on most platforms +assertEquals(os.date("!%Z", ts), "UTC") -- in Space Lua -- %h is alias for %b -assert_equal(os.date("!%h", ts), os.date("!%b", ts)) +assertEquals(os.date("!%h", ts), os.date("!%b", ts)) -- Multiple specifiers combined -assert_equal(os.date("!%Y-%m-%d %H:%M:%S", ts), "2006-01-02 15:04:05") +assertEquals(os.date("!%Y-%m-%d %H:%M:%S", ts), "2006-01-02 15:04:05") -- Plain text mixed with specifiers -assert_equal(os.date("!year=%Y", ts), "year=2006") +assertEquals(os.date("!year=%Y", ts), "year=2006") -- *t table (UTC) local dt = os.date("!*t", ts) -assert_equal(dt.year, 2006) -assert_equal(dt.month, 1) -assert_equal(dt.day, 2) -assert_equal(dt.hour, 15) -assert_equal(dt.min, 4) -assert_equal(dt.sec, 5) -assert_equal(dt.wday, 2) -- Monday; Lua: 1=Sunday, so Monday=2 -assert_equal(dt.yday, 2) +assertEquals(dt.year, 2006) +assertEquals(dt.month, 1) +assertEquals(dt.day, 2) +assertEquals(dt.hour, 15) +assertEquals(dt.min, 4) +assertEquals(dt.sec, 5) +assertEquals(dt.wday, 2) -- Monday; Lua: 1=Sunday, so Monday=2 +assertEquals(dt.yday, 2) -- *t table (local time) has isdst field local dt_local = os.date("*t", ts) @@ -135,28 +135,28 @@ assert(not dt.isdst) -- %G/%g (ISO week-based year) -- 2006-01-02 is in ISO week 1 of 2006 -assert_equal(os.date("!%G", ts), "2006") -assert_equal(os.date("!%g", ts), "06") +assertEquals(os.date("!%G", ts), "2006") +assertEquals(os.date("!%g", ts), "06") -- ISO week-year boundary: 2005-01-01 (Saturday) is in ISO week 53 of 2004 local ts_2005 = 1104537600 -- 2005-01-01 00:00:00 UTC -assert_equal(os.date("!%G", ts_2005), "2004") -assert_equal(os.date("!%V", ts_2005), "53") +assertEquals(os.date("!%G", ts_2005), "2004") +assertEquals(os.date("!%V", ts_2005), "53") -- Week number specifiers at reference time (2006-01-02, Monday) -- %U (weeks starting Sunday): Jan 1 is Sunday -> week 01, Jan 2 still week 01 -assert_equal(os.date("!%U", ts), "01") +assertEquals(os.date("!%U", ts), "01") -- %W (weeks starting Monday): Jan 2 is first Monday -> week 01 -assert_equal(os.date("!%W", ts), "01") +assertEquals(os.date("!%W", ts), "01") -- %V (ISO week): week 01 -assert_equal(os.date("!%V", ts), "01") +assertEquals(os.date("!%V", ts), "01") -- Preserved original week tests -assert_equal( +assertEquals( os.date("%Y-%m-%d", os.time({ year = 2020, month = 1, day = 1 })), "2020-01-01" ) -assert_equal( +assertEquals( os.date("%Y-%m-%d", os.time({ year = 2025, month = 2, day = 3 })), "2025-02-03" ) @@ -167,4 +167,4 @@ assert(not ok) assert(type(err) == "string") -- Repeated specifiers -assert_equal(os.date("!%Y%Y", ts), "20062006") +assertEquals(os.date("!%Y%Y", ts), "20062006") diff --git a/client/space_lua/tonumber_test.lua b/client/space_lua/tonumber_test.lua index b8f8de6c..8de09aa9 100644 --- a/client/space_lua/tonumber_test.lua +++ b/client/space_lua/tonumber_test.lua @@ -1,4 +1,4 @@ -local function assert_eq(a, b, message) +local function assertEquals(a, b, message) if a ~= b then error('Assertion failed: ' .. tostring(a) .. ' is not equal to ' .. tostring(b) .. (message and (' | ' .. message) or '')) @@ -26,88 +26,88 @@ end -- helper for whitespace handling tests local chr = string.char -- no base: whitespace handling -assert_eq(tonumber(chr(32, 9, 10, 11, 12, 13) .. '42'), 42) -assert_eq(tonumber('42' .. chr(32, 9, 10, 11, 12, 13)), 42) +assertEquals(tonumber(chr(32, 9, 10, 11, 12, 13) .. '42'), 42) +assertEquals(tonumber('42' .. chr(32, 9, 10, 11, 12, 13)), 42) -- converting numbers that are already numbers -assert_eq(tonumber(0), 0) -assert_eq(tonumber(10), 10) +assertEquals(tonumber(0), 0) +assertEquals(tonumber(10), 10) -- no base: zeroes -assert_eq(tonumber('-0'), 0) -assert_eq(tonumber('0x0p0'), 0.0) -assert_eq(tonumber('0x.0p10'), 0.0) +assertEquals(tonumber('-0'), 0) +assertEquals(tonumber('0x0p0'), 0.0) +assertEquals(tonumber('0x.0p10'), 0.0) -- no base: valid decimal integers and floats -assert_eq(tonumber('123'), 123) -assert_eq(tonumber('+123'), 123) -assert_eq(tonumber('-123'), -123) -assert_eq(tonumber('0'), 0) -assert_eq(tonumber('000123'), 123) -assert_eq(tonumber('123.45'), 123.45) -assert_eq(tonumber('5.'), 5.0) -assert_eq(tonumber('.5'), 0.5) -assert_eq(tonumber('5.e1'), 50.0) -assert_eq(tonumber('.5e2'), 50.0) -assert_eq(tonumber('-.5e2'), -50.0) -assert_eq(tonumber('1e-2'), 0.01) -assert_eq(tonumber('1E+2'), 100.0) +assertEquals(tonumber('123'), 123) +assertEquals(tonumber('+123'), 123) +assertEquals(tonumber('-123'), -123) +assertEquals(tonumber('0'), 0) +assertEquals(tonumber('000123'), 123) +assertEquals(tonumber('123.45'), 123.45) +assertEquals(tonumber('5.'), 5.0) +assertEquals(tonumber('.5'), 0.5) +assertEquals(tonumber('5.e1'), 50.0) +assertEquals(tonumber('.5e2'), 50.0) +assertEquals(tonumber('-.5e2'), -50.0) +assertEquals(tonumber('1e-2'), 0.01) +assertEquals(tonumber('1E+2'), 100.0) -- no base: valid hexadecimal integers (no exponent) -assert_eq(tonumber('0x10'), 16) -assert_eq(tonumber('0X10'), 16) -assert_eq(tonumber('+0x10'), 16) -assert_eq(tonumber('-0x10'), -16) -assert_eq(tonumber(' 0x0 '), 0) -assert_eq(tonumber('0x000F'), 15) -assert_eq(tonumber('0XdeadBEEF'), 3735928559) +assertEquals(tonumber('0x10'), 16) +assertEquals(tonumber('0X10'), 16) +assertEquals(tonumber('+0x10'), 16) +assertEquals(tonumber('-0x10'), -16) +assertEquals(tonumber(' 0x0 '), 0) +assertEquals(tonumber('0x000F'), 15) +assertEquals(tonumber('0XdeadBEEF'), 3735928559) -- no base: valid hexadecimal floats (with exponent) -assert_eq(tonumber('0x1p0'), 1.0) -assert_eq(tonumber('0x1p+0'), 1.0) -assert_eq(tonumber('0x1p-2'), 0.25) -assert_eq(tonumber('0x1.0p-2'), 0.25) -assert_eq(tonumber('0x1.8p1'), 3.0) -assert_eq(tonumber('0x.8p0'), 0.5) -assert_eq(tonumber('0x.Fp4'), 15.0) -assert_eq(tonumber('0XA.P-1'), 5.0) -assert_eq(tonumber(' 0x10P0 '), 16.0) -assert_eq(tonumber('-0x10p0'), -16.0) -assert_eq(tonumber('0x10.2p0'), 16.125) -assert_eq(tonumber('0x10.3P-1'), 8.09375) -assert_eq(tonumber('-0X10.3P-1'), -8.09375) -assert_eq(tonumber('0x1.2'), 1.125) +assertEquals(tonumber('0x1p0'), 1.0) +assertEquals(tonumber('0x1p+0'), 1.0) +assertEquals(tonumber('0x1p-2'), 0.25) +assertEquals(tonumber('0x1.0p-2'), 0.25) +assertEquals(tonumber('0x1.8p1'), 3.0) +assertEquals(tonumber('0x.8p0'), 0.5) +assertEquals(tonumber('0x.Fp4'), 15.0) +assertEquals(tonumber('0XA.P-1'), 5.0) +assertEquals(tonumber(' 0x10P0 '), 16.0) +assertEquals(tonumber('-0x10p0'), -16.0) +assertEquals(tonumber('0x10.2p0'), 16.125) +assertEquals(tonumber('0x10.3P-1'), 8.09375) +assertEquals(tonumber('-0X10.3P-1'), -8.09375) +assertEquals(tonumber('0x1.2'), 1.125) -- no base: invalid -assert_eq(tonumber(''), nil) -assert_eq(tonumber(' '), nil) -assert_eq(tonumber('abc'), nil) -assert_eq(tonumber('12.34.56'), nil) -assert_eq(tonumber('e10'), nil) -assert_eq(tonumber('.e1'), nil) -assert_eq(tonumber('1e'), nil) -assert_eq(tonumber('1e+'), nil) -assert_eq(tonumber('0x'), nil) -assert_eq(tonumber('0xG'), nil) -assert_eq(tonumber('+ 10'), nil) -assert_eq(tonumber('- 10'), nil) -assert_eq(tonumber('123x'), nil) +assertEquals(tonumber(''), nil) +assertEquals(tonumber(' '), nil) +assertEquals(tonumber('abc'), nil) +assertEquals(tonumber('12.34.56'), nil) +assertEquals(tonumber('e10'), nil) +assertEquals(tonumber('.e1'), nil) +assertEquals(tonumber('1e'), nil) +assertEquals(tonumber('1e+'), nil) +assertEquals(tonumber('0x'), nil) +assertEquals(tonumber('0xG'), nil) +assertEquals(tonumber('+ 10'), nil) +assertEquals(tonumber('- 10'), nil) +assertEquals(tonumber('123x'), nil) -- with base: whitespace handling -assert_eq(tonumber(chr(32, 9, 10, 11, 12, 13) .. 'FF', 16), 255) -assert_eq(tonumber('FF' .. chr(32, 9, 10, 11, 12, 13), 16), 255) +assertEquals(tonumber(chr(32, 9, 10, 11, 12, 13) .. 'FF', 16), 255) +assertEquals(tonumber('FF' .. chr(32, 9, 10, 11, 12, 13), 16), 255) -- with base: valid -assert_eq(tonumber('1010', 2), 10) -assert_eq(tonumber('+1011', 2), 11) -assert_eq(tonumber('ff', 16), 255) -assert_eq(tonumber('FF', 16), 255) -assert_eq(tonumber('fF', 16), 255) -assert_eq(tonumber('377', 8), 255) -assert_eq(tonumber('z', 36), 35) -assert_eq(tonumber('Aa', 11), 120) -assert_eq(tonumber(' ff ', 16), 255) -assert_eq(tonumber('1010', 10), 1010) +assertEquals(tonumber('1010', 2), 10) +assertEquals(tonumber('+1011', 2), 11) +assertEquals(tonumber('ff', 16), 255) +assertEquals(tonumber('FF', 16), 255) +assertEquals(tonumber('fF', 16), 255) +assertEquals(tonumber('377', 8), 255) +assertEquals(tonumber('z', 36), 35) +assertEquals(tonumber('Aa', 11), 120) +assertEquals(tonumber(' ff ', 16), 255) +assertEquals(tonumber('1010', 10), 1010) -- with base: invalid assertThrows("bad argument #2 to 'tonumber' (base out of range)", @@ -122,13 +122,13 @@ assertThrows("bad argument #2 to 'tonumber' (base out of range)", end ) -assert_eq(tonumber('FF', 10), nil) -assert_eq(tonumber('8', 8), nil) -assert_eq(tonumber('2', 2), nil) -assert_eq(tonumber('', 16), nil) -assert_eq(tonumber(' ', 16), nil) -assert_eq(tonumber('+', 16), nil) -assert_eq(tonumber('-', 16), nil) -assert_eq(tonumber('+ FF', 16), nil) -assert_eq(tonumber('1_0', 10), nil) -assert_eq(tonumber('123x', 10), nil) +assertEquals(tonumber('FF', 10), nil) +assertEquals(tonumber('8', 8), nil) +assertEquals(tonumber('2', 2), nil) +assertEquals(tonumber('', 16), nil) +assertEquals(tonumber(' ', 16), nil) +assertEquals(tonumber('+', 16), nil) +assertEquals(tonumber('-', 16), nil) +assertEquals(tonumber('+ FF', 16), nil) +assertEquals(tonumber('1_0', 10), nil) +assertEquals(tonumber('123x', 10), nil) diff --git a/client/space_lua/truthiness_test.lua b/client/space_lua/truthiness_test.lua index 2570fd42..5d4f29d8 100644 --- a/client/space_lua/truthiness_test.lua +++ b/client/space_lua/truthiness_test.lua @@ -1,18 +1,18 @@ -local function assert_eq(actual, expected, msg) +local function assertEquals(actual, expected, msg) if actual ~= expected then - error('assert_eq failed: ' .. msg) + error('assertEquals failed: ' .. msg) end end -local function assert_true(cond, msg) +local function assertTrue(cond, msg) if not cond then - error('assert_true failed: ' .. msg) + error('assertTrue failed: ' .. msg) end end -local function assert_false(cond, msg) +local function assertFalse(cond, msg) if cond then - error('assert_false failed: ' .. msg) + error('assertFalse failed: ' .. msg) end end @@ -44,35 +44,35 @@ end -- 1. Basic boolean/nil -assert_false(false, "false must be falsey") -assert_true(true, "true must be truthy") -assert_false(nil, "nil must be falsey") +assertFalse(false, "false must be falsey") +assertTrue(true, "true must be truthy") +assertFalse(nil, "nil must be falsey") -- 2. Numbers: all numbers are truthy -assert_true(0, "0 must be truthy") -assert_true(1, "1 must be truthy") -assert_true(-1, "-1 must be truthy") -assert_true(0.0, "0.0 must be truthy") -assert_true(-0.0, "-0.0 must be truthy") +assertTrue(0, "0 must be truthy") +assertTrue(1, "1 must be truthy") +assertTrue(-1, "-1 must be truthy") +assertTrue(0.0, "0.0 must be truthy") +assertTrue(-0.0, "-0.0 must be truthy") -- 3. Strings: empty and non-empty strings are truthy -assert_true("", "empty string must be truthy") -assert_true("0", '"0" must be truthy') -assert_true("a", '"a" must be truthy') +assertTrue("", "empty string must be truthy") +assertTrue("0", '"0" must be truthy') +assertTrue("a", '"a" must be truthy') -- 4. Tables: empty and non-empty tables are truthy -assert_true({}, "empty table must be truthy") -assert_true({1}, "non-empty table must be truthy") +assertTrue({}, "empty table must be truthy") +assertTrue({1}, "non-empty table must be truthy") -- 5. Functions are truthy local fn = function() end -assert_true(fn, "function must be truthy") -assert_true(function() end, "function must be truthy") +assertTrue(fn, "function must be truthy") +assertTrue(function() end, "function must be truthy") -- 6. Multi-return: only the first value determines truthiness @@ -100,24 +100,24 @@ end -- 7.1. `and` returns first falsey value, otherwise last value -assert_eq((true and 2), 2, "and: true and 2 -> 2") -assert_eq((false and 2), false, "and: false and 2 -> false") -assert_eq((nil and 2), nil, "and: nil and 2 -> nil") -assert_eq((0 and "x"), "x", "and: 0 and 'x' -> 'x' (0 is truthy)") +assertEquals((true and 2), 2, "and: true and 2 -> 2") +assertEquals((false and 2), false, "and: false and 2 -> false") +assertEquals((nil and 2), nil, "and: nil and 2 -> nil") +assertEquals((0 and "x"), "x", "and: 0 and 'x' -> 'x' (0 is truthy)") -- 7.2. `or` returns first truthy value, otherwise last value -assert_eq((false or 3), 3, "or: false or 3 -> 3") -assert_eq((nil or 3), 3, "or: nil or 3 -> 3") -assert_eq((0 or 3), 0, "or: 0 or 3 -> 0 (0 is truthy)") -assert_eq(("" or "x"), "", "or: '' or 'x' -> '' ('' is truthy)") +assertEquals((false or 3), 3, "or: false or 3 -> 3") +assertEquals((nil or 3), 3, "or: nil or 3 -> 3") +assertEquals((0 or 3), 0, "or: 0 or 3 -> 0 (0 is truthy)") +assertEquals(("" or "x"), "", "or: '' or 'x' -> '' ('' is truthy)") -- 7.3. Multi-return: operand evaluation yields first value -assert_eq((true and ret_one_two()), 1, +assertEquals((true and ret_one_two()), 1, "and: true and (1,2) yields first result 1") -assert_eq((false or ret_one_two()), 1, +assertEquals((false or ret_one_two()), 1, "or: false or (1,2) yields first result 1") -- 8. Litmus tests involving tables and `and`/`or` @@ -127,20 +127,20 @@ assert_eq((false or ret_one_two()), 1, local t = {} -assert_eq((t and 2 or 3), 2, "{} and 2 or 3 must be 2") +assertEquals((t and 2 or 3), 2, "{} and 2 or 3 must be 2") -- `v` should be the same table reference `t` local v = (t or 2 and 3) -assert_true(type(v) == "table", +assertTrue(type(v) == "table", "{} or 2 and 3 must return the table (truthy left operand)") -- changing `t` reflects in `v` (same reference) t.key = "ok" -assert_eq(v.key, "ok", +assertEquals(v.key, "ok", "{} or 2 and 3 returns original table reference") -- 9. `if`/`while` with truthiness @@ -151,7 +151,7 @@ if {} then ran_if_truthy = true end -assert_true(ran_if_truthy, "if {} must run branch") +assertTrue(ran_if_truthy, "if {} must run branch") local ran_if_falsey = false @@ -159,7 +159,7 @@ if nil then ran_if_falsey = true end -assert_false(ran_if_falsey, "if nil must not run branch") +assertFalse(ran_if_falsey, "if nil must not run branch") -- `while` must stop only on `false`/`nil` @@ -182,7 +182,7 @@ while next_or_nil() do count = count + 1 end -assert_eq(count, 2, +assertEquals(count, 2, "while should loop while condition is truthy") -- 10. Short-circuit evaluation (no RHS evaluation when not needed) @@ -199,13 +199,13 @@ end local s0 = side local _ = (true or bump()) -assert_eq(side, s0, "or short-circuit must avoid RHS when LHS truthy") +assertEquals(side, s0, "or short-circuit must avoid RHS when LHS truthy") -- For `false and bump()` RHS must not be evaluated local _ = (false and bump()) -assert_eq(side, s0, "and short-circuit must avoid RHS when LHS falsey") +assertEquals(side, s0, "and short-circuit must avoid RHS when LHS falsey") -- 11. Multi-return short-circuit @@ -221,11 +221,11 @@ end local s1 = (falsy_pair() or 5) -assert_eq(s1, 5, "or should see falsy first result and evaluate RHS") +assertEquals(s1, 5, "or should see falsy first result and evaluate RHS") local s2 = (truthy_pair() or 5) -assert_eq(s2, 1, "or should return first result of LHS when truthy") +assertEquals(s2, 1, "or should return first result of LHS when truthy") -- 12. Only the last expression expands @@ -234,21 +234,21 @@ local function a() return "A1", "A2" end local function b() return "B1", "B2" end local function c() return "C1", "C2" end -assert_eq(string.format("%s-%s", ret()), "A-B", +assertEquals(string.format("%s-%s", ret()), "A-B", "last-only: single arg expands") -assert_eq(string.format("%s-%s", ret(), "Z"), "A-Z", +assertEquals(string.format("%s-%s", ret(), "Z"), "A-Z", "last-only: earlier arg is single") -assert_eq(string.format("%s-%s-%s-%s", a(), b(), c()), "A1-B1-C1-C2", +assertEquals(string.format("%s-%s-%s-%s", a(), b(), c()), "A1-B1-C1-C2", "last-only: only last expands, earlier args single") -- 13. Only false and `nil` are falsey -assert_false(not 0, "not 0 must be false") -assert_false(not -0.0, "not -0.0 must be false") -assert_false(not "", "not '' must be false") -assert_false(not {}, "not {} must be false") +assertFalse(not 0, "not 0 must be false") +assertFalse(not -0.0, "not -0.0 must be false") +assertFalse(not "", "not '' must be false") +assertFalse(not {}, "not {} must be false") -assert_true(not nil, "not nil must be true") -assert_true(not false, "not false must be true") +assertTrue(not nil, "not nil must be true") +assertTrue(not false, "not false must be true")