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

Function TestParseSelectCommand

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

Source from the content-addressed store, hash-verified

124}
125
126func TestParseSelectCommand(t *testing.T) {
127 tests := []struct {
128 input string
129 expectedTableName string
130 expectedSpaces []ast.Space
131 expectedDistinct bool
132 }{
133 {"SELECT * FROM TBL;", "TBL", []ast.Space{{ColumnName: token.Token{Type: token.ASTERISK, Literal: "*"}}}, false},
134 {"SELECT ONE, TWO, THREE FROM TBL;", "TBL", []ast.Space{{ColumnName: token.Token{Type: token.IDENT, Literal: "ONE"}}, {ColumnName: token.Token{Type: token.IDENT, Literal: "TWO"}}, {ColumnName: token.Token{Type: token.IDENT, Literal: "THREE"}}}, false},
135 {"SELECT DISTINCT * FROM TBL;", "TBL", []ast.Space{{ColumnName: token.Token{Type: token.ASTERISK, Literal: "*"}}}, true},
136 }
137
138 for testIndex, tt := range tests {
139 lexer := lexer.RunLexer(tt.input)
140 parserInstance := New(lexer)
141 sequences, err := parserInstance.ParseSequence()
142 if err != nil {
143 t.Fatalf("[%d] Got error from parser: %s", testIndex, err)
144 }
145
146 if len(sequences.Commands) != 1 {
147 t.Fatalf("[%d] sequences does not contain 1 statements. got=%d", testIndex, len(sequences.Commands))
148 }
149
150 if !testSelectStatement(t, sequences.Commands[0], tt.expectedTableName, tt.expectedSpaces, tt.expectedDistinct) {
151 return
152 }
153 }
154}
155
156func TestParseWhereCommand(t *testing.T) {
157 firstExpression := ast.ConditionExpression{

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected