─── CASE expression ─────────────────────────────────────────────────────────
(t *testing.T)
| 849 | // ─── CASE expression ───────────────────────────────────────────────────────── |
| 850 | |
| 851 | func TestRenderCase_Simple(t *testing.T) { |
| 852 | expr := &ast.CaseExpression{ |
| 853 | Value: &ast.Identifier{Name: "status"}, |
| 854 | WhenClauses: []ast.WhenClause{ |
| 855 | {Condition: &ast.LiteralValue{Value: "1"}, Result: &ast.LiteralValue{Value: "'active'"}}, |
| 856 | {Condition: &ast.LiteralValue{Value: "2"}, Result: &ast.LiteralValue{Value: "'inactive'"}}, |
| 857 | }, |
| 858 | ElseClause: &ast.LiteralValue{Value: "'unknown'"}, |
| 859 | } |
| 860 | result := fmtExpr(expr, ast.ReadableStyle()) |
| 861 | for _, kw := range []string{"CASE", "WHEN", "THEN", "ELSE", "END"} { |
| 862 | if !strings.Contains(result, kw) { |
| 863 | t.Errorf("expected %q in: %s", kw, result) |
| 864 | } |
| 865 | } |
| 866 | if !strings.Contains(result, "status") { |
| 867 | t.Errorf("expected simple CASE value in: %s", result) |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | func TestRenderCase_Searched(t *testing.T) { |
| 872 | expr := &ast.CaseExpression{ |
nothing calls this directly
no test coverage detected