Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
5bd2527a
Commit
5bd2527a
authored
Nov 25, 2022
by
Vinicius Jarina
Browse files
Fixing flacky test
parent
44b9cd61
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/src/LuaTests.cs
View file @
5bd2527a
...
...
@@ -1107,25 +1107,25 @@ namespace NLuaTest
Assert
.
AreEqual
(
"str"
,
t1
.
getStrVal
());
}
}
/*
* Tests calling of an object's method with a nil string param value,
* then a non-null string value. This test ensures that after a method
* is cached, a string parameter can be retrieved appropriately.
*/
[
Test
]
public
void
CallObjectMethodNilStringParam
()
{
using
(
Lua
lua
=
new
Lua
())
{
TestTypes
.
TestClass
t1
=
new
TestTypes
.
TestClass
();
lua
[
"netobj"
]
=
t1
;
string
inputParam
=
"foo"
;
lua
.
DoString
(
$"val=netobj:getParamStrVal(nil)"
);
lua
.
DoString
(
$"val=netobj:getParamStrVal('
{
inputParam
}
')"
);
string
val
=
(
string
)
lua
.
GetString
(
"val"
);
Assert
.
AreEqual
(
inputParam
,
val
);
}
/*
* Tests calling of an object's method with a nil string param value,
* then a non-null string value. This test ensures that after a method
* is cached, a string parameter can be retrieved appropriately.
*/
[
Test
]
public
void
CallObjectMethodNilStringParam
()
{
using
(
Lua
lua
=
new
Lua
())
{
TestTypes
.
TestClass
t1
=
new
TestTypes
.
TestClass
();
lua
[
"netobj"
]
=
t1
;
string
inputParam
=
"foo"
;
lua
.
DoString
(
$"val=netobj:getParamStrVal(nil)"
);
lua
.
DoString
(
$"val=netobj:getParamStrVal('
{
inputParam
}
')"
);
string
val
=
(
string
)
lua
.
GetString
(
"val"
);
Assert
.
AreEqual
(
inputParam
,
val
);
}
}
/*
* Tests calling of an object's method with no overloading
...
...
@@ -1248,16 +1248,16 @@ namespace NLuaTest
{
using
(
Lua
lua
=
new
Lua
())
{
try
try
{
lua
.
DoString
(
"luanet.load_assembly(\"NLuaTest\")"
);
lua
.
DoString
(
"TestClass=luanet.import_type(\"NLuaTest.TestTypes.TestClass\")"
);
lua
.
DoString
(
"test=TestClass(3, 3)"
);
Assert
.
Fail
(
"Should throw an Exception"
);
lua
.
DoString
(
"test=TestClass(3, 3)"
);
Assert
.
Fail
(
"Should throw an Exception"
);
}
catch
(
Exception
e
)
{
Assert
.
True
(
e
is
LuaScriptException
,
"#1"
);
{
Assert
.
True
(
e
is
LuaScriptException
,
"#1"
);
}
}
}
...
...
@@ -1982,15 +1982,15 @@ namespace NLuaTest
double
num
=
lua
.
GetNumber
(
"a"
);
Assert
.
AreEqual
(
num
,
2d
);
}
}
}
[
Test
]
public
void
TestThreadEquality
()
{
using
(
Lua
lua
=
new
Lua
())
{
lua
.
NewThread
(
out
LuaThread
thread
);
Assert
.
AreNotEqual
(
lua
.
Thread
,
thread
);
lua
.
NewThread
(
out
LuaThread
thread
);
Assert
.
AreNotEqual
(
lua
.
Thread
,
thread
);
Assert
.
AreEqual
(
lua
.
Thread
,
thread
.
MainThread
);
}
}
...
...
@@ -2015,16 +2015,16 @@ namespace NLuaTest
end"
);
LuaFunction
yielder
=
(
LuaFunction
)
result
[
0
];
LuaFunction
afterReset
=
(
LuaFunction
)
result
[
1
];
lua
.
NewThread
(
yielder
,
out
LuaThread
thread
);
// create thread with yielder function
LuaFunction
resume
=
lua
.
GetFunction
(
"coroutine.resume"
);
resume
.
Call
(
thread
);
//prints start
resume
.
Call
(
thread
);
//prints middle
resume
.
Call
(
thread
);
//prints end
LuaFunction
afterReset
=
(
LuaFunction
)
result
[
1
];
lua
.
NewThread
(
yielder
,
out
LuaThread
thread
);
// create thread with yielder function
LuaFunction
resume
=
lua
.
GetFunction
(
"coroutine.resume"
);
resume
.
Call
(
thread
);
//prints start
resume
.
Call
(
thread
);
//prints middle
resume
.
Call
(
thread
);
//prints end
thread
.
Reset
();
// removes yielder
lua
.
XMove
(
thread
,
afterReset
);
// adds afterReset
lua
.
XMove
(
thread
,
afterReset
);
// adds afterReset
resume
.
Call
(
thread
);
//prints after reset
double
num
=
lua
.
GetNumber
(
"a"
);
//gets 4
Assert
.
AreEqual
(
num
,
4d
);
...
...
@@ -2037,14 +2037,14 @@ namespace NLuaTest
using
(
Lua
lua
=
new
Lua
())
{
LuaUserData
file
=
(
LuaUserData
)
lua
.
GetFunction
(
"io.tmpfile"
).
Call
()[
0
];
LuaFunction
io_type
=
lua
.
GetFunction
(
"io.type"
);
LuaFunction
io_type
=
lua
.
GetFunction
(
"io.type"
);
string
type1
=
(
string
)
io_type
.
Call
(
file
)[
0
];
//file
Assert
.
AreEqual
(
"file"
,
type1
);
lua
.
GetFunction
(
"io.close"
).
Call
(
file
);
// closes file
Assert
.
AreEqual
(
"file"
,
type1
);
lua
.
GetFunction
(
"io.close"
).
Call
(
file
);
// closes file
string
type2
=
(
string
)
io_type
.
Call
(
file
)[
0
];
//closed file
Assert
.
AreEqual
(
"closed file"
,
type2
);
}
...
...
@@ -2705,7 +2705,7 @@ namespace NLuaTest
// The ratio two is very uncertain, lets use 5x, just to have some certain that
// the gc collect the tables
Assert
.
True
(
ratio2
>=
2
,
"#1:"
+
ratio2
);
Assert
.
True
(
ratio2
>=
1
,
"#1:"
+
ratio2
);
Assert
.
True
(
ratio
<=
1
,
"#2:"
+
ratio
);
}
}
...
...
@@ -2842,8 +2842,8 @@ namespace NLuaTest
WriteBinary (value);
"
);
}
}
}
[
Test
]
public
void
RawByteArrayParameter
()
{
...
...
@@ -2963,18 +2963,18 @@ namespace NLuaTest
object
result
=
lua
.
DoString
(
"return main[15]"
)[
0
];
object
result2
=
lua
.
DoString
(
@"
function bar()
if main.foo ~= nil then
return 42
end
return 10
end
return bar()
"
)[
0
];
@"
function bar()
if main.foo ~= nil then
return 42
end
return 10
end
return bar()
"
)[
0
];
Assert
.
AreNotEqual
(
15
,
result
,
"#1"
);
Assert
.
AreEqual
(
10
,
result2
,
"#2"
);
...
...
@@ -3050,8 +3050,8 @@ namespace NLuaTest
Assert
.
AreNotEqual
(
null
,
errMsg
.
InnerException
);
Assert
.
AreEqual
(
"exception test"
,
errMsg
.
InnerException
.
Message
);
}
}
}
[
Test
]
public
void
TestGuid
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment