From d1c490dcf0a57ccaa413ec6b8213409f000db4fa Mon Sep 17 00:00:00 2001 From: b3b00 Date: Mon, 1 Jul 2024 11:26:50 +0200 Subject: [PATCH] unit tests --- tests/ParserTests/lexer/GenericLexerTests.cs | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/ParserTests/lexer/GenericLexerTests.cs b/tests/ParserTests/lexer/GenericLexerTests.cs index 77c91af1..c425d7e9 100644 --- a/tests/ParserTests/lexer/GenericLexerTests.cs +++ b/tests/ParserTests/lexer/GenericLexerTests.cs @@ -29,6 +29,15 @@ public enum HexaTokenConflictId [AlphaId] ID } + public enum HexaTokenConflictIdAndInt + { + [Hexa("0x")]HEXA, + + [AlphaId] ID, + + [Int] INT, + } + public enum DateTokenEnglishDashed { @@ -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>()); + 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