Skip to content

Commit

Permalink
better coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
anton7r committed Jun 21, 2021
1 parent 40dc72f commit ae67269
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Binary file modified coverage_badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions internal/lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func TestCompile(t *testing.T) {
}
}

func TestCompileWrong(t *testing.T) {
_, err := lexer.Compile("SELECT * FROM users WHERE name = :Namd AND email = :EmaiI", &TestStruct{Name: "Foo", Email: "foo@barbar"})
if err == nil {
t.Error("Did not error")
}
}

func BenchmarkCompile(b *testing.B) {
ts := &TestStruct{Name: "Foo", Email: "foo@barbar"}
for i := 0; i < b.N; i++ {
Expand Down
49 changes: 49 additions & 0 deletions internal/lexer/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ func TestNamedComplete(t *testing.T) {
}
}

func TestNamedComplete2(t *testing.T) {
x, err := lexer.PrepareNamed("SELECT * FROM users WHERE name = :Name ORDER BY ID DESC")
if err != nil {
t.Error("Error while testing:" + err.Error())
}

d := &testingStruct{Name: "TEST"}

sql, err2 := lexer.FinalizeNamed(x, d)
if err2 != nil {
t.Error("Error while testing:" + err2.Error())
}

exp := "SELECT * FROM users WHERE name = 'TEST' ORDER BY ID DESC"

if sql != exp {
t.Error("Expected: " + exp + "\nBut instead got:" + sql)
}
}

func TestNamedIncorrectFieldName(t *testing.T) {
x, err := lexer.PrepareNamed("SELECT * FROM users WHERE name = :Namd")
if err != nil {
Expand Down Expand Up @@ -62,6 +82,24 @@ func TestComplete(t *testing.T) {
}
}

func TestComplete2(t *testing.T) {
x, err := lexer.Prepare("SELECT * FROM users WHERE name = $1 ORDER BY ID DESC")
if err != nil {
t.Error("Error while testing:" + err.Error())
}

sql, err2 := lexer.Finalize(x, "TEST")
if err2 != nil {
t.Errorf("Error while testing:" + err2.Error() + "\n %+v", x)
}

exp := "SELECT * FROM users WHERE name = 'TEST' ORDER BY ID DESC"

if sql != exp {
t.Error("Expected: " + exp + "\nBut instead got:" + sql)
}
}

func TestIncorrectIndex(t *testing.T) {
x, err := lexer.Prepare("SELECT * FROM users WHERE name = $2")
if err != nil {
Expand All @@ -74,6 +112,17 @@ func TestIncorrectIndex(t *testing.T) {
}
}

func TestIncorrectIndex2(t *testing.T) {
x, err := lexer.Prepare("SELECT * FROM users WHERE name = $g")
if err != nil {
t.Error("Error while testing:" + err.Error())
}

_, err2 := lexer.Finalize(x, "TEST")
if err2 == nil {
t.Errorf("Did not error!")
}
}
// func TestPrepareNamed(t *testing.T) {

// }

0 comments on commit ae67269

Please sign in to comment.