public void format() { Lua.DoText(@" assertEquals('AB3CD', string.format('AB{0}CD', 3), 'format: normal') assertEquals('ABCD', string.format('ABCD'), 'format: no format') "); }
public void BaseClass_CanCallOtherMembers() { Lua.DoText(@" class Foobar : BaseClass function Foobar:VirtualMethod() return 456 end function Foobar:NewMethod() return 123 end function Foobar:AbstractMethod() assertNotNull(self, 'AbstractMethod must have self') assertEquals(123, self:NewMethod(), 'NewMethod inside AbstractMethod') assertEquals(456, self:VirtualMethod(), 'VirtualMethod inside AbstractMethod') return 0 end function Foobar:TestMethod() assertNotNull(self, 'TestMethod must have self') assertEquals(123, self:NewMethod(), 'NewMethod inside TestMethod') assertEquals(456, self:VirtualMethod(), 'VirtualMethod inside TestMethod') end local inst = Foobar() inst:AbstractMethod() inst:TestMethod() "); }
public void random() { // NOTE: Although the multiple runs will produce the same results, the actual value of // the value is undefined; therefore we need to just check for 'randomness' and for // consistency, not for specific values. Lua.DoText(@" math.randomseed(12345) local a = math.random() local b = math.random(45) local c = math.random(24, 68) assertTrue(0 <= a and a <= 1, 'random: no-arg range') assertTrue(1 <= b and b <= 45, 'random: one-arg range') assertEquals(0, math.fmod(b, 1), 'random: one-arg is an integer') assertTrue(24 <= c and c <= 68, 'random: two-arg range') assertEquals(0, math.fmod(c, 1), 'random: two-arg is an integer') -- This is technically possible, but extremely unlikely. math.randomseed(54321) local x = math.random() local y = math.random(45) assertTrue(x ~= a and y ~= b, 'random: different seeds make different values') math.randomseed(12345) assertEquals(a, math.random(), 'random: zero-arg makes same values') assertEquals(b, math.random(45), 'random: one-arg makes same values') assertEquals(c, math.random(24, 68), 'random: two-arg makes same values') "); }
public void ParenthesesCollapseMultiValues() { Lua.DoText(@" function values() return 1, 2 end function checkArgs(a, b) assertEquals(a, 1, 'collapse arguments1') assertEquals(b, nil, 'collapse arguments2') end function checkReturn() return (values()) end local a, b = values() assertEquals(a, 1, 'collapse sanity check1') assertEquals(b, 2, 'collapse sanity check2') local c, d = (values()) assertEquals(c, 1, 'collapse assignment1') assertEquals(d, nil, 'collapse assignment2') checkArgs((values())) local e, f = checkReturn() assertEquals(e, 1, 'collapse return1') assertEquals(f, nil, 'collapse return2') "); }
public void General() { // Combine many of the methods together since they are just imported. Lua.DoText(@" assertEquals( 251245, math.abs(-251245), 'abs') assertEqualsDelta(0.361416951927645, math.asin(0.3536), 'asin') assertEqualsDelta(0.187568907875447, math.atan(0.1898), 'atan') assertEqualsDelta(0.161967351986035, math.atan2(25, 153), 'atan2') assertEquals( 2455, math.ceil(2454.5147), 'ceil') assertEqualsDelta(0.658878051008508, math.cos(0.85147), 'cos') assertEqualsDelta(1.38493787774095, math.cosh(0.85147), 'cosh') assertEqualsDelta(48.7856373820042, math.deg(0.85147), 'deg') assertEqualsDelta(69.6254387609039, math.exp(4.24313), 'exp') assertEquals( 2454, math.floor(2454.5147), 'floor') assertEqualsDelta(-1.195, math.fmod(24.54, 5.147), 'fmod') assertEqualsDelta(70866960384, math.ldexp(528, 27), 'ldexp') assertEqualsDelta(3.20030443928277, math.log(24.54), 'ln') assertEqualsDelta(1.53902111462939, math.log(24.54, 8), 'log') assertEqualsDelta(40872.6120526573, math.pow(3.678, 8.153), 'pow') assertEqualsDelta(4.802797035638, math.rad(275.18), 'rad') assertEqualsDelta(0.608415615200534, math.sin(2.48753), 'sin') assertEqualsDelta(5.97420326157982, math.sinh(2.48753), 'sinh') assertEqualsDelta(221.303904168002, math.sqrt(48975.418), 'sqrt') assertEqualsDelta(-0.76663479914779, math.tan(2.48753), 'tan') assertEqualsDelta(0.986278580120099, math.tanh(2.48753), 'tanh') "); }
public void upper() { Lua.DoText(@" assertEquals('ABCDE', string.upper('aBCdE'), 'upper: normal') assertEquals('', string.upper(''), 'upper: empty string') assertEquals('ΤΥΦΧΨΩ', string.upper('τυφχψω'), 'upper: Unicode') "); }
public void min() { Lua.DoText(@" assertEquals(-566, math.min(2, -566, 451, 2672368, 1), 'min: normal') assertEquals(-63, math.min(-63, 566, 47, 0, -7), 'min: return is first argument') assertEquals(8, math.min(8), 'min: one argument') "); }
public void lower() { Lua.DoText(@" assertEquals('abcde', string.lower('aBCdE'), 'lower: normal') assertEquals('', string.lower(''), 'lower: empty string') assertEquals('τυφχψω', string.lower('ΤΥΦΧΨΩ'), 'lower: Unicode') "); }
public void max() { Lua.DoText(@" assertEquals(2672368, math.max(2, -566, 451, 2672368, 1), 'max: normal') assertEquals(63, math.max(63, -566, -47, 0, -7), 'max: return is first argument') assertEquals(8, math.max(8), 'max: one argument') "); }
public void extract() { Lua.DoText(@" assertEquals(0x3a28, bit32.extract(0xa74e8a28, 6, 16), 'extract: normal') assertEquals(0x0, bit32.extract(0xa74e8a28, 6), 'extract: defaults to 1 width') assertEquals(0x4fe3a, bit32.extract(0x913f8ea, 2, 21, 'cat'), 'extract: extra args') assertEquals(0x1e, bit32.extract(0xff0305d2f0, 3, 6), 'extract: larger than 32-bits') "); }
public void reverse() { Lua.DoText(@" assertEquals('DCBA', string.reverse('ABCD'), 'reverse: normal') assertEquals('', string.reverse(''), 'reverse: empty string') assertEquals('" + "\u2678a\u4623" + @"', string.reverse('" + "\u4623a\u2678" + @"'), 'reverse: supports Unicode') assertEquals('" + "\ud801\udc37a" + @"', string.reverse('" + "a\ud801\udc37" + @"'), 'reverse: supports UTF-16') "); }
public void rep() { Lua.DoText(@" assertEquals('XaXaXaXa', string.rep('Xa', 4), 'rep: normal') assertEquals('', string.rep('Xa', 0), 'rep: zero rep') assertEquals('', string.rep('Xa', -3), 'rep: negative rep') assertEquals('Xa,Xa,Xa', string.rep('Xa', 3, ','), 'rep: with sep') "); }
public void len() { Lua.DoText(@" assertEquals(5, string.len('ab xy'), 'len: normal') assertEquals(0, string.len(''), 'len: empty string') assertEquals(5, string.len('a\000b\000c'), 'len: embedded nulls') assertEquals(6, string.len('" + "a\u94ac\ud852xa\udf62" + @"'), 'len: Unicode') "); }
public void concat() { Lua.DoText(@" assertEquals('1c3', table.concat({1,'c',3}), 'concat: normal') assertEquals('1c', table.concat({1,'c',nil,3}), 'concat: with nil') assertEquals('1,c,3', table.concat({1,'c',3}, ','), 'concat: with sep') assertEquals('c,3,4', table.concat({1,'c',3,4}, ',', 2), 'concat: with start') assertEquals('c,3', table.concat({1,'c',3,4}, ',', 2, 3), 'concat: with start & end') "); }
public void BaseClass_CantReplaceMethodWithField() { Lua.DoText(@" class Foobar : BaseClass assertThrows('can\'t replace method with field', function() Foobar.VirtualMethod = 'abc' end) "); }
public void BaseClass_InheritsFromType() { Lua.DoText(@"class Foobar : BaseClass"); var cls = GetLuaClass("Foobar"); object inst = cls.CreateInstance(); Assert.IsNotNull(inst); Assert.IsInstanceOf <BaseClass>(inst); }
public void bor() { Lua.DoText(@" assertEquals(0xff, bit32.bor(0xaa, 0x55), 'bor: normal') assertEquals(0x0, bit32.bor(), 'bor: zero arguments') assertEquals(0xea, bit32.bor(0xea), 'bor: one arguement') assertEquals(0xab, bit32.bor(0x01, 0x83, 0x21, 0x2a), 'bor: more than two') assertEquals(0xff00aaaa, bit32.bor(0xfa0000aa, 0xaf00aa00), 'bor: large number') assertEquals(0xff, bit32.bor(0xff000000f0, 0xff0000000f), 'bor: larger than 32-bits') "); }
public void bnot() { Lua.DoText(@" assertEquals(0xff005533, bit32.bnot(0x00ffaacc), 'bnot: normal') assertEquals(0xff005533, bit32.bnot(0x00ffaacc, 'cat'), 'bnot: extra args') assertEquals(0x00ffaa66, bit32.bnot(0xff005599), 'bnot: high-bit set') assertEquals(11, bit32.bnot(-12), 'bnot: negative') assertEquals(0xffffffff, bit32.bnot(0), 'bnot: zero') assertEquals(0xffffefdb, bit32.bnot(0x4500001024), 'bnot: larger than 32-bits') "); }
public void BaseClass_InstanceInLua() { Lua.DoText(@" class Foobar : BaseClass local inst = Foobar() assertNotNull(inst, 'create instance') assertEquals(15, inst.VirtualMethod(), 'virtual method') "); }
public void replace() { Lua.DoText(@" assertEquals(0xa74a4a28, bit32.replace(0xa74e8a28, 0x452, 13, 6), 'replace: normal') assertEquals(0xa74e8a20, bit32.replace(0xa74e8a28, 6, 3), 'replace: defaults to 1 width') assertEquals(0xffff4c47, bit32.replace(-45625, 34, 5, 4), 'replace: negative source') assertEquals(0xa74eca, bit32.replace(0xa74e8a, -42, 5, 4), 'replace: negative repl') assertEquals(0x918aa, bit32.replace(0x918ea, 0x2462a, 2, 10, 'cat'), 'replace: extra args') assertEquals(0xd0f0, bit32.replace(0xff0000d2f0, 0x23, 6, 4), 'replace: larger than 32-bits') "); }
public void sub() { Lua.DoText(@" assertEquals('CDE', string.sub('ABCDE', 3), 'sub: normal') assertEquals('DE', string.sub('ABCDE', -2), 'sub: negative start') assertEquals('BCD', string.sub('ABCDE', 2, 4), 'sub: with end') assertEquals('B', string.sub('ABCDE', 2, 2), 'sub: start == end') assertEquals('BCD', string.sub('ABCDE', 2, -2), 'sub: with negative end') assertEquals('', string.sub('ABCDE', 4, 1), 'sub: start > end') "); }
public void bxor() { Lua.DoText(@" assertEquals(0x82, bit32.bxor(0x24, 0xa6), 'bxor: normal') assertEquals(0x0, bit32.bxor(), 'bxor: zero arguments') assertEquals(0xea, bit32.bxor(0xea), 'bxor: one arguement') assertEquals(0x89, bit32.bxor(0x01, 0x83, 0x21, 0x2a), 'bxor: more than two') assertEquals(0x5500f848, bit32.bxor(0xfa005a1e, 0xaf00a256), 'bxor: large number') assertEquals(0xff, bit32.bxor(0xff000000f0, 0xff0000000f), 'bxor: larger than 32-bits') "); }
public void btest() { Lua.DoText(@" assertEquals(false, bit32.btest(0xaa, 0x55), 'btest: normal') assertEquals(true, bit32.btest(), 'btest: zero arguments') assertEquals(true, bit32.btest(0xea), 'btest: one arguement') assertEquals(false, bit32.btest(0x01, 0x83, 0x21, 0x2a), 'btest: more than two') assertEquals(true, bit32.btest(0xfa0000aa, 0xaf00aa00), 'btest: large number') assertEquals(false, bit32.btest(0xff000000f0, 0xff0000000f), 'btest: larger than 32-bits') "); }
public void frexp() { Lua.DoText(@" local a, b = math.frexp(245) assertEqualsDelta(0.95703125, a, 'frexp: normal(1)') assertEquals( 8, b, 'frexp: normal(2)') a, b = math.frexp(-24623) assertEqualsDelta(-0.751434326171, a, 'frexp: negative(1)') assertEquals( 15, b, 'frexp: negative(2)') "); }
public void band() { Lua.DoText(@" assertEquals(0xea, bit32.band(0xff, 0xea), 'band: normal') assertEquals(0xffffffff, bit32.band(), 'band: zero arguments') assertEquals(0xea, bit32.band(0xea), 'band: one arguement') assertEquals(0x22, bit32.band(0xff, 0xea, 0x7f, 0xa3), 'band: more than two') assertEquals(0x00, bit32.band(0x42, 0xea, 0x7a, 0xa1), 'band: clears out') assertEquals(0xaa000000, bit32.band(0xfa0000aa, 0xaf00aa00), 'band: large number') assertEquals(0x0f, bit32.band(0xff0000000f, 0xff0000000f), 'band: larger than 32-bits') "); }
public void rshift() { Lua.DoText(@" assertEquals(0x29d3a28, bit32.rshift(0xa74e8a28, 6), 'rshift: normal') assertEquals(0, bit32.rshift(0xa74e8a28, 65), 'rshift: > 32') assertEquals(0, bit32.rshift(0xa74e8a28, 65, 'cat'), 'rshift: extra args') assertEquals(0x789ec200, bit32.rshift(0x5a789ec2, -8), 'rshift: negative') assertEquals(0, bit32.rshift(0x5a789ec2, -82), 'rshift: negative < -32') assertEquals(0xfffff21, bit32.rshift(-3562, 4), 'rshift: negative source') assertEquals(0xd2f, bit32.rshift(0xff0000d2f0, 4), 'rshift: larger than 32-bits') "); }
public void rrotate() { Lua.DoText(@" assertEquals(0xa29d3a28, bit32.rrotate(0xa74e8a28, 6), 'rrotate: normal') assertEquals(0x53a74514, bit32.rrotate(0xa74e8a28, 65), 'rrotate: > 32') assertEquals(0x53a74514, bit32.rrotate(0xa74e8a28, 65, 'cat'), 'rrotate: extra args') assertEquals(0x789ec25a, bit32.rrotate(0x5a789ec2, -8), 'rrotate: negative') assertEquals(0x7b0969e2, bit32.rrotate(0x5a789ec2, -82), 'rrotate: negative < -32') assertEquals(0x6fffff21, bit32.rrotate(-3562, 4), 'rrotate: negative source') assertEquals(0xd2f, bit32.rrotate(0xff0000d2f0, 4), 'rrotate: larger than 32-bits') "); }
public void lrotate() { Lua.DoText(@" assertEquals(0xd3a28a29, bit32.lrotate(0xa74e8a28, 6), 'lrotate: normal') assertEquals(0x4e9d1451, bit32.lrotate(0xa74e8a28, 65), 'lrotate: > 32') assertEquals(0x4e9d1451, bit32.lrotate(0xa74e8a28, 65, 'cat'), 'lrotate: > 32') assertEquals(0xc25a789e, bit32.lrotate(0x5a789ec2, -8), 'lrotate: negative') assertEquals(0x27b0969e, bit32.lrotate(0x5a789ec2, -82), 'lrotate: negative < -32') assertEquals(0xffff216f, bit32.lrotate(-3562, 4), 'lrotate: negative source') assertEquals(0xd2f00, bit32.lrotate(0xff0000d2f0, 4), 'lrotate: larger than 32-bits') "); }
public void char_() { Lua.DoText(@" -- These use UTF-16 code points. -- The escape sequences are done in C#, so they are passed as Unicode characters to Lua. assertEquals('ABC', string.char(0x41, 0x42, 0x43), 'char: normal') assertEquals('', string.char(), 'char: zero args') assertEquals('" + "\uac20" + @"', string.char(0xac20), 'char: handles UTF-16') assertEquals('" + "\ud801\udc37" + @"', string.char(0xd801, 0xdc37), 'char: handles surrotgate pairs split') assertEquals('" + "\ud801\udc37" + @"', string.char(0x10437), 'char: handles high code points') "); }
public void BaseClass_CantReplaceField() { Lua.DoText(@" class Foobar : BaseClass assertThrows('replace fields with different type', function() Foobar.Field = 'abc' end) assertThrows('replace fields with same type', function() Foobar.Field = 123 end) "); }