Skip to content

Commit

Permalink
chore: code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
luispfgarces committed Jun 22, 2024
1 parent 94662f4 commit 7a09d74
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Rules.Framework.Rql.Pipeline.Scan
{
internal interface IScanner
internal interface ITokenScanner
{
ScanResult ScanTokens(string source);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Rules.Framework.Rql/Pipeline/Scan/ScanContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -100,7 +100,7 @@ private bool Move(int toOffset)
this.NextColumn();
}

this.Offset = toOffset;
this.Offset = offset;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '.';

Expand Down
8 changes: 4 additions & 4 deletions src/Rules.Framework.Rql/RqlEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ internal class RqlEngine<TContentType, TConditionType> : 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;
}
Expand All @@ -34,7 +34,7 @@ public void Dispose()

public async Task<IEnumerable<IResult>> 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)
Expand Down Expand Up @@ -73,7 +73,7 @@ protected virtual void Dispose(bool disposing)
if (disposing)
{
this.interpreter = null!;
this.scanner = null!;
this.tokenScanner = null!;
this.parser = null!;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rules.Framework.Rql/RqlEngineArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ internal class RqlEngineArgs

public IParser Parser { get; set; }

public IScanner Scanner { get; set; }
public ITokenScanner TokenScanner { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Rules.Framework.Rql/RqlEngineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static RqlEngineBuilder<TContentType, TConditionType> CreateRqlEngine(IRu
public IRqlEngine Build()
{
var runtime = RqlRuntime<TContentType, TConditionType>.Create(this.rulesEngine);
var scanner = new Scanner();
var tokenScanner = new TokenScanner();
var parseStrategyProvider = new ParseStrategyPool();
var parser = new Parser(parseStrategyProvider);
var reverseRqlBuilder = new ReverseRqlBuilder();
Expand All @@ -40,7 +40,7 @@ public IRqlEngine Build()
Interpreter = interpreter,
Options = this.options,
Parser = parser,
Scanner = scanner,
TokenScanner = tokenScanner,
};

return new RqlEngine<TContentType, TConditionType>(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public void CheckRqlGrammar(string rqlSource, bool expectsSuccess, IEnumerable<s

private bool TryScanAndParse(string rqlSource, out IEnumerable<string> errorMessages)
{
var scanResult = this.scanner.ScanTokens(rqlSource);
var scanResult = this.tokenScanner.ScanTokens(rqlSource);
if (!scanResult.Success)
{
errorMessages = scanResult.Messages.Select(x => x.Text).ToArray();
Expand Down
38 changes: 19 additions & 19 deletions tests/Rules.Framework.Rql.Tests/RqlEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ public class RqlEngineTests
private readonly IInterpreter interpreter;
private readonly IParser parser;
private readonly RqlEngine<ContentType, ConditionType> rqlEngine;
private readonly IScanner scanner;
private readonly ITokenScanner tokenScanner;

public RqlEngineTests()
{
this.scanner = Mock.Of<IScanner>();
this.tokenScanner = Mock.Of<ITokenScanner>();
this.parser = Mock.Of<IParser>();
this.interpreter = Mock.Of<IInterpreter>();
var rqlEngineArgs = new RqlEngineArgs
{
Interpreter = interpreter,
Parser = parser,
Scanner = scanner,
TokenScanner = tokenScanner,
};

this.rqlEngine = new RqlEngine<ContentType, ConditionType>(rqlEngineArgs);
Expand Down Expand Up @@ -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)
Expand All @@ -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));

Expand Down Expand Up @@ -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)
Expand All @@ -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));

Expand Down Expand Up @@ -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)
Expand All @@ -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));

Expand Down Expand Up @@ -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)
Expand All @@ -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));

Expand Down Expand Up @@ -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);

Expand All @@ -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 <unavailable> @{1:1}-{1:10}");
rqlException.Errors.Should().HaveCount(1);
Expand Down Expand Up @@ -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)
Expand All @@ -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 <unavailable> @{1:1}-{1:10}");
Expand Down Expand Up @@ -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)
Expand All @@ -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));

Expand Down Expand Up @@ -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)
Expand All @@ -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));

Expand Down

0 comments on commit 7a09d74

Please sign in to comment.