Skip to content

Commit

Permalink
reproducer: fails to query trait imported from a dependecy
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed May 14, 2024
1 parent 9fb656a commit 9e5b341
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

63 changes: 63 additions & 0 deletions src/adapter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,69 @@ fn impl_for_ref() {
);
}

#[test]
fn impl_name_for_impl_owners() {
let path = "./localdata/test_data/impl_for_ref/rustdoc.json";
let content = std::fs::read_to_string(path)
.with_context(|| format!("Could not load {path} file, did you forget to run ./scripts/regenerate_test_rustdocs.sh ?"))
.expect("failed to load rustdoc");

let crate_ = serde_json::from_str(&content).expect("failed to parse rustdoc");
let indexed_crate = IndexedCrate::new(&crate_);
let adapter = RustdocAdapter::new(&indexed_crate, None);

let query = r#"
{
Crate {
item {
... on ImplOwner {
name @output
impl {
implemented_trait {
name @output(name: "impls")
}
}
}
}
}
}
"#;

let schema =
Schema::parse(include_str!("../rustdoc_schema.graphql")).expect("schema failed to parse");

#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, serde::Deserialize)]
struct Output {
name: String,
impls: Option<String>,
}

let vars: BTreeMap<&str, &str> = Default::default();
let mut results: Vec<_> = trustfall::execute_query(&schema, adapter.into(), query, vars)
.expect("failed to run query")
.map(|row| row.try_into_struct().expect("shape mismatch"))
.collect();

results.sort_unstable();

// OK
assert!(results.contains(&Output {
name: "StringHolder".to_string(),
impls: Some("PartialEq".to_string())
}));

// Ok
assert!(results.contains(&Output {
name: "StringHolder".to_string(),
impls: Some("Trait".to_string())
}));

// Fails !
assert!(results.contains(&Output {
name: "StringHolder".to_string(),
impls: Some("DummyExternalTrait".to_string())
}));
}
#[test]
fn rustdoc_finds_supertrait() {
let path = "./localdata/test_data/supertrait/rustdoc.json";
Expand Down
6 changes: 6 additions & 0 deletions test_crates/dummy_ext/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "dummy_ext"
version = "0.1.0"
edition = "2021"

[dependencies]
3 changes: 3 additions & 0 deletions test_crates/dummy_ext/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub trait DummyExternalTrait {
fn do_something(&self);
}
1 change: 1 addition & 0 deletions test_crates/impl_for_ref/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dummy_ext = { path = "../dummy_ext" }
8 changes: 8 additions & 0 deletions test_crates/impl_for_ref/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
use dummy_ext::DummyExternalTrait;
pub trait Trait {}

pub struct StringHolder {
content: String,
}

impl Trait for StringHolder {}
impl DummyExternalTrait for StringHolder {
fn do_something(&self) {}
}

impl<'a> PartialEq<StringHolder> for &'a str {
fn eq(&self, other: &StringHolder) -> bool {
(*self).eq(&other.content)
Expand Down

0 comments on commit 9e5b341

Please sign in to comment.