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

Function TestCaseWithVal

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

Source from the content-addressed store, hash-verified

7)
8
9func TestCaseWithVal(t *testing.T) {
10 caseStmt := Case("number").
11 When("1", "one").
12 When("2", "two").
13 Else(Expr("?", "big number"))
14
15 qb := Select().
16 Column(caseStmt).
17 From("table")
18 sql, args, err := qb.ToSql()
19
20 assert.NoError(t, err)
21
22 expectedSql := "SELECT CASE number " +
23 "WHEN 1 THEN one " +
24 "WHEN 2 THEN two " +
25 "ELSE ? " +
26 "END " +
27 "FROM table"
28 assert.Equal(t, expectedSql, sql)
29
30 expectedArgs := []interface{}{"big number"}
31 assert.Equal(t, expectedArgs, args)
32}
33
34func TestCaseWithComplexVal(t *testing.T) {
35 caseStmt := Case("? > ?", 10, 5).

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…