|
| 1 | +// Copyright 2026 GoSQLX Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + |
| 5 | +package parser_test |
| 6 | + |
| 7 | +import ( |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/ajitpratap0/GoSQLX/pkg/gosqlx" |
| 11 | + "github.com/ajitpratap0/GoSQLX/pkg/sql/keywords" |
| 12 | +) |
| 13 | + |
| 14 | +// TestClickHouseArrayLiteral verifies that the bare-bracket array literal |
| 15 | +// `[1, 2, 3]` parses in the ClickHouse dialect. ClickHouse supports this as |
| 16 | +// a shorthand for `array(1, 2, 3)`. Regression for #482. |
| 17 | +func TestClickHouseArrayLiteral(t *testing.T) { |
| 18 | + queries := map[string]string{ |
| 19 | + "int_literal": `SELECT [1, 2, 3] AS nums`, |
| 20 | + "string_literal": `SELECT ['a', 'b', 'c'] AS words`, |
| 21 | + "empty": `SELECT [] AS empty`, |
| 22 | + "nested": `SELECT [[1, 2], [3, 4]] AS matrix`, |
| 23 | + "in_function": `SELECT arrayJoin([10, 20, 30]) AS x`, |
| 24 | + "mixed_with_col": `SELECT id, [status, type] AS labels FROM events`, |
| 25 | + } |
| 26 | + for name, q := range queries { |
| 27 | + q := q |
| 28 | + t.Run(name, func(t *testing.T) { |
| 29 | + if _, err := gosqlx.ParseWithDialect(q, keywords.DialectClickHouse); err != nil { |
| 30 | + t.Fatalf("ParseWithDialect failed: %v", err) |
| 31 | + } |
| 32 | + }) |
| 33 | + } |
| 34 | +} |
0 commit comments