Generic For Loops

This commit is contained in:
2018-11-23 18:18:07 +01:00
parent 2db4d0607e
commit 638394d25b
38 changed files with 530 additions and 327 deletions

View File

@@ -79,5 +79,42 @@ return a
Assert.Equal(15, result);
}
[Fact]
public void GenericForLoopValueTest()
{
const string input = @"
arr = {100, 56, 28}
value = 0
for key, val in arr do
value = value + val
end
return value
";
var script = new Script(input, BoundScope, StaticScope);
Assert.Empty(script.Diagnostics.Messages);
var result = script.Evaluate<long>();
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal(184, result);
}
[Fact]
public void GenericForLoopKeyTest()
{
const string input = @"
arr = {100, 56, 28}
value = 0
for key, val in arr do
local keyInt = tonumber(key)
value = value + keyInt
end
return value
";
var script = new Script(input, BoundScope, StaticScope);
Assert.Empty(script.Diagnostics.Messages);
var result = script.Evaluate<long>();
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal(6, result);
}
}
}