Skip to content

Commit

Permalink
Update Constant test with extra properties
Browse files Browse the repository at this point in the history
expr/value/is_literal
  • Loading branch information
eugenesvk committed Oct 8, 2023
1 parent e0ced16 commit c109df4
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/adapter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ fn rustdoc_finds_consts() {
item {
... on Constant {
name @output
expr @output
value @output
is_literal @output
importable_path {
path @output
Expand All @@ -190,24 +193,45 @@ fn rustdoc_finds_consts() {
struct Output {
name: String,
path: Vec<String>,
expr: String,
value: Option<String>,
is_literal: bool,
}
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, serde::Deserialize)]
struct OutputSimple {
name: String,
path: Vec<String>,
}

let mut results: Vec<_> =
trustfall::execute_query(&schema, adapter.clone(), query, variables.clone())
.expect("failed to run query")
.map(|row| row.try_into_struct().expect("shape mismatch"))
.map(|row| row.try_into_struct::<Output>().expect("shape mismatch"))
.collect();
results.sort_unstable();
// to compare to GlobalValue that doesn't Constant-specific properties
let mut results_simple: Vec<_> =
trustfall::execute_query(&schema, adapter.clone(), query, variables.clone())
.expect("failed to run query")
.map(|row| row.try_into_struct::<OutputSimple>().expect("shape mismatch"))
.collect();
results_simple.sort_unstable();

similar_asserts::assert_eq!(
vec![
Output {
name: "FIRST".into(),
path: vec!["consts".into(), "FIRST".into()],
expr: "1".to_string().into(),
value: Some("1u32".to_string()).into(),
is_literal: true,
},
Output {
name: "SECOND".into(),
path: vec!["consts".into(), "inner".into(), "SECOND".into()],
expr: "2".to_string().into(),
value: Some("2i64".to_string()).into(),
is_literal: true,
},
],
results
Expand All @@ -232,10 +256,10 @@ fn rustdoc_finds_consts() {
let mut global_values_results: Vec<_> =
trustfall::execute_query(&schema, adapter, global_values_query, variables)
.expect("failed to run query")
.map(|row| row.try_into_struct().expect("shape mismatch"))
.map(|row| row.try_into_struct::<OutputSimple>().expect("shape mismatch"))
.collect();
global_values_results.sort_unstable();
assert_eq!(results, global_values_results);
assert_eq!(results_simple, global_values_results);
}

#[test]
Expand Down

0 comments on commit c109df4

Please sign in to comment.