Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer consider number literal suffixes as identifiers. #316

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/DynamicExpresso.Core/Detector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,18 @@ public IdentifiersInfo DetectIdentifiers(string expression)
if (IsReservedKeyword(identifier))
continue;

// don't consider member accesses as identifiers (e.g. "x.Length" will only return x but not Length)
if (idGroup.Index > 0 && expression[idGroup.Index - 1] == '.')
continue;
if (idGroup.Index > 0)
{
var previousChar = expression[idGroup.Index - 1];

// don't consider member accesses as identifiers (e.g. "x.Length" will only return x but not Length)
if (previousChar == '.')
continue;

// don't consider number literals as identifiers
if (char.IsDigit(previousChar))
continue;
}

if (_settings.Identifiers.TryGetValue(identifier, out Identifier knownIdentifier))
knownIdentifiers.Add(knownIdentifier);
Expand Down
17 changes: 17 additions & 0 deletions test/DynamicExpresso.UnitTest/DetectIdentifiersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,22 @@ public void Dont_detect_members_with_at()
Assert.AreEqual(1, detectedIdentifiers.UnknownIdentifiers.Count());
Assert.AreEqual("@class", detectedIdentifiers.UnknownIdentifiers.ElementAt(0));
}


[Test]
[TestCase("1L")]
[TestCase("2M")]
[TestCase("3.0D")]
[TestCase("4.0F")]
[TestCase("6.7e-8")]
[TestCase("9U")]
[TestCase("10ul")]
[TestCase("11lu")]
public void Dont_detect_numbers_with_suffix(string code)
{
var target = new Interpreter(InterpreterOptions.Default | InterpreterOptions.LambdaExpressions);
var detectedIdentifiers = target.DetectIdentifiers(code);
Assert.IsEmpty(detectedIdentifiers.UnknownIdentifiers);
}
}
}
Loading