Special UserData types for ILists(includes arrays) and IDictionaries

This commit is contained in:
2018-11-21 14:49:59 +01:00
parent 1d24be85d6
commit 105c40bc05
11 changed files with 242 additions and 24 deletions

View File

@@ -0,0 +1,31 @@
using System.Collections.Generic;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
{
public class UserDataDictionaryTests
{
[Fact]
public void BasicStringKeyed()
{
var arr = new Dictionary<string, int>
{
{"test", 100},
{"1234", 90},
{"here", 1683},
};
const string input = @"
function getValue(arr)
return arr[""here""]
end
";
var script = new Script(input);
Assert.Empty(script.Diagnostics.Messages);
var evaluated = script.EvaluateFunction<long>("getValue", new[] {arr});
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal(1683, evaluated);
}
}
}

View File

@@ -0,0 +1,42 @@
using System.Collections.Generic;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
{
public class UserDataListTests
{
[Fact]
public void BasicArrayTest()
{
var arr = new[] {100, 30, 56, 213, 76787};
const string input = @"
function getValue(arr)
return arr[3]
end
";
var script = new Script(input);
Assert.Empty(script.Diagnostics.Messages);
var evaluated = script.EvaluateFunction<long>("getValue", new[] {arr});
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal(56, evaluated);
}
[Fact]
public void BasicListTest()
{
var arr = new List<int> {100, 30, 56, 213, 76787};
const string input = @"
function getValue(arr)
return arr[2]
end
";
var script = new Script(input);
Assert.Empty(script.Diagnostics.Messages);
var evaluated = script.EvaluateFunction<long>("getValue", new[] {arr});
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal(30, evaluated);
}
}
}