Test BinaryExpression node
(t *testing.T)
| 740 | |
| 741 | // Test BinaryExpression node |
| 742 | func TestBinaryExpression(t *testing.T) { |
| 743 | tests := []struct { |
| 744 | name string |
| 745 | expr *BinaryExpression |
| 746 | wantLiteral string |
| 747 | wantChildren int |
| 748 | }{ |
| 749 | { |
| 750 | name: "equality expression", |
| 751 | expr: &BinaryExpression{ |
| 752 | Left: &Identifier{Name: "id"}, |
| 753 | Operator: "=", |
| 754 | Right: &LiteralValue{Value: "1"}, |
| 755 | }, |
| 756 | wantLiteral: "=", |
| 757 | wantChildren: 2, |
| 758 | }, |
| 759 | { |
| 760 | name: "AND expression", |
| 761 | expr: &BinaryExpression{ |
| 762 | Left: &BinaryExpression{Operator: "="}, |
| 763 | Operator: "AND", |
| 764 | Right: &BinaryExpression{Operator: ">"}, |
| 765 | }, |
| 766 | wantLiteral: "AND", |
| 767 | wantChildren: 2, |
| 768 | }, |
| 769 | { |
| 770 | name: "arithmetic expression", |
| 771 | expr: &BinaryExpression{ |
| 772 | Left: &Identifier{Name: "price"}, |
| 773 | Operator: "*", |
| 774 | Right: &LiteralValue{Value: "1.1"}, |
| 775 | }, |
| 776 | wantLiteral: "*", |
| 777 | wantChildren: 2, |
| 778 | }, |
| 779 | } |
| 780 | |
| 781 | for _, tt := range tests { |
| 782 | tt := tt // G601: Create local copy to avoid memory aliasing |
| 783 | t.Run(tt.name, func(t *testing.T) { |
| 784 | // Test TokenLiteral |
| 785 | if got := tt.expr.TokenLiteral(); got != tt.wantLiteral { |
| 786 | t.Errorf("BinaryExpression.TokenLiteral() = %v, want %v", got, tt.wantLiteral) |
| 787 | } |
| 788 | |
| 789 | // Test Children |
| 790 | children := tt.expr.Children() |
| 791 | if len(children) != tt.wantChildren { |
| 792 | t.Errorf("BinaryExpression.Children() count = %d, want %d", len(children), tt.wantChildren) |
| 793 | } |
| 794 | |
| 795 | // Test that it implements Expression interface |
| 796 | var _ Expression = tt.expr |
| 797 | tt.expr.expressionNode() |
| 798 | }) |
| 799 | } |
nothing calls this directly
no test coverage detected