Skip to content

Commit

Permalink
Add a doc test for the cursor with names
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Dec 14, 2023
1 parent e8574d1 commit 01de21e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/solidity/outputs/cargo/tests/src/doc_examples/cursor_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,20 @@ fn using_iter_combinators() -> Result<()> {
assert_eq!(contract_names, &["Foo", "Bar", "Baz"]);
Ok(())
}

#[test]
fn using_iter_with_node_names() -> Result<()> {
let language = Language::new(Version::parse("0.8.0")?)?;
let parse_output = language.parse(RuleKind::SourceUnit, SOURCE);

let names: Vec<_> = parse_output
.create_tree_cursor()
.with_names()
.filter_map(|(name, node)| (name == "name").then_some(node))
.filter_map(|node| node.as_token_with_kind(&[TokenKind::Identifier]).cloned())
.map(|node| node.text.clone())
.collect();

assert_eq!(names, &["Foo", "Bar", "Baz"]);
Ok(())
}

0 comments on commit 01de21e

Please sign in to comment.