Added length tests.

This commit is contained in:
Paul Knopf 2018-08-17 16:10:56 -04:00
parent ab449ad363
commit 7997adbdc7
2 changed files with 40 additions and 1 deletions

View file

@ -52,7 +52,7 @@ ReturnedValue NetArray::method_length(const FunctionObject *b, const Value *this
THROW_GENERIC_ERROR("The wrapped object can't be treated as an array.");
}
return Encode(scope.engine->newNumberObject(arrayFacade->getLength(netValue->getNetReference())));
return Encode(arrayFacade->getLength(netValue->getNetReference()));
}
ReturnedValue NetArray::getIndexed(const Managed *m, uint index, bool *hasProperty)

View file

@ -0,0 +1,39 @@
using Moq;
using Xunit;
namespace Qml.Net.Tests.Qml
{
public class ArrayTests : BaseQmlTests<ArrayTests.ArrayTestsQml>
{
public class ArrayTestsQml
{
public virtual int[] GetArray()
{
return null;
}
public virtual void Test(object value)
{
}
}
[Fact]
public void Can_get_length()
{
var array = new[] {3, 4, 6};
Mock.Setup(x => x.GetArray()).Returns(array);
Mock.Setup(x => x.Test(3));
RunQmlTest(
"test",
@"
var array = Net.toJsArray(test.getArray())
test.test(array.length)
");
Mock.Verify(x => x.GetArray(), Times.Once);
Mock.Verify(x => x.Test(3), Times.Once);
}
}
}