(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func 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 | |
| 41 | func testCreateStatement(t *testing.T, command ast.Command, expectedTableName string, expectedColumnNames []string, expectedColumTypes []token.Token) bool { |
| 42 | if command.TokenLiteral() != "CREATE" { |
nothing calls this directly
no test coverage detected