Skip to content

Commit

Permalink
a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen committed Jan 25, 2024
1 parent 498ab35 commit e78f4b0
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 12 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
cargo-release
pkg-config
openssl
cargo-llvm-cov

# actions
go-task
Expand Down
19 changes: 11 additions & 8 deletions prqlc/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,23 @@ tasks:
- cmd: cargo clippy --all-targets {{.packages_core}}

test:
desc: A full test of prqlc
desc: |
A full test of prqlc (excluding --test-dbs-external).
Generates coverage report.
env:
# Use a different target dir so we don't poison the cache
CARGO_LLVM_COV_TARGET_DIR: ../target-cov
cmds:
- cmd:
cargo nextest run {{.packages_core}} {{.packages_addon}}
{{.packages_bindings}}
- cmd: |
cargo \
llvm-cov --lcov --output-path lcov.info \
nextest --features=test-dbs \
{{.packages_core}} {{.packages_addon}} {{.packages_bindings}}
- cmd:
cargo clippy --all-targets {{.packages_core}} {{.packages_addon}}
{{.packages_bindings}} -- -D warnings

- cmd:
cargo test --package prqlc --features=default,test-dbs
--test=integration -- queries::results

pull-request:
desc: Most checks that run within GH actions for a pull request
cmds:
Expand Down
80 changes: 76 additions & 4 deletions prqlc/prqlc/src/codegen/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ impl WriteSource for Stmt {
}
_ => {
r += &val.write(opt)?;
r += "\n";
}
}

Expand Down Expand Up @@ -524,6 +525,19 @@ mod test {
assert_is_formatted(r#"join `project-bar.dataset.table` (==col_bax)"#);
}

#[test]
fn test_binary() {
assert_is_formatted(r#"let a = 5 * (4 + 3) ?? (5 / 2) // 2 == 1 and true"#);

// TODO: associativity is not handled correctly
// assert_is_formatted(r#"let a = 5 / 2 / 2"#);
}

#[test]
fn test_func() {
assert_is_formatted(r#"let a = func x y:false -> x and y"#);
}

#[test]
fn test_simple() {
assert_is_formatted(
Expand Down Expand Up @@ -553,15 +567,73 @@ group {title, country} (aggregate {
fn test_range() {
assert_is_formatted(
r#"
from foo
is_negative = -100..0
let negative = -100..0
"#,
);

assert_is_formatted(
r#"
let negative = -(100..0)
"#,
);

assert_is_formatted(
r#"
let negative = -100..
"#,
);

assert_is_formatted(
r#"
let negative = ..-100
"#,
);
}

#[test]
fn test_annotation() {
assert_is_formatted(
r#"
@deprecated
module hello {
}
"#,
);
}

#[test]
fn test_var_def() {
assert_is_formatted(
r#"
let a
"#,
);

assert_is_formatted(
r#"
from foo
is_negative = -(100..0)
let a <int>
"#,
);

assert_is_formatted(
r#"
let a = 5
"#,
);

assert_is_formatted(
r#"
5
into a
"#,
);
}

#[test]
fn test_query_def() {
assert_is_formatted(
r#"
prql version:"^0.9" target:sql.sqlite
"#,
);
}
Expand Down
13 changes: 13 additions & 0 deletions prqlc/prqlc/tests/integration/resolving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ fn resolve_types_04() {
"###);
}

#[test]
fn resolve_types_05() {
// TODO: this is very strange, it should only be allowed in std
assert_snapshot!(resolve(
r#"
type A
"#,
)
.unwrap(), @r###"
type A = null
"###);
}

#[test]
fn resolve_generics_01() {
assert_snapshot!(resolve(
Expand Down
19 changes: 19 additions & 0 deletions prqlc/prqlc/tests/integration/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4959,3 +4959,22 @@ fn test_table_declarations() {
10
"###);
}

#[test]
fn test_param_declarations() {
assert_display_snapshot!(compile(
r###"
let a <int>
from x | filter b == a
"###,
)
.unwrap(), @r###"
SELECT
*
FROM
x
WHERE
b = $a
"###);
}

0 comments on commit e78f4b0

Please sign in to comment.