Unverified Commit 7f6dc089 authored by Vinicius Jarina's avatar Vinicius Jarina Committed by GitHub
Browse files

Fixed #370 Overloaded indexer operators (#371)

* Fixed #370 Overloaded indexer operators

`TryIndexMethods` was testing only the first index method (`get_Item`)

* Fixing flaky test.
parent 4541180d
......@@ -585,7 +585,7 @@ namespace NLua
// If the index type and the parameter doesn't match, just skip it
if (index == null)
break;
continue;
object[] args = new object[1];
......
......@@ -2155,7 +2155,7 @@ namespace NLuaTest
sw.Start();
try
{
for(int i = 0; i < 1000; i++)
for(int i = 0; i < 10000; i++)
lua.DoString($" v:Lengthx{i}() ");
}
catch (Exception e)
......@@ -2169,7 +2169,7 @@ namespace NLuaTest
sw2.Start();
try
{
for (int i = 0; i < 1000; i++)
for (int i = 0; i < 10000; i++)
lua.DoString($" v:Lengthx{i}() ");
}
catch (Exception e)
......@@ -2955,6 +2955,26 @@ namespace NLuaTest
}
}
[Test]
public void TestIndexers()
{
var myClass = new TestClass2();
myClass.teststrval = "Gamma";
Assert.AreEqual("Gamma", myClass.teststrval);
Assert.AreEqual(3, myClass[1]);
Assert.AreEqual(1, myClass["fff"]);
using (var lua = new Lua())
{
lua["mc"] = myClass;
Assert.AreEqual("Gamma", lua.DoString("return mc.teststrval")[0]);
Assert.AreEqual(3, lua.DoString("return mc[1]")[0]);
Assert.AreEqual(1, lua.DoString("return mc['fff']")[0]);
}
}
static Lua m_lua;
}
......
......@@ -70,18 +70,6 @@ namespace NLuaTest.TestTypes
}
}
public int this[int index]
{
get { return 1; }
set { }
}
public int this[string index]
{
get { return 1; }
set { }
}
public TimeSpan? NullableMethod(TimeSpan? input)
{
return input;
......
......@@ -2,6 +2,8 @@
{
public class TestClass2
{
public string teststrval;
public static int func(int x, int y)
{
return x + y;
......@@ -11,5 +13,17 @@
{
return x + y;
}
public int this[int index]
{
get { return 3; }
set { }
}
public int this[string index]
{
get { return 1; }
set { }
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment