aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/src/Godosa.Core.Tests/Runs/Scripts/StepLexerTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Godosa.Core.Tests/Runs/Scripts/StepLexerTests.cs')
-rw-r--r--src/Godosa.Core.Tests/Runs/Scripts/StepLexerTests.cs58
1 files changed, 58 insertions, 0 deletions
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<FormatException>(() => 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));
+}