From 02b6397aa357b4aca8dc2ee19e9175e22bb9022f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 30 Sep 2019 16:36:20 -0700 Subject: [PATCH] Add test for advancing query cursor after has already finished --- cli/src/tests/query_test.rs | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cli/src/tests/query_test.rs b/cli/src/tests/query_test.rs index 740d6d73..65f89bfb 100644 --- a/cli/src/tests/query_test.rs +++ b/cli/src/tests/query_test.rs @@ -913,6 +913,49 @@ fn test_query_captures_with_matches_removed() { }); } +#[test] +fn test_query_captures_and_matches_iterators_are_fused() { + allocations::record(|| { + let language = get_language("javascript"); + let query = Query::new( + language, + r#" + (comment) @comment + "#, + ) + .unwrap(); + + let source = " + // one + // two + // three + /* unfinished + "; + + let mut parser = Parser::new(); + parser.set_language(language).unwrap(); + let tree = parser.parse(&source, None).unwrap(); + let mut cursor = QueryCursor::new(); + let mut captures = cursor.captures(&query, tree.root_node(), to_callback(source)); + + assert_eq!(captures.next().unwrap().0.captures[0].index, 0); + assert_eq!(captures.next().unwrap().0.captures[0].index, 0); + assert_eq!(captures.next().unwrap().0.captures[0].index, 0); + assert!(captures.next().is_none()); + assert!(captures.next().is_none()); + assert!(captures.next().is_none()); + drop(captures); + + let mut matches = cursor.matches(&query, tree.root_node(), to_callback(source)); + assert_eq!(matches.next().unwrap().captures[0].index, 0); + assert_eq!(matches.next().unwrap().captures[0].index, 0); + assert_eq!(matches.next().unwrap().captures[0].index, 0); + assert!(matches.next().is_none()); + assert!(matches.next().is_none()); + assert!(matches.next().is_none()); + }); +} + #[test] fn test_query_start_byte_for_pattern() { let language = get_language("javascript");