test: add tests about workspace/symbol requests (#1966)

This commit is contained in:
Myriad-Dreamin 2025-08-02 21:45:42 +08:00 committed by GitHub
parent ab774377f7
commit e8e6df319a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 118 additions and 0 deletions

View file

@ -0,0 +1,7 @@
/// path: base.typ
#let y() = 1;
-----
#import "base.typ"
#let x = 1;

View file

@ -0,0 +1,5 @@
/// pattern: ana
#let analysis = 1;
#let banana = 1;
#let c = 1;

View file

@ -0,0 +1,4 @@
/// pattern: x
#let x = 1;
#let y = 1;

View file

@ -0,0 +1,2 @@
#let x = 1;

View file

@ -0,0 +1,15 @@
---
source: crates/tinymist-query/src/symbol.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/symbols/multiple_files.typ
---
[
{
"kind": 13,
"name": "x"
},
{
"kind": 12,
"name": "y"
}
]

View file

@ -0,0 +1,15 @@
---
source: crates/tinymist-query/src/symbol.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/symbols/pattern_contains.typ
---
[
{
"kind": 13,
"name": "analysis"
},
{
"kind": 13,
"name": "banana"
}
]

View file

@ -0,0 +1,11 @@
---
source: crates/tinymist-query/src/symbol.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/symbols/pattern_start.typ
---
[
{
"kind": 13,
"name": "x"
}
]

View file

@ -0,0 +1,11 @@
---
source: crates/tinymist-query/src/symbol.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/symbols/single_file.typ
---
[
{
"kind": 13,
"name": "x"
}
]

View file

@ -0,0 +1,11 @@
---
source: crates/tinymist-query/src/symbol.rs
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
input_file: crates/tinymist-query/src/fixtures/symbols/with_comment.typ
---
[
{
"kind": 13,
"name": "x"
}
]

View file

@ -0,0 +1,2 @@
// Comment
#let x = 1;

View file

@ -95,3 +95,38 @@ fn filter_document_symbols(
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::syntax::find_module_level_docs;
use crate::tests::*;
#[test]
fn test() {
snapshot_testing("symbols", &|ctx, path| {
let source = ctx.source_by_path(&path).unwrap();
let docs = find_module_level_docs(&source).unwrap_or_default();
let mut properties = get_test_properties(&docs);
// need to compile the doc to get the dependencies
properties.insert("compile", "true");
let _doc = compile_doc_for_test(ctx, &properties);
let request = SymbolRequest {
pattern: properties.get("pattern").copied().map(str::to_owned),
};
let mut result = request.request(ctx);
if let Some(result) = &mut result {
// Sort the symbols by name for consistent output
result.sort_by(|x, y| {
x.name
.cmp(&y.name)
.then_with(|| x.location.uri.cmp(&y.location.uri))
});
}
assert_snapshot!(JsonRepr::new_redacted(result, &REDACT_LOC));
});
}
}