feat: converted unit tests for vm to idiomatic table driven tests
This commit is contained in:
+37
-29
@@ -15,36 +15,44 @@ func comapareExpectedAndRetruned(t *testing.T, result, expectedResult PrepareRes
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareStatementSelect(t *testing.T) {
|
||||
inputBuffer.Buffer = "select"
|
||||
func TestVM(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
prepareStatusExpected PrepareResults
|
||||
statementResultExpected statementType
|
||||
}{
|
||||
{
|
||||
name: "Testing Select Statement",
|
||||
input: "select",
|
||||
prepareStatusExpected: PrepareSuccess,
|
||||
statementResultExpected: StatementSelect,
|
||||
},
|
||||
{
|
||||
name: "Testing Insert Statement",
|
||||
input: "insert 0 hello hello.com",
|
||||
prepareStatusExpected: PrepareSuccess,
|
||||
statementResultExpected: StatementInsert,
|
||||
},
|
||||
{
|
||||
name: "Testing Unrecognized Statement",
|
||||
input: "something",
|
||||
prepareStatusExpected: PrepareUnrecognised,
|
||||
statementResultExpected: StatementUnrecognized,
|
||||
},
|
||||
{
|
||||
name: "Testing Syntax Errors",
|
||||
input: "insert 0 hello",
|
||||
prepareStatusExpected: PrepareSyntaxError,
|
||||
statementResultExpected: StatementUnrecognized,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
inputBuffer.Buffer = test.input
|
||||
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)
|
||||
comapareExpectedAndRetruned(t, result, test.prepareStatusExpected, statement.stype, test.statementResultExpected)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user