Skip to content

Commit

Permalink
command: added table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomarrell committed Dec 20, 2019
1 parent debd118 commit aca1b97
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 10 deletions.
1 change: 1 addition & 0 deletions codegen_test.go
@@ -0,0 +1 @@
package lbadd
88 changes: 88 additions & 0 deletions command_test.go
@@ -0,0 +1,88 @@
package lbadd

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_newCommand(t *testing.T) {
type args struct {
cmd string
}

tests := []struct {
name string
args args
want command
}{
{
name: "unknown command",
args: args{cmd: "uh oh"},
want: 0,
},
{
name: "insert",
args: args{cmd: "insert"},
want: 1,
},
{
name: "select",
args: args{cmd: "select"},
want: 2,
},
{
name: "delete",
args: args{cmd: "delete"},
want: 3,
},
{
name: "mixed casing insert",
args: args{cmd: "iNsErT"},
want: 1,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := newCommand(tt.args.cmd)
assert.Equal(t, tt.want, got)
})
}
}

func Test_command_String(t *testing.T) {
tests := []struct {
name string
c command
want string
}{
{
name: "unknown",
c: 0,
want: "UNKNOWN",
},
{
name: "insert",
c: 1,
want: "INSERT",
},
{
name: "select",
c: 2,
want: "SELECT",
},
{
name: "delete",
c: 3,
want: "DELETE",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.c.String()
assert.Equal(t, tt.want, got)
})
}
}
31 changes: 31 additions & 0 deletions executor_test.go
@@ -1 +1,32 @@
package lbadd

import "testing"

func Test_executor_execute(t *testing.T) {
type (
fields struct {
db *db
}
args struct {
instr instruction
}
)

tests := []struct {
name string
fields fields
args args
wantErr bool
}{
// TODO: Add test cases.
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := &executor{db: tt.fields.db}
if err := e.execute(tt.args.instr); (err != nil) != tt.wantErr {
t.Errorf("executor.execute() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
6 changes: 3 additions & 3 deletions parser.go
Expand Up @@ -101,10 +101,10 @@ func (p *parser) doParse() (query, error) {
}
}

// TODO
var reservedWords = []string{
"(", ")", ">=", "<=", "!=", ",", "=", ">", "<", "SELECT", "INSERT INTO", "VALUES", "UPDATE", "DELETE FROM",
"WHERE", "FROM", "SET",
"(", ")", ">=", "<=", "!=", ",", "=", ">", "<",
"SELECT", "INSERT INTO", "VALUES", "UPDATE",
"DELETE FROM", "WHERE", "FROM", "SET",
}

func (p *parser) peek() string {
Expand Down
7 changes: 0 additions & 7 deletions parser_test.go
Expand Up @@ -7,13 +7,6 @@ import (
"github.com/stretchr/testify/assert"
)

// queryType queryType
// tableName string
// conditions []condition
// updates map[string]string
// inserts [][]string
// fields []string

func TestParser(t *testing.T) {
cases := []struct {
name string
Expand Down

0 comments on commit aca1b97

Please sign in to comment.