Skip to content

Commit

Permalink
test: improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ifiokjr committed Aug 28, 2024
1 parent 53460a2 commit 1e40df1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/edgedb_codegen/tests/compile/macros/absolute_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use edgedb_codegen_macros::edgedb_query_raw;

fn main() {
edgedb_query_raw!(insert_user, file: "/absolute/path/to/queries/insert_user.edgeql");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: absolute paths will only work on the current machine
--> tests/compile/macros/absolute_file.rs:4:39
|
4 | edgedb_query_raw!(insert_user, file: "/absolute/path/to/queries/insert_user.edgeql");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 changes: 3 additions & 3 deletions crates/edgedb_codegen/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ edgedb_query!(
#[tokio::test]
pub async fn simple_query_with_input() -> Result<()> {
let client = create_client().await?;
let input = simple::Input::builder()
.custom("This is a custom field")
.build();
let input = simple::Input {
custom: String::from("This is a custom field"),
};
let output = simple::query(&client, &input).await?;

insta::assert_ron_snapshot!(output, @r###"
Expand Down
4 changes: 4 additions & 0 deletions crates/edgedb_codegen_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ thiserror = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "process"] }
typed-builder = { workspace = true }

[dev-dependencies]
assert2 = { workspace = true }
tokio = { workspace = true, features = ["time", "test-util"] }

[features]
with_bigint = []
with_bigdecimal = []
Expand Down
27 changes: 27 additions & 0 deletions crates/edgedb_codegen_core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,30 @@ pub async fn rustfmt(source: &str) -> Result<String> {
pub fn prettify(source: &str) -> syn::Result<String> {
Ok(prettyplease::unparse(&syn::parse_str(source)?))
}

#[cfg(test)]
mod tests {
use assert2::check;

use super::*;

#[tokio::test]
async fn can_format_file() -> Result<()> {
let content = "struct Foo { content: String, allowed: bool, times: u64 }";
let formatted = rustfmt(content).await?;

// formatting changes based on the version of rust used, so can't check for
// exact output
check!(formatted != content);

Ok(())
}

#[tokio::test]
async fn error_when_formatting_invalid_rust() {
let content = "struct Foo { content: String, allowed: bool, times: u64,,,,, INVALID}";
let result = rustfmt(content).await;

check!(result.is_err(), "result should be an error");
}
}

0 comments on commit 1e40df1

Please sign in to comment.