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

Function TestCaseWithExpr

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

Source from the content-addressed store, hash-verified

75}
76
77func TestCaseWithExpr(t *testing.T) {
78 caseStmt := Case(Expr("x = ?", true)).
79 When("true", Expr("?", "it's true!")).
80 Else("42")
81
82 qb := Select().Column(caseStmt).From("table")
83 sql, args, err := qb.ToSql()
84
85 assert.NoError(t, err)
86
87 expectedSql := "SELECT CASE x = ? " +
88 "WHEN true THEN ? " +
89 "ELSE 42 " +
90 "END " +
91 "FROM table"
92
93 assert.Equal(t, expectedSql, sql)
94
95 expectedArgs := []interface{}{true, "it's true!"}
96 assert.Equal(t, expectedArgs, args)
97}
98
99func TestMultipleCase(t *testing.T) {
100 caseStmtNoval := Case(Expr("x = ?", true)).

Callers

nothing calls this directly

Calls 8

CaseFunction · 0.85
ExprFunction · 0.85
SelectFunction · 0.85
ElseMethod · 0.80
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…