1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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));
}
|