(t *testing.T)
| 752 | } |
| 753 | |
| 754 | func TestParseUpdateCommandWithWhere(t *testing.T) { |
| 755 | tests := []struct { |
| 756 | input string |
| 757 | expectedTableName string |
| 758 | expectedChanges map[token.Token]ast.Anonymitifier |
| 759 | expectedWhereCommand ast.Expression |
| 760 | }{ |
| 761 | { |
| 762 | input: "UPDATE tbl SET colName TO 5 WHERE id EQUAL 3;", |
| 763 | expectedTableName: "tbl", |
| 764 | expectedChanges: map[token.Token]ast.Anonymitifier{ |
| 765 | {Type: token.IDENT, Literal: "colName"}: {Token: token.Token{Type: token.LITERAL, Literal: "5"}}, |
| 766 | }, |
| 767 | expectedWhereCommand: ast.ConditionExpression{ |
| 768 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "id"}}, |
| 769 | Right: ast.Anonymitifier{Token: token.Token{Type: token.LITERAL, Literal: "3"}}, |
| 770 | Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"}, |
| 771 | }, |
| 772 | }, |
| 773 | } |
| 774 | |
| 775 | for testIndex, tt := range tests { |
| 776 | lexer := lexer.RunLexer(tt.input) |
| 777 | parserInstance := New(lexer) |
| 778 | sequences, err := parserInstance.ParseSequence() |
| 779 | if err != nil { |
| 780 | t.Fatalf("Got error from parser: %s", err) |
| 781 | } |
| 782 | |
| 783 | if len(sequences.Commands) != 1 { |
| 784 | t.Fatalf("[%d] sequences does not contain 1 statements. got=%d", testIndex, len(sequences.Commands)) |
| 785 | } |
| 786 | |
| 787 | actualUpdateCommand, ok := sequences.Commands[0].(*ast.UpdateCommand) |
| 788 | |
| 789 | if !ok { |
| 790 | t.Errorf("[%d] actualUpdateCommand is not %T. got=%T", testIndex, &ast.UpdateCommand{}, sequences.Commands[0]) |
| 791 | } |
| 792 | |
| 793 | if !testUpdateStatement(t, actualUpdateCommand, tt.expectedTableName, tt.expectedChanges) { |
| 794 | return |
| 795 | } |
| 796 | |
| 797 | if !actualUpdateCommand.HasWhereCommand() { |
| 798 | t.Errorf("[%d] actualUpdateCommand should have where command", testIndex) |
| 799 | } |
| 800 | |
| 801 | if !whereStatementIsValid(t, actualUpdateCommand.WhereCommand, tt.expectedWhereCommand) { |
| 802 | return |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | func TestParseLogicOperatorsInCommand(t *testing.T) { |
| 808 |
nothing calls this directly
no test coverage detected