-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…cross-scripts accesses)
- Loading branch information
Showing
21 changed files
with
309 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/MoonSharp.Interpreter.Tests/EndToEnd/VarargsTupleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
|
||
namespace MoonSharp.Interpreter.Tests.EndToEnd | ||
{ | ||
[TestFixture] | ||
public class VarargsTupleTests | ||
{ | ||
|
||
|
||
private void DoTest(string code, string expectedResult) | ||
{ | ||
Script S = new Script(); | ||
|
||
S.DoString(@" | ||
function f(a,b) | ||
local debug = 'a: ' .. tostring(a) .. ' b: ' .. tostring(b) | ||
return debug | ||
end | ||
function g(a, b, ...) | ||
local debug = 'a: ' .. tostring(a) .. ' b: ' .. tostring(b) | ||
local arg = {...} | ||
debug = debug .. ' arg: {' | ||
for k, v in pairs(arg) do | ||
debug = debug .. tostring(v) .. ', ' | ||
end | ||
debug = debug .. '}' | ||
return debug | ||
end | ||
function r() | ||
return 1, 2, 3 | ||
end | ||
function h(...) | ||
return g(...) | ||
end | ||
function i(...) | ||
return g('extra', ...) | ||
end | ||
"); | ||
DynValue res = S.DoString("return " + code); | ||
|
||
Assert.AreEqual(res.Type, DataType.String); | ||
Assert.AreEqual(expectedResult, res.String); | ||
} | ||
|
||
[Test] | ||
public void VarArgsTuple_Basic() | ||
{ | ||
DoTest("f(3)", "a: 3 b: nil"); | ||
DoTest("f(3,4)", "a: 3 b: 4"); | ||
DoTest("f(3,4,5)", "a: 3 b: 4"); | ||
DoTest("f(r(),10)", "a: 1 b: 10"); | ||
DoTest("f(r())", "a: 1 b: 2"); | ||
} | ||
|
||
[Test] | ||
public void VarArgsTuple_Intermediate() | ||
{ | ||
DoTest("g(3) ", "a: 3 b: nil arg: {}"); | ||
DoTest("g(3,4) ", "a: 3 b: 4 arg: {}"); | ||
DoTest("g(3,4,5,8) ", "a: 3 b: 4 arg: {5, 8, }"); | ||
DoTest("g(5,r()) ", "a: 5 b: 1 arg: {2, 3, }"); | ||
} | ||
|
||
[Test] | ||
public void VarArgsTuple_Advanced() | ||
{ | ||
//DoTest("h(3) ", "a: 3 b: nil arg: {}"); | ||
//DoTest("h(3,4) ", "a: 3 b: 4 arg: {}"); | ||
//DoTest("h(3,4,5,8) ", "a: 3 b: 4 arg: {5, }"); | ||
DoTest("h(5,r()) ", "a: 5 b: 1 arg: {2, 3, }"); | ||
} | ||
|
||
[Test] | ||
public void VarArgsTuple_Advanced2() | ||
{ | ||
DoTest("i(3) ", "a: extra b: 3 arg: {}"); | ||
DoTest("i(3,4) ", "a: extra b: 3 arg: {4, }"); | ||
DoTest("i(3,4,5,8) ", "a: extra b: 3 arg: {4, 5, 8, }"); | ||
DoTest("i(5,r()) ", "a: extra b: 5 arg: {1, 2, 3, }"); | ||
} | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.