Allow testing highlight and tag queries when testing wasm build
Replace non-mutating `ts_parser_wasm_store` function with `ts_parser_take_wasm_store`, which removes and returns the wasm store, in order to facilitate single ownership.
This commit is contained in:
parent
35ce2e47ec
commit
555277a102
7 changed files with 84 additions and 13 deletions
|
|
@ -9,7 +9,9 @@ use tree_sitter_cli::{
|
|||
util, wasm,
|
||||
};
|
||||
use tree_sitter_config::Config;
|
||||
use tree_sitter_highlight::Highlighter;
|
||||
use tree_sitter_loader as loader;
|
||||
use tree_sitter_tags::TagsContext;
|
||||
|
||||
const BUILD_VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
const BUILD_SHA: Option<&'static str> = option_env!("BUILD_SHA");
|
||||
|
|
@ -350,18 +352,29 @@ fn run() -> Result<()> {
|
|||
)?;
|
||||
}
|
||||
|
||||
let mut store = parser.take_wasm_store();
|
||||
|
||||
// Check that all of the queries are valid.
|
||||
test::check_queries_at_path(*language, ¤t_dir.join("queries"))?;
|
||||
|
||||
// Run the syntax highlighting tests.
|
||||
let test_highlight_dir = test_dir.join("highlight");
|
||||
if test_highlight_dir.is_dir() {
|
||||
test_highlight::test_highlights(&loader, &test_highlight_dir)?;
|
||||
let mut highlighter = Highlighter::new();
|
||||
if let Some(store) = store.take() {
|
||||
highlighter.parser().set_wasm_store(store).unwrap();
|
||||
}
|
||||
test_highlight::test_highlights(&loader, &mut highlighter, &test_highlight_dir)?;
|
||||
store = highlighter.parser().take_wasm_store();
|
||||
}
|
||||
|
||||
let test_tag_dir = test_dir.join("tags");
|
||||
if test_tag_dir.is_dir() {
|
||||
test_tags::test_tags(&loader, &test_tag_dir)?;
|
||||
let mut tags_context = TagsContext::new();
|
||||
if let Some(store) = store.take() {
|
||||
tags_context.parser().set_wasm_store(store).unwrap();
|
||||
}
|
||||
test_tags::test_tags(&loader, &mut tags_context, &test_tag_dir)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,9 +38,12 @@ impl std::fmt::Display for Failure {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn test_highlights(loader: &Loader, directory: &Path) -> Result<()> {
|
||||
pub fn test_highlights(
|
||||
loader: &Loader,
|
||||
highlighter: &mut Highlighter,
|
||||
directory: &Path,
|
||||
) -> Result<()> {
|
||||
let mut failed = false;
|
||||
let mut highlighter = Highlighter::new();
|
||||
|
||||
println!("syntax highlighting:");
|
||||
for highlight_test_file in fs::read_dir(directory)? {
|
||||
|
|
@ -55,7 +58,7 @@ pub fn test_highlights(loader: &Loader, directory: &Path) -> Result<()> {
|
|||
.ok_or_else(|| anyhow!("No highlighting config found for {:?}", test_file_path))?;
|
||||
match test_highlight(
|
||||
&loader,
|
||||
&mut highlighter,
|
||||
highlighter,
|
||||
highlight_config,
|
||||
fs::read(&test_file_path)?.as_slice(),
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -38,9 +38,8 @@ impl std::fmt::Display for Failure {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn test_tags(loader: &Loader, directory: &Path) -> Result<()> {
|
||||
pub fn test_tags(loader: &Loader, tags_context: &mut TagsContext, directory: &Path) -> Result<()> {
|
||||
let mut failed = false;
|
||||
let mut tags_context = TagsContext::new();
|
||||
|
||||
println!("tags:");
|
||||
for tag_test_file in fs::read_dir(directory)? {
|
||||
|
|
@ -54,7 +53,7 @@ pub fn test_tags(loader: &Loader, directory: &Path) -> Result<()> {
|
|||
.tags_config(language)?
|
||||
.ok_or_else(|| anyhow!("No tags config found for {:?}", test_file_path))?;
|
||||
match test_tag(
|
||||
&mut tags_context,
|
||||
tags_context,
|
||||
tags_config,
|
||||
fs::read(&test_file_path)?.as_slice(),
|
||||
) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue