still not right

This commit is contained in:
William Woodruff 2025-07-01 16:16:23 -04:00
parent 1c5a36d1d5
commit fc356a3654
No known key found for this signature in database
2 changed files with 35 additions and 31 deletions

View file

@ -597,9 +597,13 @@ impl Document {
//
// NOTE: We might already be on the block/flow pair if we terminated
// with an absent value, in which case we don't need to do this cleanup.
if focus_node.kind_id() != self.block_mapping_pair_id
|| focus_node.kind_id() == self.flow_node_id
if (matches!(query.route.last(), Some(Component::Key(_)))
&& focus_node.kind_id() != self.block_mapping_pair_id
&& focus_node.kind_id() != self.flow_pair_id)
|| (matches!(query.route.last(), Some(Component::Index(_)))
&& focus_node.kind_id() == self.flow_node_id)
{
dbg!("hmmmm");
focus_node.parent().unwrap()
} else {
focus_node
@ -853,36 +857,36 @@ baz: quux
)
}
#[test]
fn test_basic() {
let doc = r#"
foo: bar
baz:
sub:
keys:
abc:
- 123
- 456
- [a, b, c, {d: e}]
"#;
// #[test]
// fn test_basic() {
// let doc = r#"
// foo: bar
// baz:
// sub:
// keys:
// abc:
// - 123
// - 456
// - [a, b, c, {d: e}]
// "#;
let doc = Document::new(doc).unwrap();
let query = Query {
route: vec![
Component::Key("baz"),
Component::Key("sub"),
Component::Key("keys"),
Component::Key("abc"),
Component::Index(2),
Component::Index(3),
],
};
// let doc = Document::new(doc).unwrap();
// let query = Query {
// route: vec![
// Component::Key("baz"),
// Component::Key("sub"),
// Component::Key("keys"),
// Component::Key("abc"),
// Component::Index(2),
// Component::Index(3),
// ],
// };
assert_eq!(
doc.extract_with_leading_whitespace(&doc.query_pretty(&query).unwrap()),
"{d: e}"
);
}
// assert_eq!(
// doc.extract_with_leading_whitespace(&doc.query_pretty(&query).unwrap()),
// "{d: e}"
// );
// }
#[test]
fn test_flow_pair_in_sequence() {

View file

@ -16,7 +16,7 @@ queries:
- query: [flow1, foo, 2]
# TODO: ideally would be `3: [4, 5, { a: b }]`
expected: "[4, 5, { a: b }]"
expected: "3: [4, 5, { a: b }]"
- query: [flow1, foo, 2, 2]
expected: "{ a: b }"