51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package vm
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"godb/internals/buffer"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
var inputBuffer = buffer.NewInputBuffer()
|
||
|
|
|
||
|
|
var statement = NewStatement()
|
||
|
|
|
||
|
|
func comapareExpectedAndRetruned(t *testing.T, result, expectedResult PrepareResults, resultingStype, expectedStype statementType) {
|
||
|
|
if result != expectedResult && resultingStype == expectedStype {
|
||
|
|
t.Errorf("Expected prepareResult and stype to be: (%v, %v), got: (%v,%v)\n", expectedResult, expectedStype, result, resultingStype)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestPrepareStatementSelect(t *testing.T) {
|
||
|
|
inputBuffer.Buffer = "select"
|
||
|
|
|
||
|
|
result := statement.PrepareStatements(inputBuffer)
|
||
|
|
|
||
|
|
comapareExpectedAndRetruned(t, result, PrepareSuccess, statement.stype, StatementSelect)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestPrepareStatementInsert(t *testing.T) {
|
||
|
|
inputBuffer.Buffer = "insert 0 hello hello.com"
|
||
|
|
|
||
|
|
result := statement.PrepareStatements(inputBuffer)
|
||
|
|
|
||
|
|
comapareExpectedAndRetruned(t, result, PrepareSuccess, statement.stype, StatementInsert)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestPrepareStatementUnrecognized(t *testing.T) {
|
||
|
|
inputBuffer.Buffer = "something"
|
||
|
|
|
||
|
|
result := statement.PrepareStatements(inputBuffer)
|
||
|
|
|
||
|
|
comapareExpectedAndRetruned(t, result, PrepareUnrecognised, statement.stype, StatementUnrecognized)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestPrepareStatementSyntaxError(t *testing.T) {
|
||
|
|
inputBuffer.Buffer = "insert 0 hello"
|
||
|
|
|
||
|
|
result := statement.PrepareStatements(inputBuffer)
|
||
|
|
|
||
|
|
if result != PrepareSyntaxError {
|
||
|
|
t.Errorf("Expected prepareResult to be: %v, got: %v\n", PrepareSyntaxError, result)
|
||
|
|
}
|
||
|
|
}
|