mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 10:18:16 +00:00
test: base snapshot testing for document symbols
This commit is contained in:
parent
152b23ebac
commit
e7c5bf7c43
7 changed files with 188 additions and 62 deletions
|
@ -56,69 +56,14 @@ mod tests {
|
|||
use crate::tests::*;
|
||||
|
||||
#[test]
|
||||
fn test_get_document_symbols() {
|
||||
run_with_source(
|
||||
r#"
|
||||
= Heading 1
|
||||
#let a = 1;
|
||||
== Heading 2
|
||||
#let b = 1;
|
||||
= Heading 3
|
||||
#let c = 1;
|
||||
#let d = {
|
||||
#let e = 1;
|
||||
0
|
||||
}
|
||||
"#,
|
||||
|world, path| {
|
||||
let request = DocumentSymbolRequest { path: path.clone() };
|
||||
fn test() {
|
||||
snapshot_testing("document_symbols", &|world, path| {
|
||||
let request = DocumentSymbolRequest { path: path.clone() };
|
||||
|
||||
let source = get_suitable_source_in_workspace(world, &path).unwrap();
|
||||
let source = get_suitable_source_in_workspace(world, &path).unwrap();
|
||||
|
||||
let result = request.request(source, PositionEncoding::Utf16);
|
||||
assert_snapshot!(JsonRepr::new_redacted(result.unwrap(), &REDACT_LOC), @r###"
|
||||
[
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "a"
|
||||
},
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "b"
|
||||
}
|
||||
],
|
||||
"kind": 3,
|
||||
"name": "Heading 2"
|
||||
}
|
||||
],
|
||||
"kind": 3,
|
||||
"name": "Heading 1"
|
||||
},
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "c"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "d"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "e"
|
||||
}
|
||||
],
|
||||
"kind": 3,
|
||||
"name": "Heading 3"
|
||||
}
|
||||
]
|
||||
"###);
|
||||
},
|
||||
);
|
||||
let result = request.request(source, PositionEncoding::Utf16);
|
||||
assert_snapshot!(JsonRepr::new_redacted(result.unwrap(), &REDACT_LOC));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
10
crates/tinymist-query/src/fixtures/document_symbols/base.typ
Normal file
10
crates/tinymist-query/src/fixtures/document_symbols/base.typ
Normal file
|
@ -0,0 +1,10 @@
|
|||
= Heading 1
|
||||
#let a = 1;
|
||||
== Heading 2
|
||||
#let b = 1;
|
||||
= Heading 3
|
||||
#let c = 1;
|
||||
#let d = {
|
||||
let e = 1;
|
||||
0
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#let a = [
|
||||
== Heading 1
|
||||
#lorem(1)
|
||||
#let b = [
|
||||
// todo: there is a bug
|
||||
== Heading 2
|
||||
#lorem(1)
|
||||
]
|
||||
]
|
|
@ -0,0 +1,19 @@
|
|||
#let a = {
|
||||
let b = {
|
||||
let c = [
|
||||
|
||||
]
|
||||
}
|
||||
let b = {{
|
||||
|
||||
}}
|
||||
let b = {
|
||||
let c = {
|
||||
|
||||
} + {
|
||||
|
||||
}
|
||||
}
|
||||
let b = {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/document_symbol.rs
|
||||
expression: "JsonRepr::new_redacted(result.unwrap(), &REDACT_LOC)"
|
||||
input_file: crates/tinymist-query/src/fixtures/document_symbols/base.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "a",
|
||||
"range": "1:5:1:6",
|
||||
"selectionRange": "1:5:1:6"
|
||||
},
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "b",
|
||||
"range": "3:5:3:6",
|
||||
"selectionRange": "3:5:3:6"
|
||||
}
|
||||
],
|
||||
"kind": 3,
|
||||
"name": "Heading 2",
|
||||
"range": "2:3:2:12",
|
||||
"selectionRange": "2:3:2:12"
|
||||
}
|
||||
],
|
||||
"kind": 3,
|
||||
"name": "Heading 1",
|
||||
"range": "0:2:0:11",
|
||||
"selectionRange": "0:2:0:11"
|
||||
},
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "c",
|
||||
"range": "5:5:5:6",
|
||||
"selectionRange": "5:5:5:6"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "d",
|
||||
"range": "6:5:6:6",
|
||||
"selectionRange": "6:5:6:6"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "e",
|
||||
"range": "7:6:7:7",
|
||||
"selectionRange": "7:6:7:7"
|
||||
}
|
||||
],
|
||||
"kind": 3,
|
||||
"name": "Heading 3",
|
||||
"range": "4:2:4:11",
|
||||
"selectionRange": "4:2:4:11"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/document_symbol.rs
|
||||
expression: "JsonRepr::new_redacted(result.unwrap(), &REDACT_LOC)"
|
||||
input_file: crates/tinymist-query/src/fixtures/document_symbols/headings-in-blocks.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "a",
|
||||
"range": "0:5:0:6",
|
||||
"selectionRange": "0:5:0:6"
|
||||
},
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "b",
|
||||
"range": "3:7:3:8",
|
||||
"selectionRange": "3:7:3:8"
|
||||
}
|
||||
],
|
||||
"kind": 3,
|
||||
"name": "Heading 1",
|
||||
"range": "1:5:1:14",
|
||||
"selectionRange": "1:5:1:14"
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"name": "Heading 2",
|
||||
"range": "5:7:5:16",
|
||||
"selectionRange": "5:7:5:16"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,49 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/document_symbol.rs
|
||||
expression: "JsonRepr::new_redacted(result.unwrap(), &REDACT_LOC)"
|
||||
input_file: crates/tinymist-query/src/fixtures/document_symbols/nested-blocks.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "a",
|
||||
"range": "0:5:0:6",
|
||||
"selectionRange": "0:5:0:6"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "b",
|
||||
"range": "1:6:1:7",
|
||||
"selectionRange": "1:6:1:7"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "c",
|
||||
"range": "2:8:2:9",
|
||||
"selectionRange": "2:8:2:9"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "b",
|
||||
"range": "6:6:6:7",
|
||||
"selectionRange": "6:6:6:7"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "b",
|
||||
"range": "9:6:9:7",
|
||||
"selectionRange": "9:6:9:7"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "c",
|
||||
"range": "10:8:10:9",
|
||||
"selectionRange": "10:8:10:9"
|
||||
},
|
||||
{
|
||||
"kind": 13,
|
||||
"name": "b",
|
||||
"range": "16:6:16:7",
|
||||
"selectionRange": "16:6:16:7"
|
||||
}
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue