generate: Avoid duplicate string tokens in unique symbol map

This commit is contained in:
Max Brunsfeld 2020-03-20 11:35:11 -07:00
parent ae1c51051a
commit a003e5f6bd
2 changed files with 52 additions and 2 deletions

View file

@ -491,7 +491,7 @@ fn test_query_matches_with_wildcard_at_the_root() {
}
#[test]
fn test_query_with_immediate_siblings() {
fn test_query_matches_with_immediate_siblings() {
allocations::record(|| {
let language = get_language("python");
@ -677,6 +677,41 @@ fn test_query_matches_in_language_with_simple_aliases() {
});
}
#[test]
fn test_query_matches_with_different_tokens_with_the_same_string_value() {
allocations::record(|| {
let language = get_language("rust");
let query = Query::new(
language,
r#"
"<" @less
">" @greater
"#,
)
.unwrap();
// In Rust, there are two '<' tokens: one for the binary operator,
// and one with higher precedence for generics.
let source = "const A: B<C> = d < e || f > g;";
let mut parser = Parser::new();
parser.set_language(language).unwrap();
let tree = parser.parse(&source, None).unwrap();
let mut cursor = QueryCursor::new();
let matches = cursor.matches(&query, tree.root_node(), to_callback(source));
assert_eq!(
collect_matches(matches, &query, source),
&[
(0, vec![("less", "<")]),
(1, vec![("greater", ">")]),
(0, vec![("less", "<")]),
(1, vec![("greater", ">")]),
]
);
});
}
#[test]
fn test_query_matches_with_too_many_permutations_to_track() {
allocations::record(|| {