forked from Zaid-Ajaj/Npgsql.FSharp.Analyzer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial parsing of INSERT and DELETE queries and string literals
- Loading branch information
Showing
6 changed files
with
258 additions
and
36 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
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
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
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,42 @@ | ||
module ParserDeleteTests | ||
|
||
open Expecto | ||
open NpgsqlFSharpParser | ||
|
||
let testDelete inputQuery expected = | ||
test inputQuery { | ||
match Parser.parse inputQuery with | ||
| Ok (Expr.DeleteQuery query) -> | ||
Expect.equal query expected "The query is parsed correctly" | ||
| Ok somethingElse -> | ||
failwithf "Unexpected delete statement %A" somethingElse | ||
| Error errorMsg -> | ||
failwith errorMsg | ||
} | ||
|
||
let ftestDelete inputQuery expected = | ||
ftest inputQuery { | ||
match Parser.parse inputQuery with | ||
| Ok (Expr.DeleteQuery query) -> | ||
Expect.equal query expected "The query is parsed correctly" | ||
| Ok somethingElse -> | ||
failwithf "Unexpected delete statement %A" somethingElse | ||
| Error errorMsg -> | ||
failwith errorMsg | ||
} | ||
|
||
[<Tests>] | ||
let deleteQueryTests = testList "Parse DELETE tests" [ | ||
testDelete "DELETE FROM users WHERE last_login IS NULL" { | ||
DeleteExpr.Default with | ||
Table = "users" | ||
Where = Some (Expr.Equals(Expr.Null, Expr.Ident "last_login")) | ||
} | ||
|
||
testDelete "DELETE FROM users WHERE luck = 'bad' RETURNING *" { | ||
DeleteExpr.Default with | ||
Table = "users" | ||
Where = Some (Expr.Equals(Expr.Ident "luck", Expr.StringLiteral "bad")) | ||
Returning = [Expr.Star] | ||
} | ||
] |
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,44 @@ | ||
module ParseInsertTests | ||
|
||
open Expecto | ||
open NpgsqlFSharpParser | ||
|
||
let testInsert inputQuery expected = | ||
test inputQuery { | ||
match Parser.parse inputQuery with | ||
| Ok (Expr.InsertQuery query) -> | ||
Expect.equal query expected "The query is parsed correctly" | ||
| Ok somethingElse -> | ||
failwithf "Unexpected insert statement %A" somethingElse | ||
| Error errorMsg -> | ||
failwith errorMsg | ||
} | ||
|
||
let ftestInsert inputQuery expected = | ||
ftest inputQuery { | ||
match Parser.parse inputQuery with | ||
| Ok (Expr.InsertQuery query) -> | ||
Expect.equal query expected "The query is parsed correctly" | ||
| Ok somethingElse -> | ||
failwithf "Unexpected insert statement %A" somethingElse | ||
| Error errorMsg -> | ||
failwith errorMsg | ||
} | ||
|
||
[<Tests>] | ||
let insertQueryTests = testList "Parse INSERT queries" [ | ||
testInsert "INSERT INTO users (username, active) VALUES (@username, true)" { | ||
InsertExpr.Default with | ||
Table = "users" | ||
Columns = ["username"; "active"] | ||
Values = [ Expr.Parameter("@username"); Expr.Boolean true ] | ||
} | ||
|
||
testInsert "INSERT INTO users (username, active) VALUES (@username, true) RETURNING *" { | ||
InsertExpr.Default with | ||
Table = "users" | ||
Columns = ["username"; "active"] | ||
Values = [ Expr.Parameter("@username"); Expr.Boolean true ] | ||
Returning = [Expr.Star] | ||
} | ||
] |
Oops, something went wrong.