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

Function TestParser_CastExpression_WithPrecision

pkg/sql/parser/cast_test.go:81–115  ·  view source on GitHub ↗

TestParser_CastExpression_WithPrecision tests CAST with type precision

(t *testing.T)

Source from the content-addressed store, hash-verified

79
80// TestParser_CastExpression_WithPrecision tests CAST with type precision
81func TestParser_CastExpression_WithPrecision(t *testing.T) {
82 // SELECT CAST(price AS DECIMAL(10,2)) FROM products
83 tokens := []token.Token{
84 {Type: models.TokenTypeSelect, Literal: "SELECT"},
85 {Type: models.TokenTypeCast, Literal: "CAST"},
86 {Type: models.TokenTypeLParen, Literal: "("},
87 {Type: models.TokenTypeIdentifier, Literal: "price"},
88 {Type: models.TokenTypeAs, Literal: "AS"},
89 {Type: models.TokenTypeIdentifier, Literal: "DECIMAL"},
90 {Type: models.TokenTypeLParen, Literal: "("},
91 {Type: models.TokenTypeNumber, Literal: "10"},
92 {Type: models.TokenTypeComma, Literal: ","},
93 {Type: models.TokenTypeNumber, Literal: "2"},
94 {Type: models.TokenTypeRParen, Literal: ")"},
95 {Type: models.TokenTypeRParen, Literal: ")"},
96 {Type: models.TokenTypeFrom, Literal: "FROM"},
97 {Type: models.TokenTypeIdentifier, Literal: "products"},
98 }
99
100 parser := NewParser()
101 defer parser.Release()
102
103 tree, err := parser.Parse(tokens)
104 if err != nil {
105 t.Fatalf("unexpected error: %v", err)
106 }
107 defer ast.ReleaseAST(tree)
108
109 stmt := tree.Statements[0].(*ast.SelectStatement)
110 castExpr := stmt.Columns[0].(*ast.CastExpression)
111
112 if castExpr.Type != "DECIMAL(10,2)" {
113 t.Errorf("expected type DECIMAL(10,2), got %s", castExpr.Type)
114 }
115}
116
117// TestParser_CastExpression_VarcharWithLength tests CAST to VARCHAR with length
118func TestParser_CastExpression_VarcharWithLength(t *testing.T) {

Callers

nothing calls this directly

Calls 6

ReleaseMethod · 0.95
ParseMethod · 0.95
ReleaseASTFunction · 0.92
NewParserFunction · 0.70
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected