From eedbd5e7e56fd1fa0a9b1af076157e1212220cb7 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sat, 17 Aug 2024 11:37:41 +0800 Subject: [PATCH] add: Variable declaration tests. --- .../CombinatorsTests/CombinatorParserTests.cs | 14 +++++++++++++ .../ParserTests/VariableDeclarationTests.cs | 20 +++++++++++++++++++ .../ReaderTests/StringReadStateTests.cs | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 CanonSharp.Tests/ParserTests/VariableDeclarationTests.cs diff --git a/CanonSharp.Tests/CombinatorsTests/CombinatorParserTests.cs b/CanonSharp.Tests/CombinatorsTests/CombinatorParserTests.cs index 247f980..927f310 100644 --- a/CanonSharp.Tests/CombinatorsTests/CombinatorParserTests.cs +++ b/CanonSharp.Tests/CombinatorsTests/CombinatorParserTests.cs @@ -103,6 +103,20 @@ public class CombinatorParserTests : ParserTestsBase parser = Token('a').Skip1Till(Token('b')); ValidateSuccessfulResult(parser, 'b', "aaab"); ValidateFailedResult(parser, "b"); + + parser = Token('a').SkipTill(Choice( + Token('b'), Token('c'))); + + ValidateSuccessfulResult(parser, 'b', "aaab"); + ValidateSuccessfulResult(parser, 'c', "ac"); + } + + [Fact] + public void SkipTillManyTest() + { + IParser> parser = Token('a').SkipTill(Token('b')).Many(); + + ValidateSuccessfulResult(parser, ['b', 'b'], "aaabaab"); } [Fact] diff --git a/CanonSharp.Tests/ParserTests/VariableDeclarationTests.cs b/CanonSharp.Tests/ParserTests/VariableDeclarationTests.cs new file mode 100644 index 0000000..2501c7f --- /dev/null +++ b/CanonSharp.Tests/ParserTests/VariableDeclarationTests.cs @@ -0,0 +1,20 @@ +using CanonSharp.Pascal.Parser; +using CanonSharp.Pascal.SyntaxTree; +using CanonSharp.Tests.Utils; + +namespace CanonSharp.Tests.ParserTests; + +public class VariableDeclarationTests : GrammarParserTestBase +{ + [Theory] + [InlineData("boolean", "boolean")] + [InlineData("integer", "integer")] + [InlineData("char", "char")] + [InlineData("real", "real")] + public void TypeParseTest(string input, string value) + { + TypeNode node = RunParser(GrammarParser.TypeParser(), input); + Assert.Equal(value, node.TypeToken.LiteralValue); + } +} + diff --git a/CanonSharp.Tests/ReaderTests/StringReadStateTests.cs b/CanonSharp.Tests/ReaderTests/StringReadStateTests.cs index 2f0a426..beaaead 100644 --- a/CanonSharp.Tests/ReaderTests/StringReadStateTests.cs +++ b/CanonSharp.Tests/ReaderTests/StringReadStateTests.cs @@ -1,7 +1,7 @@ using CanonSharp.Combinator.Extensions; using CanonSharp.Pascal.Scanner; -namespace CanonSharp.Tests.LexicalAnalyzerTests; +namespace CanonSharp.Tests.ReaderTests; public class StringReadStateTests {