Skip to content

Commit

Permalink
Use multi line debug formatting in asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Oct 10, 2024
1 parent 48cadde commit d21ebd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions examples/querying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ fn main() {
// get_by_name won't panic here since we only find the button in the group
group.get_by_name("Duplicate");

let btn_in_parent = harness.get_all_by_name("Duplicate").next_back().expect("No buttons found");
assert_eq!(btn_in_parent.parent_id().expect("No parent id"), group.id(), "Button is not in the group");
let btn_in_parent = harness
.get_all_by_name("Duplicate")
.next_back()
.expect("No buttons found");
assert_eq!(
btn_in_parent.parent_id().expect("No parent id"),
group.id(),
"Button is not in the group"
);

// query_by and get_by functions will panic if more than one node is found
// harness.get_by_role(Role::Button); // This will panic!
Expand Down
6 changes: 3 additions & 3 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn get_all<'tree>(
let mut iter = query_all(node, by).peekable();
assert!(
iter.peek().is_some(),
"No nodes found matching the query: {debug_query:?}\n\nOn node: {node:?}"
"No nodes found matching the query:\n{debug_query:#?}\n\nOn node:\n{node:#?}"
);
iter
}
Expand All @@ -87,7 +87,7 @@ fn query<'tree>(node: Node<'tree>, by: By<'tree>) -> Option<Node<'tree>> {
if let Some(second) = iter.next() {
let first = result?;
panic!(
"Found two or more nodes matching the query: \n{debug_query:?}\n\nFirst node: {first:?}\nSecond node: {second:?}\
"Found two or more nodes matching the query: \n{debug_query:#?}\n\nFirst node:\n{first:#?}\n\nSecond node: {second:#?}\
\n\nIf you were expecting multiple nodes, use query_all instead of query."
);
}
Expand All @@ -102,7 +102,7 @@ fn get<'tree>(node: Node<'tree>, by: By<'tree>) -> Node<'tree> {
if let Some(node) = option {
node
} else {
panic!("No nodes found matching the query: {debug_query:?}\n\nOn node: {node:?}");
panic!("No nodes found matching the query:\n{debug_query:#?}\n\nOn node:\n{node:#?}");
}
}

Expand Down

0 comments on commit d21ebd3

Please sign in to comment.