Files
inkblot/InkBlot.Tests/LexerTest.cs
2025-03-01 12:30:36 +01:00

34 lines
1.1 KiB
C#

using Antlr4.Runtime;
using Shouldly;
namespace InkBlot.Tests;
public class LexerTest
{
[Fact]
public void TestDivertForLexer()
{
var divertTokens = GetTokens("<- threadName");
divertTokens.ShouldSatisfyAllConditions(
() => divertTokens[0].Text.ShouldBe("<-"),
() => divertTokens[0].Type.ShouldBe(InkBlotAntlrGrammarLexer.THREAD_ARROW),
() => divertTokens[1].Text.ShouldBe(" "),
() => divertTokens[1].Type.ShouldBe(InkBlotAntlrGrammarLexer.WS),
() => divertTokens[2].Text.ShouldBe("threadName"),
() => divertTokens[2].Type.ShouldBe(InkBlotAntlrGrammarLexer.IDENTIFIER),
() => divertTokens[3].Text.ShouldBe("<EOF>"),
() => divertTokens[3].Type.ShouldBe(InkBlotAntlrGrammarLexer.Eof)
);
}
private IList<IToken> GetTokens(string text)
{
var fileReader = new InMemoryFileReader([
("main.ink", text)
]);
var tokensStream = InkBlotParser.GetTokenStream(fileReader, "main.ink");
tokensStream.Fill();
var tokens = tokensStream.GetTokens();
return tokens;
}
}