-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestPatches.cs
More file actions
104 lines (87 loc) · 2.72 KB
/
TestPatches.cs
File metadata and controls
104 lines (87 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using CSLua;
using CSLua.Extensions;
namespace Test;
public sealed class TestPatches
{
[Fact]
public void TestNE()
{
var L = new LuaState();
L.Eval("return false ~= true");
Assert.Equal(LuaType.LUA_TBOOLEAN, L.Type(-1));
Assert.True(L.PopBool());
L.Eval("return false != true");
Assert.Equal(LuaType.LUA_TBOOLEAN, L.Type(-1));
Assert.True(L.PopBool());
}
[Fact]
public void TestCompoundAssignment()
{
var L = new LuaState();
L.Eval("local foo = 1; foo += 1; return foo;");
Assert.Equal(2, L.PopInteger());
L.Eval("local foo = {bar=1}; foo.bar += 1; return foo.bar;");
Assert.Equal(2, L.PopInteger());
L.Eval("local foo = 2; foo -= 1; return foo;");
Assert.Equal(1, L.PopInteger());
L.Eval("local foo = 1; foo *= 2; return foo;");
Assert.Equal(2, L.PopInteger());
L.Eval("local foo = 4; foo /= 2; return foo;");
Assert.Equal(2, L.PopInteger());
L.Eval("local foo = 5; foo %= 3; return foo;");
Assert.Equal(2, L.PopInteger());
L.Eval("local foo = true; foo &= false; return foo;");
Assert.Equal(false, L.PopBool());
L.Eval("local foo = false; foo |= true; return foo;");
Assert.Equal(true, L.PopBool());
L.Eval("local foobar = 'foo'; foobar ..= 'bar'; return foobar;");
Assert.Equal("foobar", L.PopString());
}
[Fact]
public void TestNumUnderscore()
{
var L = new LuaState();
L.Eval("return 1_000;");
Assert.Equal(1000, L.PopInteger());
}
[Fact]
public void TestContinue1()
{
var L = new LuaState();
L.Eval("""
local foo = 0
for i = 1, 10 do
if i % 2 == 0 then continue end
foo += 1
end
return foo
""");
var foo = L.PopInteger();
Assert.Equal(5, foo);
}
[Fact]
public void TestContinue2()
{
var L = new LuaState();
L.OpenLibs();
var r1 = L.DoFile(Path.Join("lua", "continue_valid.lua"));
Assert.Equal(ThreadStatus.LUA_OK, r1);
}
[Fact]
public void TestImplicitIter()
{
// Self-iterating Objects
// http://lua-users.org/files/wiki_insecure/power_patches/5.2/jh-lua-iter-5.2.patch
var L = new LuaState();
L.OpenLibs();
L.Eval("""
local res = 0
for i, v in {1, 2, 3, 4} do
res += v
end
return res
""");
var i = L.PopInteger()!;
Assert.Equal(10, i);
}
}