MCPcopy Index your code
hub / github.com/LissaGreense/GO4SQL / TestParseUpdateCommandWithWhere

Function TestParseUpdateCommandWithWhere

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

Source from the content-addressed store, hash-verified

752}
753
754func 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
807func TestParseLogicOperatorsInCommand(t *testing.T) {
808

Callers

nothing calls this directly

Calls 6

RunLexerFunction · 0.92
testUpdateStatementFunction · 0.85
whereStatementIsValidFunction · 0.85
ParseSequenceMethod · 0.80
NewFunction · 0.70
HasWhereCommandMethod · 0.45

Tested by

no test coverage detected