diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-05-29 16:32:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-29 14:32:20 +0000 |
| commit | 54604ccb6b96576c0495db48bd6a450dc69bc90b (patch) | |
| tree | 374f74f647019dccec4c89a280c902e7bf1fdd52 /crates/typst-ide/src/tooltip.rs | |
| parent | e6739ecc2f78f023b7b6b1729983af30f657e6dd (diff) | |
Fix `Default` impls for AST nodes (#4288)
Diffstat (limited to 'crates/typst-ide/src/tooltip.rs')
| -rw-r--r-- | crates/typst-ide/src/tooltip.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/crates/typst-ide/src/tooltip.rs b/crates/typst-ide/src/tooltip.rs index 3ecc4d8f..4864a266 100644 --- a/crates/typst-ide/src/tooltip.rs +++ b/crates/typst-ide/src/tooltip.rs @@ -38,7 +38,7 @@ pub fn tooltip( } /// A hover tooltip. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub enum Tooltip { /// A string of text. Text(EcoString), @@ -250,3 +250,39 @@ fn font_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option<Tooltip> { None } + +#[cfg(test)] +mod tests { + use typst::eval::Tracer; + use typst::syntax::Side; + + use super::{tooltip, Tooltip}; + use crate::tests::TestWorld; + + fn text(text: &str) -> Option<Tooltip> { + Some(Tooltip::Text(text.into())) + } + + fn code(code: &str) -> Option<Tooltip> { + Some(Tooltip::Code(code.into())) + } + + #[track_caller] + fn test(text: &str, cursor: usize, side: Side, expected: Option<Tooltip>) { + let world = TestWorld::new(text); + let doc = typst::compile(&world, &mut Tracer::new()).ok(); + assert_eq!(tooltip(&world, doc.as_ref(), &world.main, cursor, side), expected); + } + + #[test] + fn test_tooltip() { + test("#let x = 1 + 2", 5, Side::After, code("3")); + test("#let x = 1 + 2", 6, Side::Before, code("3")); + test("#let f(x) = x + y", 11, Side::Before, text("This closure captures `y`.")); + } + + #[test] + fn test_empty_contextual() { + test("#{context}", 10, Side::Before, code("context()")); + } +} |
