fix: added some unit tests for vm
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
package repl
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// in trying to implement unit test for Run we would kinda endup implementing a test which would be somewhat similar to
|
||||||
|
// e2e test which we already have in place under ../tests directory
|
||||||
|
// PrintConsole simply prints godb > to the console, so not sure if we would need a test for that
|
||||||
|
// Skipping unit test for this, while marking it as a TODO
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user