Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct escaped conversion generation; test with cargo test --no-run. #407

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion trustfall_stubgen/src/edges_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use maplit::btreemap;
use quote::quote;
use trustfall::{Schema, SchemaAdapter, TryIntoStruct};

use crate::util::upper_case_variant_name;

use super::util::escaped_rust_name;

use super::{
Expand Down Expand Up @@ -140,9 +142,10 @@ fn make_edge_resolver_and_call(
},
);

let variant_name = escaped_rust_name(upper_case_variant_name(type_name));
let resolver_fn_name = escaped_rust_name(to_lower_snake_case(edge_name));
let resolver_fn_ident = syn::Ident::new(&resolver_fn_name, proc_macro2::Span::call_site());
let conversion_fn_name = format!("as_{}", escaped_rust_name(to_lower_snake_case(type_name)));
let conversion_fn_name = format!("as_{}", to_lower_snake_case(&variant_name));
let conversion_fn_ident = syn::Ident::new(&conversion_fn_name, proc_macro2::Span::call_site());
let expect_msg = format!("conversion failed, vertex was not a {type_name}");
let todo_msg = format!("get neighbors along edge '{edge_name}' for type '{type_name}'");
Expand Down
11 changes: 7 additions & 4 deletions trustfall_stubgen/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ edition = "2021"
rust-version = "1.70"

[dependencies]
trustfall = "0.5.0"
trustfall = "*"

[workspace]
"#;
Expand All @@ -41,9 +41,12 @@ mod adapter;
lib_rs_path.push("lib.rs");
write_new_file(lib_rs_path.as_path(), lib_rs);

// Run `cargo test --no-run` over the generated code.
// This is like a `cargo check` but includes `#[cfg(test)]` code as well.
let output = Command::new("cargo")
.current_dir(path)
.arg("check")
.arg("test")
.arg("--no-run")
.output()
.expect("failed to execute process");

Expand Down Expand Up @@ -150,12 +153,12 @@ fn test_schema(name: &str) {
}

#[test]
fn test_hackernews_schema() {
fn hackernews_schema() {
test_schema("hackernews")
}

#[test]
fn test_use_reserved_rust_names_in_schema() {
fn use_reserved_rust_names_in_schema() {
test_schema("use_reserved_rust_names_in_schema");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod const_ {
contexts,
|vertex| {
let vertex = vertex
.as_const_()
.as_const()
.expect("conversion failed, vertex was not a const");
todo!("get neighbors along edge 'const' for type 'const'")
},
Expand Down Expand Up @@ -74,7 +74,7 @@ mod continue_ {
contexts,
|vertex| {
let vertex = vertex
.as_continue_()
.as_continue()
.expect("conversion failed, vertex was not a continue");
todo!("get neighbors along edge 'continue' for type 'continue'")
},
Expand Down Expand Up @@ -114,7 +114,7 @@ mod dyn_ {
contexts,
|vertex| {
let vertex = vertex
.as_dyn_()
.as_dyn()
.expect("conversion failed, vertex was not a dyn");
todo!("get neighbors along edge 'dyn' for type 'dyn'")
},
Expand Down Expand Up @@ -154,7 +154,7 @@ mod if_ {
contexts,
|vertex| {
let vertex = vertex
.as_if_()
.as_if()
.expect("conversion failed, vertex was not a if");
todo!("get neighbors along edge 'if' for type 'if'")
},
Expand Down Expand Up @@ -194,7 +194,7 @@ mod mod_ {
contexts,
|vertex| {
let vertex = vertex
.as_mod_()
.as_mod()
.expect("conversion failed, vertex was not a mod");
todo!("get neighbors along edge 'mod' for type 'mod'")
},
Expand Down Expand Up @@ -274,7 +274,7 @@ mod type_ {
contexts,
|vertex| {
let vertex = vertex
.as_type_()
.as_type()
.expect("conversion failed, vertex was not a type");
todo!("get neighbors along edge 'type' for type 'type'")
},
Expand Down Expand Up @@ -314,7 +314,7 @@ mod unsafe_ {
contexts,
|vertex| {
let vertex = vertex
.as_unsafe_()
.as_unsafe()
.expect("conversion failed, vertex was not a unsafe");
todo!("get neighbors along edge 'unsafe' for type 'unsafe'")
},
Expand Down Expand Up @@ -354,7 +354,7 @@ mod where_ {
contexts,
|vertex| {
let vertex = vertex
.as_where_()
.as_where()
.expect("conversion failed, vertex was not a where");
todo!("get neighbors along edge 'where' for type 'where'")
},
Expand Down