mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-08 07:56:06 +02:00
AddStatement now passes runtime context for custom handlers
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
|
||||
using YesNt.Interpreter.Attributes;
|
||||
using YesNt.Interpreter.Enums;
|
||||
using YesNt.Interpreter.Runtime;
|
||||
|
||||
namespace YesNt.Interpreter.Tests;
|
||||
|
||||
@@ -333,4 +334,44 @@ public class AddStatementTests
|
||||
interpreter.AddStatement("var", SearchMode.StartOfLine, SpaceAround.End, _ => { });
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddStatementWithRuntimeInfoCanSetVariableTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"set_var foo",
|
||||
"${foo}"
|
||||
];
|
||||
|
||||
YesNtAssert.IsLastLineEqualWithSetup(lines, "hello", interpreter =>
|
||||
{
|
||||
interpreter.AddStatement("set_var", SearchMode.StartOfLine, SpaceAround.End, (args, rt) =>
|
||||
{
|
||||
rt.Variables[args] = "hello";
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddStatementWithRuntimeInfoCanReadVariableTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"var greeting = world",
|
||||
"echo_var greeting"
|
||||
];
|
||||
|
||||
string? captured = null;
|
||||
|
||||
YesNtAssert.GetLastLineWithSetup(lines, interpreter =>
|
||||
{
|
||||
interpreter.AddStatement("echo_var", SearchMode.StartOfLine, SpaceAround.End, (args, rt) =>
|
||||
{
|
||||
_ = rt.Variables.TryGetValue(args, out captured);
|
||||
});
|
||||
});
|
||||
|
||||
Assert.AreEqual("world", captured);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user