From 7a09d741461999a1b045941f0acdbc65ccfc114f Mon Sep 17 00:00:00 2001 From: Luis Garces Date: Sat, 22 Jun 2024 17:52:51 +0100 Subject: [PATCH] chore: code review changes --- .../Scan/{IScanner.cs => ITokenScanner.cs} | 2 +- .../Pipeline/Scan/ScanContext.cs | 8 ++-- .../Scan/{Scanner.cs => TokenScanner.cs} | 2 +- src/Rules.Framework.Rql/RqlEngine.cs | 8 ++-- src/Rules.Framework.Rql/RqlEngineArgs.cs | 2 +- src/Rules.Framework.Rql/RqlEngineBuilder.cs | 4 +- .../GrammarCheck/GrammarCheckTests.cs | 6 +-- .../RqlEngineTests.cs | 38 +++++++++---------- 8 files changed, 35 insertions(+), 35 deletions(-) rename src/Rules.Framework.Rql/Pipeline/Scan/{IScanner.cs => ITokenScanner.cs} (73%) rename src/Rules.Framework.Rql/Pipeline/Scan/{Scanner.cs => TokenScanner.cs} (99%) diff --git a/src/Rules.Framework.Rql/Pipeline/Scan/IScanner.cs b/src/Rules.Framework.Rql/Pipeline/Scan/ITokenScanner.cs similarity index 73% rename from src/Rules.Framework.Rql/Pipeline/Scan/IScanner.cs rename to src/Rules.Framework.Rql/Pipeline/Scan/ITokenScanner.cs index bcd93a8a..273cd91f 100644 --- a/src/Rules.Framework.Rql/Pipeline/Scan/IScanner.cs +++ b/src/Rules.Framework.Rql/Pipeline/Scan/ITokenScanner.cs @@ -1,6 +1,6 @@ namespace Rules.Framework.Rql.Pipeline.Scan { - internal interface IScanner + internal interface ITokenScanner { ScanResult ScanTokens(string source); } diff --git a/src/Rules.Framework.Rql/Pipeline/Scan/ScanContext.cs b/src/Rules.Framework.Rql/Pipeline/Scan/ScanContext.cs index bbb1f400..641dd2d6 100644 --- a/src/Rules.Framework.Rql/Pipeline/Scan/ScanContext.cs +++ b/src/Rules.Framework.Rql/Pipeline/Scan/ScanContext.cs @@ -86,11 +86,11 @@ private void DiscardTokenCandidate() this.TokenCandidate = null; } - private bool Move(int toOffset) + private bool Move(int offset) { - if (toOffset >= 0 && toOffset < this.source.Length) + if (offset >= 0 && offset < this.source.Length) { - var toChar = this.source[toOffset]; + var toChar = this.source[offset]; if (toChar == '\n') { this.NextLine(); @@ -100,7 +100,7 @@ private bool Move(int toOffset) this.NextColumn(); } - this.Offset = toOffset; + this.Offset = offset; return true; } diff --git a/src/Rules.Framework.Rql/Pipeline/Scan/Scanner.cs b/src/Rules.Framework.Rql/Pipeline/Scan/TokenScanner.cs similarity index 99% rename from src/Rules.Framework.Rql/Pipeline/Scan/Scanner.cs rename to src/Rules.Framework.Rql/Pipeline/Scan/TokenScanner.cs index 4c6a2d07..859165b5 100644 --- a/src/Rules.Framework.Rql/Pipeline/Scan/Scanner.cs +++ b/src/Rules.Framework.Rql/Pipeline/Scan/TokenScanner.cs @@ -7,7 +7,7 @@ namespace Rules.Framework.Rql.Pipeline.Scan using Rules.Framework.Rql.Messages; using Rules.Framework.Rql.Tokens; - internal class Scanner : IScanner + internal class TokenScanner : ITokenScanner { private const char DecimalSeparator = '.'; diff --git a/src/Rules.Framework.Rql/RqlEngine.cs b/src/Rules.Framework.Rql/RqlEngine.cs index 17e46a3e..3b65ec66 100644 --- a/src/Rules.Framework.Rql/RqlEngine.cs +++ b/src/Rules.Framework.Rql/RqlEngine.cs @@ -17,11 +17,11 @@ internal class RqlEngine : IRqlEngine private bool disposedValue; private IInterpreter interpreter; private IParser parser; - private IScanner scanner; + private ITokenScanner tokenScanner; public RqlEngine(RqlEngineArgs rqlEngineArgs) { - this.scanner = rqlEngineArgs.Scanner; + this.tokenScanner = rqlEngineArgs.TokenScanner; this.parser = rqlEngineArgs.Parser; this.interpreter = rqlEngineArgs.Interpreter; } @@ -34,7 +34,7 @@ public void Dispose() public async Task> ExecuteAsync(string rql) { - var scanResult = this.scanner.ScanTokens(rql); + var scanResult = this.tokenScanner.ScanTokens(rql); if (!scanResult.Success) { var errors = scanResult.Messages.Where(m => m.Severity == MessageSeverity.Error) @@ -73,7 +73,7 @@ protected virtual void Dispose(bool disposing) if (disposing) { this.interpreter = null!; - this.scanner = null!; + this.tokenScanner = null!; this.parser = null!; } diff --git a/src/Rules.Framework.Rql/RqlEngineArgs.cs b/src/Rules.Framework.Rql/RqlEngineArgs.cs index 2788320b..5a230c92 100644 --- a/src/Rules.Framework.Rql/RqlEngineArgs.cs +++ b/src/Rules.Framework.Rql/RqlEngineArgs.cs @@ -14,6 +14,6 @@ internal class RqlEngineArgs public IParser Parser { get; set; } - public IScanner Scanner { get; set; } + public ITokenScanner TokenScanner { get; set; } } } \ No newline at end of file diff --git a/src/Rules.Framework.Rql/RqlEngineBuilder.cs b/src/Rules.Framework.Rql/RqlEngineBuilder.cs index 1f1831f7..83053697 100644 --- a/src/Rules.Framework.Rql/RqlEngineBuilder.cs +++ b/src/Rules.Framework.Rql/RqlEngineBuilder.cs @@ -30,7 +30,7 @@ public static RqlEngineBuilder CreateRqlEngine(IRu public IRqlEngine Build() { var runtime = RqlRuntime.Create(this.rulesEngine); - var scanner = new Scanner(); + var tokenScanner = new TokenScanner(); var parseStrategyProvider = new ParseStrategyPool(); var parser = new Parser(parseStrategyProvider); var reverseRqlBuilder = new ReverseRqlBuilder(); @@ -40,7 +40,7 @@ public IRqlEngine Build() Interpreter = interpreter, Options = this.options, Parser = parser, - Scanner = scanner, + TokenScanner = tokenScanner, }; return new RqlEngine(args); diff --git a/tests/Rules.Framework.Rql.IntegrationTests/GrammarCheck/GrammarCheckTests.cs b/tests/Rules.Framework.Rql.IntegrationTests/GrammarCheck/GrammarCheckTests.cs index b30ab6b3..99fe71bd 100644 --- a/tests/Rules.Framework.Rql.IntegrationTests/GrammarCheck/GrammarCheckTests.cs +++ b/tests/Rules.Framework.Rql.IntegrationTests/GrammarCheck/GrammarCheckTests.cs @@ -20,12 +20,12 @@ public class GrammarCheckTests ]; private readonly IParser parser; - private readonly IScanner scanner; private readonly ITestOutputHelper testOutputHelper; + private readonly ITokenScanner tokenScanner; public GrammarCheckTests(ITestOutputHelper testOutputHelper) { - this.scanner = new Scanner(); + this.tokenScanner = new TokenScanner(); this.parser = new Parser(new ParseStrategyPool()); this.testOutputHelper = testOutputHelper; } @@ -111,7 +111,7 @@ public void CheckRqlGrammar(string rqlSource, bool expectsSuccess, IEnumerable errorMessages) { - var scanResult = this.scanner.ScanTokens(rqlSource); + var scanResult = this.tokenScanner.ScanTokens(rqlSource); if (!scanResult.Success) { errorMessages = scanResult.Messages.Select(x => x.Text).ToArray(); diff --git a/tests/Rules.Framework.Rql.Tests/RqlEngineTests.cs b/tests/Rules.Framework.Rql.Tests/RqlEngineTests.cs index ef54e2a6..73c9336f 100644 --- a/tests/Rules.Framework.Rql.Tests/RqlEngineTests.cs +++ b/tests/Rules.Framework.Rql.Tests/RqlEngineTests.cs @@ -22,18 +22,18 @@ public class RqlEngineTests private readonly IInterpreter interpreter; private readonly IParser parser; private readonly RqlEngine rqlEngine; - private readonly IScanner scanner; + private readonly ITokenScanner tokenScanner; public RqlEngineTests() { - this.scanner = Mock.Of(); + this.tokenScanner = Mock.Of(); this.parser = Mock.Of(); this.interpreter = Mock.Of(); var rqlEngineArgs = new RqlEngineArgs { Interpreter = interpreter, Parser = parser, - Scanner = scanner, + TokenScanner = tokenScanner, }; this.rqlEngine = new RqlEngine(rqlEngineArgs); @@ -103,7 +103,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase1_InterpretsAndReturnsResult() interpretResult.AddStatementResult(new NothingStatementResult("MATCH ONE RULE FOR \"Test\" ON $2023-01-01Z$;")); interpretResult.AddStatementResult(new ExpressionStatementResult("MATCH ONE RULE FOR \"Other\\nTest\" ON $2024-01-01Z$;", rqlArray)); - Mock.Get(this.scanner) + Mock.Get(this.tokenScanner) .Setup(x => x.ScanTokens(It.Is(rql, StringComparer.Ordinal))) .Returns(scanResult); Mock.Get(this.parser) @@ -118,7 +118,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase1_InterpretsAndReturnsResult() // Assert Mock.VerifyAll( - Mock.Get(this.scanner), + Mock.Get(this.tokenScanner), Mock.Get(this.parser), Mock.Get(this.interpreter)); @@ -172,7 +172,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase2_InterpretsAndReturnsResult() var interpretResult = new InterpretResult(); interpretResult.AddStatementResult(new ExpressionStatementResult(rql, rqlArray)); - Mock.Get(this.scanner) + Mock.Get(this.tokenScanner) .Setup(x => x.ScanTokens(It.Is(rql, StringComparer.Ordinal))) .Returns(scanResult); Mock.Get(this.parser) @@ -187,7 +187,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase2_InterpretsAndReturnsResult() // Assert Mock.VerifyAll( - Mock.Get(this.scanner), + Mock.Get(this.tokenScanner), Mock.Get(this.parser), Mock.Get(this.interpreter)); @@ -237,7 +237,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase3_InterpretsAndReturnsResult() var interpretResult = new InterpretResult(); interpretResult.AddStatementResult(new ExpressionStatementResult(rql, rqlArray)); - Mock.Get(this.scanner) + Mock.Get(this.tokenScanner) .Setup(x => x.ScanTokens(It.Is(rql, StringComparer.Ordinal))) .Returns(scanResult); Mock.Get(this.parser) @@ -252,7 +252,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase3_InterpretsAndReturnsResult() // Assert Mock.VerifyAll( - Mock.Get(this.scanner), + Mock.Get(this.tokenScanner), Mock.Get(this.parser), Mock.Get(this.interpreter)); @@ -294,7 +294,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase4_InterpretsAndReturnsResult() var interpretResult = new InterpretResult(); interpretResult.AddStatementResult(new ExpressionStatementResult(rql, rqlString)); - Mock.Get(this.scanner) + Mock.Get(this.tokenScanner) .Setup(x => x.ScanTokens(It.Is(rql, StringComparer.Ordinal))) .Returns(scanResult); Mock.Get(this.parser) @@ -309,7 +309,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase4_InterpretsAndReturnsResult() // Assert Mock.VerifyAll( - Mock.Get(this.scanner), + Mock.Get(this.tokenScanner), Mock.Get(this.parser), Mock.Get(this.interpreter)); @@ -340,7 +340,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase5HavingErrorsOnScanner_ThrowsRq }; var scanResult = ScanResult.CreateError(messages); - Mock.Get(this.scanner) + Mock.Get(this.tokenScanner) .Setup(x => x.ScanTokens(It.Is(rql, StringComparer.Ordinal))) .Returns(scanResult); @@ -349,7 +349,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase5HavingErrorsOnScanner_ThrowsRq // Assert Mock.VerifyAll( - Mock.Get(this.scanner)); + Mock.Get(this.tokenScanner)); rqlException.Message.Should().Be("Errors have occurred processing provided RQL source - Sample scan error for source @{1:1}-{1:10}"); rqlException.Errors.Should().HaveCount(1); @@ -380,7 +380,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase6HavingErrorsOnParser_ThrowsRql }; var parseResult = ParseResult.CreateError(messages); - Mock.Get(this.scanner) + Mock.Get(this.tokenScanner) .Setup(x => x.ScanTokens(It.Is(rql, StringComparer.Ordinal))) .Returns(scanResult); Mock.Get(this.parser) @@ -392,7 +392,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase6HavingErrorsOnParser_ThrowsRql // Assert Mock.VerifyAll( - Mock.Get(this.scanner), + Mock.Get(this.tokenScanner), Mock.Get(this.parser)); rqlException.Message.Should().Be("Errors have occurred processing provided RQL source - Sample parse error for source @{1:1}-{1:10}"); @@ -427,7 +427,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase7HavingErrorsOnInterpreter_Thro var interpretResult = new InterpretResult(); interpretResult.AddStatementResult(new ErrorStatementResult("Sample interpret error", rql, RqlSourcePosition.From(1, 1), RqlSourcePosition.From(1, 10))); - Mock.Get(this.scanner) + Mock.Get(this.tokenScanner) .Setup(x => x.ScanTokens(It.Is(rql, StringComparer.Ordinal))) .Returns(scanResult); Mock.Get(this.parser) @@ -442,7 +442,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase7HavingErrorsOnInterpreter_Thro // Assert Mock.VerifyAll( - Mock.Get(this.scanner), + Mock.Get(this.tokenScanner), Mock.Get(this.parser), Mock.Get(this.interpreter)); @@ -478,7 +478,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase8HavingUnknownResultType_Throws var interpretResult = new InterpretResult(); interpretResult.AddStatementResult(new StubResult()); - Mock.Get(this.scanner) + Mock.Get(this.tokenScanner) .Setup(x => x.ScanTokens(It.Is(rql, StringComparer.Ordinal))) .Returns(scanResult); Mock.Get(this.parser) @@ -493,7 +493,7 @@ public async Task ExecuteAsync_GivenRqlSourceCase8HavingUnknownResultType_Throws // Assert Mock.VerifyAll( - Mock.Get(this.scanner), + Mock.Get(this.tokenScanner), Mock.Get(this.parser), Mock.Get(this.interpreter));