use insta::assert_snapshot;
use super::sql::compile;
#[test]
fn test_bad_error_messages() {
assert_snapshot!(compile(r###"
from film
group
"###).unwrap_err(), @r"
Error:
╭─[ :3:5 ]
│
3 │ group
│ ──┬──
│ ╰──── main expected type `relation`, but found type `func transform relation -> relation`
│
│ Help: Argument might be missing to function std.group?
│
│ Note: Type `relation` expands to `[{..}]`
───╯
");
assert_snapshot!(compile(r#"
let f = country -> country == "Canada"
from employees
filter f location
"#).unwrap_err(), @r"
Error:
╭─[ :5:14 ]
│
5 │ filter f location
│ ────┬───
│ ╰───── Unknown name `location`
───╯
");
assert_snapshot!(compile(r###"
select tracks
from artists
"###).unwrap_err(), @r"
Error:
╭─[ :3:5 ]
│
3 │ from artists
│ ──────┬─────
│ ╰─────── expected a function, but found `default_db.artists`
───╯
");
}
#[test]
fn interpolation_end() {
use insta::assert_debug_snapshot;
let source = r#"from x | select f"{}"#;
assert_debug_snapshot!(prqlc_parser::lexer::lex_source(source).unwrap_err(), @r#"
[
Error {
kind: Error,
span: Some(
0:20-20,
),
reason: Unexpected {
found: "end of input",
},
hints: [],
code: None,
},
]
"#);
assert_snapshot!(compile(source).unwrap_err(), @r#"
Error:
╭─[ :1:21 ]
│
1 │ from x | select f"{}
│ │
│ ╰─ unexpected end of input
───╯
"#);
}
#[test]
fn select_with_extra_fstr() {
assert_snapshot!(compile(r#"
from foo
select lower f"{x}/{y}"
"#).unwrap_err(), @r#"
Error:
╭─[ :3:21 ]
│
3 │ select lower f"{x}/{y}"
│ ┬
│ ╰── Unknown name `x`
───╯
"#);
}
#[test]
fn misplaced_type_error() {
assert_snapshot!(compile(r###"
let foo = 123
from t
select (true && foo)
"###).unwrap_err(), @r"
Error:
╭─[ :2:15 ]
│
2 │ let foo = 123
│ ─┬─
│ ╰─── function std.and, param `right` expected type `bool`, but found type `int`
───╯
");
}
#[test]
fn test_hint_missing_args() {
assert_snapshot!(compile(r###"
from film
select {film_id, lag film_id}
"###).unwrap_err(), @r"
Error:
╭─[ :3:22 ]
│
3 │ select {film_id, lag film_id}
│ ─────┬─────
│ ╰─────── unexpected `(func offset <int> column <array> -> internal std.lag) film_id`
│
│ Help: this is probably a 'bad type' error (we are working on that)
───╯
")
}
#[test]
fn test_relation_literal_contains_literals() {
assert_snapshot!(compile(r###"
[{a=(1+1)}]
"###).unwrap_err(), @r"
Error:
╭─[ :2:9 ]
│
2 │ [{a=(1+1)}]
│ ──┬──
│ ╰──── relation literal expected literals, but found ``(std.add ...)``
───╯
")
}
#[test]
fn nested_groups() {
assert_snapshot!(compile(r###"
from invoices
select {inv = this}
join item = invoice_items (==invoice_id)
group { inv.billing_city } (
group { item.name } (
aggregate {
ct1 = count inv.name,
}
)
)
"###).unwrap_err(), @r"
Error:
╭─[ :9:9 ]
│
9 │ ╭─▶ aggregate {
┆ ┆
11 │ ├─▶ }
│ │
│ ╰─────────────── internal compiler error; tracked at https://github.com/PRQL/prql/issues/3870
────╯
");
}
#[test]
fn just_std() {
assert_snapshot!(compile(r###"
std
"###).unwrap_err(), @r"
Error:
╭─[ :1:1 ]
│
1 │ ╭─▶
2 │ ├─▶ std
│ │
│ ╰───────────── internal compiler error; tracked at https://github.com/PRQL/prql/issues/4474
───╯
");
}