MCPcopy Create free account
hub / github.com/LissaGreense/GO4SQL / TestParserCreateCommand

Function TestParserCreateCommand

parser/parser_test.go:11–39  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestParserCreateCommand(t *testing.T) {
12 tests := []struct {
13 input string
14 expectedTableName string
15 expectedColumnNames []string
16 expectedColumTypes []token.Token
17 }{
18 {"CREATE TABLE TBL( ONE TEXT );", "TBL", []string{"ONE"}, []token.Token{{Type: token.TEXT, Literal: "TEXT"}}},
19 {"CREATE TABLE TBL( ONE TEXT, TWO TEXT, THREE INT);", "TBL", []string{"ONE", "TWO", "THREE"}, []token.Token{{Type: token.TEXT, Literal: "TEXT"}, {Type: token.TEXT, Literal: "TEXT"}, {Type: token.INT, Literal: "INT"}}},
20 {"CREATE TABLE TBL( );", "TBL", []string{}, []token.Token{}},
21 }
22
23 for testIndex, tt := range tests {
24 lexer := lexer.RunLexer(tt.input)
25 parserInstance := New(lexer)
26 sequences, err := parserInstance.ParseSequence()
27 if err != nil {
28 t.Fatalf("[%d] Got error from parser: %s", testIndex, err)
29 }
30
31 if len(sequences.Commands) != 1 {
32 t.Fatalf("[%d] sequences does not contain 1 statements. got=%d", testIndex, len(sequences.Commands))
33 }
34
35 if !testCreateStatement(t, sequences.Commands[0], tt.expectedTableName, tt.expectedColumnNames, tt.expectedColumTypes) {
36 return
37 }
38 }
39}
40
41func testCreateStatement(t *testing.T, command ast.Command, expectedTableName string, expectedColumnNames []string, expectedColumTypes []token.Token) bool {
42 if command.TokenLiteral() != "CREATE" {

Callers

nothing calls this directly

Calls 4

RunLexerFunction · 0.92
testCreateStatementFunction · 0.85
ParseSequenceMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected