(t *testing.T)
| 63 | } |
| 64 | |
| 65 | func TestRenderSelect_Readable(t *testing.T) { |
| 66 | stmt := &ast.SelectStatement{ |
| 67 | Columns: []ast.Expression{&ast.Identifier{Name: "a"}, &ast.Identifier{Name: "b"}}, |
| 68 | From: []ast.TableReference{{Name: "users"}}, |
| 69 | Where: &ast.BinaryExpression{ |
| 70 | Left: &ast.Identifier{Name: "active"}, |
| 71 | Operator: "=", |
| 72 | Right: &ast.LiteralValue{Value: "true"}, |
| 73 | }, |
| 74 | } |
| 75 | |
| 76 | result := fmtStmt(stmt, ast.ReadableStyle()) |
| 77 | lines := strings.Split(result, "\n") |
| 78 | if len(lines) < 3 { |
| 79 | t.Errorf("ReadableStyle should have multiple lines, got %d: %s", len(lines), result) |
| 80 | } |
| 81 | if !strings.HasPrefix(lines[0], "SELECT") { |
| 82 | t.Errorf("first line should start with SELECT, got: %s", lines[0]) |
| 83 | } |
| 84 | if !strings.Contains(result, "FROM") { |
| 85 | t.Errorf("should contain uppercase FROM, got: %s", result) |
| 86 | } |
| 87 | if !strings.Contains(result, "WHERE") { |
| 88 | t.Errorf("should contain uppercase WHERE, got: %s", result) |
| 89 | } |
| 90 | if !strings.HasSuffix(strings.TrimSpace(result), ";") { |
| 91 | t.Errorf("ReadableStyle should end with semicolon, got: %s", result) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func TestRenderSelect_LowercaseKeywords(t *testing.T) { |
| 96 | stmt := &ast.SelectStatement{ |
nothing calls this directly
no test coverage detected