add: Variable declaration tests.

This commit is contained in:
jackfiled 2024-08-17 11:37:41 +08:00
parent ed36546b30
commit eedbd5e7e5
3 changed files with 35 additions and 1 deletions

View File

@ -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<char, IEnumerable<char>> parser = Token('a').SkipTill(Token('b')).Many();
ValidateSuccessfulResult(parser, ['b', 'b'], "aaabaab");
}
[Fact]

View File

@ -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<TypeNode>(GrammarParser.TypeParser(), input);
Assert.Equal(value, node.TypeToken.LiteralValue);
}
}

View File

@ -1,7 +1,7 @@
using CanonSharp.Combinator.Extensions;
using CanonSharp.Pascal.Scanner;
namespace CanonSharp.Tests.LexicalAnalyzerTests;
namespace CanonSharp.Tests.ReaderTests;
public class StringReadStateTests
{