From 39066900773e7857faf2d02e7ed51b71d219d97d Mon Sep 17 00:00:00 2001 From: godosa Date: Tue, 6 Oct 2026 23:39:36 +0200 Subject: godosa-engine: initial public history --- .../Runs/Scripts/StepLexerTests.cs | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Godosa.Core.Tests/Runs/Scripts/StepLexerTests.cs (limited to 'src/Godosa.Core.Tests/Runs/Scripts/StepLexerTests.cs') diff --git a/src/Godosa.Core.Tests/Runs/Scripts/StepLexerTests.cs b/src/Godosa.Core.Tests/Runs/Scripts/StepLexerTests.cs new file mode 100644 index 0000000..0f787dc --- /dev/null +++ b/src/Godosa.Core.Tests/Runs/Scripts/StepLexerTests.cs @@ -0,0 +1,58 @@ +using Godosa.Core.Runs.Scripts; +using Xunit; + +namespace Godosa.Core.Tests.Runs.Scripts; + +public class StepLexerTests +{ + [Theory] + [InlineData("click 10,20 # aim", "click 10,20 ")] + [InlineData("log \"a # b\" # c", "log \"a # b\" ")] + [InlineData("# only", "")] + [InlineData("type \"say \\\"#1\\\"\"", "type \"say \\\"#1\\\"\"")] + public void StripComment_OutsideQuotesOnly(string line, string expected) => + Assert.Equal(expected, StepLexer.StripComment(line)); + + [Fact] + public void Tokens_SplitOnSpaceQuotedStaysWhole() + { + var t = StepLexer.Tokens("use @inv(Lockpicks) on \"Big Door\""); + Assert.Equal(["use", "@inv(Lockpicks)", "on", "Big Door"], t.Select(x => x.Text)); + Assert.Equal([false, false, false, true], t.Select(x => x.Quoted)); + } + + [Fact] + public void Tokens_EscapesInQuotes() + { + var t = StepLexer.Tokens("type \"a \\\"b\\\" \\\\ c\""); + Assert.Equal("a \"b\" \\ c", t[1].Text); + } + + [Fact] + public void Tokens_ParenthesesKeepSpacesInOneToken() + { + // locator args may contain spaces: @npc(Gilbert Bates) + var t = StepLexer.Tokens("talk @npc(Gilbert Bates)"); + Assert.Equal(["talk", "@npc(Gilbert Bates)"], t.Select(x => x.Text)); + } + + [Fact] + public void Tokens_UnterminatedQuote_Throws() => + Assert.Equal("unterminated quote", Assert.Throws(() => StepLexer.Tokens("log \"abc")).Message); + + [Theory] + [InlineData("120", 120)] + [InlineData("2s", 120)] + [InlineData("0.5s", 30)] + [InlineData("0", 0)] + [InlineData("1.25s", 75)] + public void Durations_FramesAndSeconds(string text, int frames) => Assert.Equal(frames, Durations.Frames(text)); + + [Theory] + [InlineData("0.01s")] // 0.6 frames: not whole + [InlineData("-5")] + [InlineData("2m")] + [InlineData("")] + [InlineData("1e3")] + public void Durations_Invalid_Null(string text) => Assert.Null(Durations.Frames(text)); +} -- cgit