MCPcopy Index your code
hub / github.com/Masterminds/squirrel / TestCaseWithNoVal

Function TestCaseWithNoVal

case_test.go:55–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

53}
54
55func TestCaseWithNoVal(t *testing.T) {
56 caseStmt := Case().
57 When(Eq{"x": 0}, "x is zero").
58 When(Expr("x > ?", 1), Expr("CONCAT('x is greater than ', ?)", 2))
59
60 qb := Select().Column(caseStmt).From("table")
61 sql, args, err := qb.ToSql()
62
63 assert.NoError(t, err)
64
65 expectedSql := "SELECT CASE " +
66 "WHEN x = ? THEN x is zero " +
67 "WHEN x > ? THEN CONCAT('x is greater than ', ?) " +
68 "END " +
69 "FROM table"
70
71 assert.Equal(t, expectedSql, sql)
72
73 expectedArgs := []interface{}{0, 1, 2}
74 assert.Equal(t, expectedArgs, args)
75}
76
77func TestCaseWithExpr(t *testing.T) {
78 caseStmt := Case(Expr("x = ?", true)).

Callers

nothing calls this directly

Calls 7

CaseFunction · 0.85
ExprFunction · 0.85
SelectFunction · 0.85
WhenMethod · 0.80
ColumnMethod · 0.80
ToSqlMethod · 0.65
FromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…