Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Jul 2, 2024
1 parent 5750d7a commit d1c490d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/ParserTests/lexer/GenericLexerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public enum HexaTokenConflictId
[AlphaId] ID
}

public enum HexaTokenConflictIdAndInt
{
[Hexa("0x")]HEXA,

[AlphaId] ID,

[Int] INT,
}


public enum DateTokenEnglishDashed
{
Expand Down Expand Up @@ -1227,6 +1236,30 @@ public void TestHexaConflictId()
Check.That(lexerResult.Tokens[3].TokenID).IsEqualTo(HexaTokenConflictId.ID);
Check.That(lexerResult.Tokens[3].Value).IsEqualTo("hello");
}

[Fact]
public void TestHexaConflictIdAndInt()
{
var lexerRes = LexerBuilder.BuildLexer(new BuildResult<ILexer<HexaTokenConflictIdAndInt>>());
Check.That(lexerRes.IsError).IsFalse();
var lexer = lexerRes.Result;

var lexerResult = lexer.Tokenize("0xAA 0x123 0xAb89CF hello 42");
Check.That(lexerResult).IsOkLexing();
Check.That(lexerResult.Tokens).IsNotNull();
Check.That(lexerResult.Tokens).CountIs(6);
Check.That(lexerResult.Tokens.Extracting(x => (x.TokenID,x.HexaIntValue)).Take(3)).IsEqualTo(new List<(HexaTokenConflictIdAndInt,long)>()
{
(HexaTokenConflictIdAndInt.HEXA,Convert.ToInt32("AA",16)),
(HexaTokenConflictIdAndInt.HEXA,Convert.ToInt32("123",16)),
(HexaTokenConflictIdAndInt.HEXA,Convert.ToInt32("AB89CF",16))
});
Check.That(lexerResult.Tokens[3].TokenID).IsEqualTo(HexaTokenConflictIdAndInt.ID);
Check.That(lexerResult.Tokens[3].Value).IsEqualTo("hello");

Check.That(lexerResult.Tokens[4].TokenID).IsEqualTo(HexaTokenConflictIdAndInt.INT);
Check.That(lexerResult.Tokens[4].Value).IsEqualTo("42");
}

[Fact]
public void TestI18nLexerError() // issue #380
Expand Down

0 comments on commit d1c490d

Please sign in to comment.