Canon/Canon.Tests/GrammarParserTests/TerminatorTests.cs
jackfiled bd3db1b7b7 feat: 添加语法分析基类抽象 (#8)
增加语法分析基类和状态转换接口抽象,为直接生成语法分析器做准备,同时也提前释放一些大对象,降低内存消耗。

Reviewed-on: PostGuard/Canon#8
2024-03-13 16:41:44 +08:00

59 lines
1.9 KiB
C#

using Canon.Core.Enums;
using Canon.Core.GrammarParser;
using Canon.Core.LexicalParser;
namespace Canon.Tests.GrammarParserTests;
public class TerminatorTests
{
[Fact]
public void TerminatorInnerTest()
{
Terminator keywordTerminator1 = new(KeywordType.Array);
Terminator keywordTerminator2 = new(KeywordType.Begin);
Assert.False(keywordTerminator1 == keywordTerminator2);
Assert.False(keywordTerminator1 == Terminator.CharacterTerminator);
Assert.False(keywordTerminator2 == Terminator.IdentifierTerminator);
Terminator keywordTerminator3 = new(KeywordType.Array);
Assert.Equal(keywordTerminator1, keywordTerminator3);
Terminator delimiterTerminator1 = new(DelimiterType.Colon);
Assert.NotEqual(keywordTerminator1, delimiterTerminator1);
}
[Fact]
public void TerminatorAndKeywordSemanticTokenTest()
{
Terminator keywordTerminator = new(KeywordType.Array);
KeywordSemanticToken keywordSemanticToken = new()
{
LinePos = 0, CharacterPos = 0, KeywordType = KeywordType.Array, LiteralValue = "array"
};
Assert.True(keywordTerminator == keywordSemanticToken);
}
[Fact]
public void TerminatorAndDelimiterSemanticTokenTest()
{
Terminator terminator = new(DelimiterType.Period);
DelimiterSemanticToken token = new()
{
LinePos = 0, CharacterPos = 0, DelimiterType = DelimiterType.Period, LiteralValue = "."
};
Assert.True(token == terminator);
}
[Fact]
public void TerminatorAndOperatorSemanticTokenTest()
{
Terminator terminator = new(OperatorType.GreaterEqual);
OperatorSemanticToken token = new()
{
LinePos = 0, CharacterPos = 0, OperatorType = OperatorType.GreaterEqual, LiteralValue = ">="
};
Assert.True(token == terminator);
}
}