MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestCaseExpression

Function TestCaseExpression

pkg/sql/ast/nodes_test.go:924–975  ·  view source on GitHub ↗

Test CaseExpression node

(t *testing.T)

Source from the content-addressed store, hash-verified

922
923// Test CaseExpression node
924func TestCaseExpression(t *testing.T) {
925 tests := []struct {
926 name string
927 caseExpr *CaseExpression
928 wantLiteral string
929 wantChildren int
930 }{
931 {
932 name: "simple CASE with WHEN clauses",
933 caseExpr: &CaseExpression{
934 WhenClauses: []WhenClause{
935 {Condition: &BinaryExpression{Operator: "="}, Result: &LiteralValue{Value: "1"}},
936 {Condition: &BinaryExpression{Operator: ">"}, Result: &LiteralValue{Value: "2"}},
937 },
938 },
939 wantLiteral: "CASE",
940 wantChildren: 2,
941 },
942 {
943 name: "CASE with value and ELSE",
944 caseExpr: &CaseExpression{
945 Value: &Identifier{Name: "status"},
946 WhenClauses: []WhenClause{
947 {Condition: &LiteralValue{Value: "active"}, Result: &LiteralValue{Value: "1"}},
948 },
949 ElseClause: &LiteralValue{Value: "0"},
950 },
951 wantLiteral: "CASE",
952 wantChildren: 3,
953 },
954 }
955
956 for _, tt := range tests {
957 tt := tt // G601: Create local copy to avoid memory aliasing
958 t.Run(tt.name, func(t *testing.T) {
959 // Test TokenLiteral
960 if got := tt.caseExpr.TokenLiteral(); got != tt.wantLiteral {
961 t.Errorf("CaseExpression.TokenLiteral() = %v, want %v", got, tt.wantLiteral)
962 }
963
964 // Test Children
965 children := tt.caseExpr.Children()
966 if len(children) != tt.wantChildren {
967 t.Errorf("CaseExpression.Children() count = %d, want %d", len(children), tt.wantChildren)
968 }
969
970 // Test that it implements Expression interface
971 var _ Expression = tt.caseExpr
972 tt.caseExpr.expressionNode()
973 })
974 }
975}
976
977// Test ExistsExpression node
978func TestExistsExpression(t *testing.T) {

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
TokenLiteralMethod · 0.65
ErrorfMethod · 0.65
ChildrenMethod · 0.65
expressionNodeMethod · 0.65

Tested by

no test coverage detected