Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added Assets/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void Test_LoadScript()
public void Test_CallFunction()
{
functions.LoadScript(testCode1, "TestClass1");
double value = functions.Call<double>("test_func0");
double value;
Assert.IsTrue(functions.TryCallFunction("test_func0", out value));
Assert.AreEqual(42.0, value);
}

Expand All @@ -63,15 +64,17 @@ public void Test_CallFunctionFurniture()
{
testFurniture1 = testFurniture1.Replace("'", "\"");
functions.LoadScript(testFurniture1, "FurnitureFunctions");
string value = functions.Call<string>("PowerCellPress_StatusInfo", new Furniture());
string value;
Assert.IsTrue(functions.TryCallFunction("PowerCellPress_StatusInfo", out value, new Furniture()));
Assert.IsTrue(value.Contains("Status"));
}

[Test]
public void Test_CallFunctionDynValue()
{
functions.LoadScript(testCode1, "TestClass1");
DynValue value = functions.Call("test_func0");
DynValue value;
Assert.IsTrue(functions.TryCallFunction("test_func0", out value));
Assert.AreEqual(42.0, value.Number);
}
}
8 changes: 6 additions & 2 deletions Assets/Editor/UnitTests/Models/Functions/FunctionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public void CompareLUAvsCSharp()
sw1.Start();
for (int i = 0; i < iterations; i++)
{
cache.Add(csharpFunctions.Call<string>("PowerCellPress_StatusInfo", new Furniture()));
string tmp;
Assert.IsTrue(luaFunctions.TryCallFunction("PowerCellPress_StatusInfo", out tmp, new Furniture()));
cache.Add(tmp);
}

sw1.Stop();
Expand All @@ -70,7 +72,9 @@ public void CompareLUAvsCSharp()
sw2.Start();
for (int i = 0; i < iterations; i++)
{
cache.Add(luaFunctions.Call<string>("PowerGenerator_FuelInfo", new Furniture()));
string tmp;
Assert.IsTrue(luaFunctions.TryCallFunction("PowerGenerator_FuelInfo", out tmp, new Furniture()));
cache.Add(tmp);
}

sw2.Stop();
Expand Down
14 changes: 9 additions & 5 deletions Assets/Editor/UnitTests/Models/Functions/LuaFunctionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public void Test_CallFunction()
{
// Test a function that dosent return anything (void c# , nil/nan Lua)
functions.LoadScript(testCode1, "testCode1");
DynValue value = functions.Call("test_func0");
DynValue value;
Assert.IsTrue(functions.TryCallFunction("test_func0", out value));
Assert.AreEqual(true, value.IsNilOrNan());
}

Expand All @@ -105,7 +106,8 @@ public void Test_CallFunction_ReturnString()
{
// Test a function that returns a string
functions.LoadScript(testCode1, "testCode1");
DynValue value = functions.Call("test_func1");
DynValue value;
Assert.IsTrue(functions.TryCallFunction("test_func1", out value));
Assert.AreEqual("test_func1_returns", value.CastToString());
}

Expand All @@ -114,7 +116,8 @@ public void Test_CallFunction_InputString_ReturnInput()
{
// Test a function that returns the String passed to it
functions.LoadScript(testCode1, "testCode1");
DynValue value = functions.Call("test_func2", "inputted value");
DynValue value;
Assert.IsTrue(functions.TryCallFunction("test_func2", out value, "inputted value"));
Assert.AreEqual("inputted value", value.CastToString());
}

Expand All @@ -123,10 +126,11 @@ public void Test_CallFunction_InputInts_ReturnSum()
{
// Test passing more than one input
functions.LoadScript(testCode1, "testCode1");
DynValue value = functions.Call("test_func3", 4, 7);
DynValue value;
Assert.IsTrue(functions.TryCallFunction("test_func3", out value, 4, 7));
Assert.AreEqual(11, (int)value.CastToNumber());
}

// TODO: unit tests for LuaFunctions.RegisterGlobal
// TODO: unit tests for LuaFunctions.CallWithInstance
// TODO: unit tests for LuaFunctions.TryCallWithInstance
}
Binary file added Assets/Resources/.DS_Store
Binary file not shown.
7 changes: 0 additions & 7 deletions Assets/Resources/Prefab.meta

This file was deleted.

Loading