fix:测试

This commit is contained in:
duqoo 2024-03-13 17:05:07 +08:00
parent 7ea97ea97e
commit 62b97aa3b6
2 changed files with 12 additions and 2 deletions

View File

@ -215,8 +215,9 @@ public class NumberSemanticToken : SemanticToken
bool hasDecimalPoint = false;
bool hasExponent = false;
bool hasMinusSign = false;
while (now != null && (char.IsDigit(now.Value) || now.Value == '.' || now.Value == 'e' || now.Value == 'E'))
while (now != null && (char.IsDigit(now.Value) || now.Value == '.' || now.Value == 'e' || now.Value == 'E' || now.Value == '-' || now.Value == '+'))
{
if (now.Value == '.')
{
@ -236,6 +237,15 @@ public class NumberSemanticToken : SemanticToken
hasExponent = true;
}
if (now.Value == '-' || now.Value == '+')
{
if (hasMinusSign)
{
break;
}
hasMinusSign = true;
}
buffer.Append(now.Value);
now = now.Next;
}

View File

@ -24,7 +24,7 @@ namespace Canon.Tests.LexicalParserTests
[InlineData("1E-7", 1E-7, NumberType.Real)]
[InlineData("1E", 0, NumberType.Real, false)]
[InlineData("abc", 0, NumberType.Integer, false)]
[InlineData("123abc", 0, NumberType.Integer, false)]
[InlineData("123abc", 123, NumberType.Integer, true)]
public void TestParseNumber(string input, double expected, NumberType expectedNumberType, bool expectedResult = true)
{
LinkedList<char> content = Utils.GetLinkedList(input);