Add a test demonstrating ERB language loading bug (#32278)

Fixes https://github.com/zed-industries/zed/issues/12174

Release Notes:

- Fixed a bug where ERB files were not parsed correctly when the
languages were initially loaded.
This commit is contained in:
Max Brunsfeld 2025-06-10 21:03:42 -07:00 committed by GitHub
parent ad206a6a97
commit 72de3143c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 145 additions and 18 deletions

View file

@ -788,15 +788,99 @@ fn test_empty_combined_injections_inside_injections(cx: &mut App) {
"(template...",
// Markdown inline content
"(inline)",
// HTML within the ERB
"(document (text))",
// The ruby syntax tree should be empty, since there are
// no interpolations in the ERB template.
"(program)",
// HTML within the ERB
"(document (text))",
],
);
}
#[gpui::test]
fn test_syntax_map_languages_loading_with_erb(cx: &mut App) {
let text = r#"
<body>
<% if @one %>
<div class=one>
<% else %>
<div class=two>
<% end %>
</div>
</body>
"#
.unindent();
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
let mut buffer = Buffer::new(0, BufferId::new(1).unwrap(), text);
let mut syntax_map = SyntaxMap::new(&buffer);
syntax_map.set_language_registry(registry.clone());
let language = Arc::new(erb_lang());
log::info!("parsing");
registry.add(language.clone());
syntax_map.reparse(language.clone(), &buffer);
log::info!("loading html");
registry.add(Arc::new(html_lang()));
syntax_map.reparse(language.clone(), &buffer);
log::info!("loading ruby");
registry.add(Arc::new(ruby_lang()));
syntax_map.reparse(language.clone(), &buffer);
assert_capture_ranges(
&syntax_map,
&buffer,
&["tag", "ivar"],
"
<«body»>
<% if «@one» %>
<«div» class=one>
<% else %>
<«div» class=two>
<% end %>
</«div»>
</«body»>
",
);
let text = r#"
<body>
<% if @one«_hundred» %>
<div class=one>
<% else %>
<div class=two>
<% end %>
</div>
</body>
"#
.unindent();
log::info!("editing");
buffer.edit_via_marked_text(&text);
syntax_map.interpolate(&buffer);
syntax_map.reparse(language.clone(), &buffer);
assert_capture_ranges(
&syntax_map,
&buffer,
&["tag", "ivar"],
"
<«body»>
<% if «@one_hundred» %>
<«div» class=one>
<% else %>
<«div» class=two>
<% end %>
</«div»>
</«body»>
",
);
}
#[gpui::test(iterations = 50)]
fn test_random_syntax_map_edits_rust_macros(rng: StdRng, cx: &mut App) {
let text = r#"