Skip to content

Commit f4f1ce2

Browse files
cpsievertclaude
andcommitted
refactor: move parser tests to tree-sitter corpus
Address PR feedback: - Remove comment block referencing planning file - Move tests from src/parser/builder.rs to tree-sitter test corpus Added 3 focused tree-sitter tests covering the key patterns: - Qualified name in function argument: SUM(s.quantity) - Nested function calls: ROUND(AVG(price), 2) - Arithmetic in function argument: SUM(quantity * price) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 017262f commit f4f1ce2

2 files changed

Lines changed: 152 additions & 100 deletions

File tree

src/parser/builder.rs

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,104 +3134,4 @@ mod tests {
31343134
assert!(ok);
31353135
eprintln!("{:?}", palette);
31363136
}
3137-
3138-
// ========================================
3139-
// Parser Limitation Tests (from ggsql-parser-limitations.md)
3140-
// Tests to verify and fix reported parsing issues
3141-
// ========================================
3142-
3143-
#[test]
3144-
fn test_table_alias_prefixes_in_select() {
3145-
// Issue 1: Table alias prefixes in SELECT clause
3146-
// Query like `SELECT p.product_name FROM products p` should parse
3147-
let query = r#"
3148-
SELECT p.product_name, SUM(s.quantity) as total
3149-
FROM sales s JOIN products p ON s.product_id = p.product_id
3150-
GROUP BY p.product_name
3151-
VISUALISE
3152-
DRAW bar MAPPING product_name AS x, total AS y
3153-
"#;
3154-
3155-
let result = parse_test_query(query);
3156-
assert!(result.is_ok(), "Parse failed: {:?}", result);
3157-
}
3158-
3159-
#[test]
3160-
fn test_cross_table_arithmetic() {
3161-
// Issue 2: Cross-table arithmetic expressions
3162-
// `quantity * price` across joined tables should work
3163-
let query = r#"
3164-
WITH t AS (
3165-
SELECT region, SUM(quantity * price) as revenue
3166-
FROM sales JOIN products ON sales.product_id = products.product_id
3167-
GROUP BY region
3168-
)
3169-
VISUALISE FROM t
3170-
DRAW bar MAPPING region AS x, revenue AS y
3171-
"#;
3172-
3173-
let result = parse_test_query(query);
3174-
assert!(result.is_ok(), "Parse failed: {:?}", result);
3175-
}
3176-
3177-
#[test]
3178-
fn test_nested_function_calls() {
3179-
// Issue 3: Nested function calls
3180-
// `ROUND(AVG(price), 2)` should parse
3181-
let query = r#"
3182-
SELECT category, ROUND(AVG(price), 2) as avg_price
3183-
FROM products
3184-
GROUP BY category
3185-
VISUALISE
3186-
DRAW bar MAPPING category AS x, avg_price AS y
3187-
"#;
3188-
3189-
let result = parse_test_query(query);
3190-
assert!(result.is_ok(), "Parse failed: {:?}", result);
3191-
}
3192-
3193-
#[test]
3194-
fn test_full_table_name_qualifiers() {
3195-
// Issue 4: Full table name qualifiers
3196-
// `products.product_name` (full table name, not alias) should work
3197-
let query = r#"
3198-
SELECT products.product_name, SUM(sales.quantity) as total
3199-
FROM sales
3200-
JOIN products ON sales.product_id = products.product_id
3201-
GROUP BY products.product_name
3202-
VISUALISE
3203-
DRAW bar MAPPING product_name AS x, total AS y
3204-
"#;
3205-
3206-
let result = parse_test_query(query);
3207-
assert!(result.is_ok(), "Parse failed: {:?}", result);
3208-
}
3209-
3210-
#[test]
3211-
fn test_simple_cross_table_multiplication() {
3212-
// Simplified version of cross-table arithmetic
3213-
let query = r#"
3214-
SELECT a.x * b.y as result
3215-
FROM a JOIN b ON a.id = b.id
3216-
VISUALISE
3217-
DRAW point MAPPING result AS x
3218-
"#;
3219-
3220-
let result = parse_test_query(query);
3221-
assert!(result.is_ok(), "Parse failed: {:?}", result);
3222-
}
3223-
3224-
#[test]
3225-
fn test_deeply_nested_functions() {
3226-
// Multiple levels of nesting
3227-
let query = r#"
3228-
SELECT COALESCE(NULLIF(TRIM(name), ''), 'Unknown') as clean_name
3229-
FROM data
3230-
VISUALISE
3231-
DRAW bar MAPPING clean_name AS x
3232-
"#;
3233-
3234-
let result = parse_test_query(query);
3235-
assert!(result.is_ok(), "Parse failed: {:?}", result);
3236-
}
32373137
}

tree-sitter-ggsql/test/corpus/basic.txt

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,3 +2102,155 @@ SELECT * FROM "data.csv"
21022102
(qualified_name
21032103
(identifier
21042104
(quoted_identifier))))))))))
2105+
2106+
================================================================================
2107+
Qualified name in function argument
2108+
================================================================================
2109+
2110+
SELECT SUM(s.quantity) FROM sales s VISUALISE DRAW bar MAPPING x AS x
2111+
2112+
--------------------------------------------------------------------------------
2113+
2114+
(query
2115+
(sql_portion
2116+
(sql_statement
2117+
(select_statement
2118+
(select_body
2119+
(function_call
2120+
(identifier
2121+
(bare_identifier))
2122+
(function_args
2123+
(function_arg
2124+
(positional_arg
2125+
(qualified_name
2126+
(identifier
2127+
(bare_identifier))
2128+
(identifier
2129+
(bare_identifier)))))))
2130+
(from_clause
2131+
(table_ref
2132+
table: (qualified_name
2133+
(identifier
2134+
(bare_identifier)))
2135+
alias: (identifier
2136+
(bare_identifier))))))))
2137+
(visualise_statement
2138+
(visualise_keyword)
2139+
(viz_clause
2140+
(draw_clause
2141+
(geom_type)
2142+
(mapping_clause
2143+
(mapping_list
2144+
(mapping_element
2145+
(explicit_mapping
2146+
value: (mapping_value
2147+
(column_reference
2148+
(identifier
2149+
(bare_identifier))))
2150+
aesthetic: (aesthetic_name)))))))))
2151+
2152+
================================================================================
2153+
Nested function calls
2154+
================================================================================
2155+
2156+
SELECT ROUND(AVG(price), 2) as avg FROM data VISUALISE DRAW bar MAPPING x AS x
2157+
2158+
--------------------------------------------------------------------------------
2159+
2160+
(query
2161+
(sql_portion
2162+
(sql_statement
2163+
(select_statement
2164+
(select_body
2165+
(function_call
2166+
(identifier
2167+
(bare_identifier))
2168+
(function_args
2169+
(function_arg
2170+
(positional_arg
2171+
(function_call
2172+
(identifier
2173+
(bare_identifier))
2174+
(function_args
2175+
(function_arg
2176+
(positional_arg
2177+
(qualified_name
2178+
(identifier
2179+
(bare_identifier)))))))))
2180+
(function_arg
2181+
(positional_arg
2182+
(number)))))
2183+
(identifier
2184+
(bare_identifier))
2185+
(identifier
2186+
(bare_identifier))
2187+
(from_clause
2188+
(table_ref
2189+
table: (qualified_name
2190+
(identifier
2191+
(bare_identifier)))))))))
2192+
(visualise_statement
2193+
(visualise_keyword)
2194+
(viz_clause
2195+
(draw_clause
2196+
(geom_type)
2197+
(mapping_clause
2198+
(mapping_list
2199+
(mapping_element
2200+
(explicit_mapping
2201+
value: (mapping_value
2202+
(column_reference
2203+
(identifier
2204+
(bare_identifier))))
2205+
aesthetic: (aesthetic_name)))))))))
2206+
2207+
================================================================================
2208+
Arithmetic in function argument
2209+
================================================================================
2210+
2211+
SELECT SUM(quantity * price) as total FROM data VISUALISE DRAW bar MAPPING x AS x
2212+
2213+
--------------------------------------------------------------------------------
2214+
2215+
(query
2216+
(sql_portion
2217+
(sql_statement
2218+
(select_statement
2219+
(select_body
2220+
(function_call
2221+
(identifier
2222+
(bare_identifier))
2223+
(function_args
2224+
(function_arg
2225+
(positional_arg
2226+
(positional_arg
2227+
(qualified_name
2228+
(identifier
2229+
(bare_identifier))))
2230+
(positional_arg
2231+
(qualified_name
2232+
(identifier
2233+
(bare_identifier))))))))
2234+
(identifier
2235+
(bare_identifier))
2236+
(identifier
2237+
(bare_identifier))
2238+
(from_clause
2239+
(table_ref
2240+
table: (qualified_name
2241+
(identifier
2242+
(bare_identifier)))))))))
2243+
(visualise_statement
2244+
(visualise_keyword)
2245+
(viz_clause
2246+
(draw_clause
2247+
(geom_type)
2248+
(mapping_clause
2249+
(mapping_list
2250+
(mapping_element
2251+
(explicit_mapping
2252+
value: (mapping_value
2253+
(column_reference
2254+
(identifier
2255+
(bare_identifier))))
2256+
aesthetic: (aesthetic_name)))))))))

0 commit comments

Comments
 (0)