mirror of
https://github.com/typst/typst
synced 2025-08-18 00:48:34 +08:00
Add autocomplete tests
This commit is contained in:
parent
ecb0be4db4
commit
7acb4e203d
@ -76,7 +76,7 @@ pub struct Completion {
|
||||
}
|
||||
|
||||
/// A kind of item that can be completed.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum CompletionKind {
|
||||
/// A syntactical structure.
|
||||
@ -1571,7 +1571,7 @@ mod tests {
|
||||
|
||||
use typst::layout::PagedDocument;
|
||||
|
||||
use super::{autocomplete, Completion};
|
||||
use super::{autocomplete, Completion, CompletionKind};
|
||||
use crate::tests::{FilePos, TestWorld, WorldLike};
|
||||
|
||||
/// Quote a string.
|
||||
@ -1737,6 +1737,33 @@ mod tests {
|
||||
|
||||
test_with_doc(&world, -1, doc.as_ref()).must_include(["test"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_autocomplete_ref_shorthand_with_partial_identifier() {
|
||||
let mut world = TestWorld::new("x<test>");
|
||||
let doc = typst::compile(&world).output.ok();
|
||||
|
||||
let end = world.main.text().len();
|
||||
world.main.edit(end..end, " @te");
|
||||
|
||||
test_with_doc(&world, -1, doc.as_ref()).must_include(["test"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_autocomplete_ref_identical_labels_returns_single_completion() {
|
||||
let mut world = TestWorld::new("x<test> y<test>");
|
||||
let doc = typst::compile(&world).output.ok();
|
||||
|
||||
let end = world.main.text().len();
|
||||
world.main.edit(end..end, " @");
|
||||
|
||||
let result = test_with_doc(&world, -1, doc.as_ref());
|
||||
let completions = result.completions();
|
||||
let label_count =
|
||||
completions.iter().filter(|c| c.kind == CompletionKind::Label).count();
|
||||
assert_eq!(label_count, 1);
|
||||
}
|
||||
|
||||
/// Test what kind of brackets we autocomplete for function calls depending
|
||||
/// on the function and existing parens.
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user