-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial implementation of query compilation (#1)
* Add link to source for Sql AST * Remove generics from QueryParser, since it is not necessary * Remove 'NotImplementedException' * Remove new() and Table constraints until it becomes necessary * Remove NoParameters from Union and Union All
- Loading branch information
Showing
56 changed files
with
903 additions
and
739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 43 additions & 2 deletions
45
src/FluentSQL.Tests/Compilation/Builders/QueryCompilerBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,57 @@ | ||
using FluentSQL.Compilation; | ||
using System; | ||
|
||
using FluentSQL.Compilation; | ||
using FluentSQL.Compilation.Parser; | ||
|
||
namespace FluentSQL.Tests.Compilation.Builders | ||
{ | ||
public class QueryCompilerBuilder : TestDataBuilder<QueryCompiler> | ||
{ | ||
protected override void OnPreBuild() | ||
{ | ||
if (Compiler == null) | ||
{ | ||
ThatCompiles(_ => { }); | ||
} | ||
} | ||
|
||
protected override QueryCompiler OnBuild() | ||
{ | ||
return new QueryCompilerStub(); | ||
return new QueryCompilerStub(this); | ||
} | ||
|
||
public QueryCompilerBuilder ThatCompiles(Func<AstNode, string> compiler) | ||
{ | ||
Compiler = compiler; | ||
return this; | ||
} | ||
|
||
public QueryCompilerBuilder ThatCompiles(Action<AstNode> compiler) | ||
{ | ||
return ThatCompiles(x => | ||
{ | ||
compiler(x); | ||
return string.Empty; | ||
}); | ||
} | ||
|
||
private Func<AstNode, string> Compiler { get; set; } | ||
|
||
private class QueryCompilerStub : QueryCompiler | ||
{ | ||
public QueryCompilerStub(QueryCompilerBuilder builder) | ||
{ | ||
Builder = builder; | ||
} | ||
|
||
public override CompilationResult Compile(AstNode node) | ||
{ | ||
string sql = Builder.Compiler(node); | ||
|
||
return new CompilationResult(sql); | ||
} | ||
|
||
private QueryCompilerBuilder Builder { get; } | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/FluentSQL.Tests/Compilation/Parser/Assertions/AstNodeAssertions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using FluentAssertions.Primitives; | ||
|
||
using FluentSQL.Compilation.Parser; | ||
|
||
namespace FluentSQL.Tests.Compilation.Parser.Assertions | ||
{ | ||
public class AstNodeAssertions : ReferenceTypeAssertions<AstNode, AstNodeAssertions> | ||
{ | ||
public AstNodeAssertions(AstNode instance) | ||
{ | ||
Subject = instance; | ||
} | ||
|
||
protected override string Identifier | ||
{ | ||
get { return "astNode"; } | ||
} | ||
|
||
public AndConstraint<AstNodeAssertions> BeEmpty(string because = "", params object[] becauseArgs) | ||
{ | ||
Execute.Assertion | ||
.BecauseOf(because, becauseArgs) | ||
.Given(() => Subject.ChildNodes) | ||
.ForCondition(astNodes => astNodes.Count == 0) | ||
.FailWith("Expected {context:astNode} to be empty, but found {0}", astNodes => astNodes); | ||
|
||
return new AndConstraint<AstNodeAssertions>(this); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/FluentSQL.Tests/Compilation/Parser/Builders/QueryParserBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using FluentSQL.Compilation.Parser; | ||
|
||
namespace FluentSQL.Tests.Compilation.Parser.Builders | ||
{ | ||
public class QueryParserBuilder : TestDataBuilder<QueryParser> | ||
{ | ||
protected override QueryParser OnBuild() | ||
{ | ||
return new QueryParser(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/FluentSQL.Tests/Compilation/Parser/Extensions/AstNodeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using FluentSQL.Compilation.Parser; | ||
using FluentSQL.Tests.Compilation.Parser.Assertions; | ||
|
||
namespace FluentSQL.Tests.Compilation.Parser.Extensions | ||
{ | ||
public static class AstNodeExtensions | ||
{ | ||
public static AstNodeAssertions Should(this AstNode instance) | ||
{ | ||
return new AstNodeAssertions(instance); | ||
} | ||
} | ||
} |
Oops, something went wrong.