Skip to content

Commit

Permalink
Add integration tests for hover request
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed May 25, 2019
1 parent 6b3c581 commit 8dd93b4
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 1 deletion.
5 changes: 5 additions & 0 deletions scenarios/hover/bibtex/entry_type/foo.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@article{foo,}

@bar{bar,}

@baz{baz,}
4 changes: 4 additions & 0 deletions scenarios/hover/bibtex/field/foo.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@article{foo,
author = {Foo Bar},
bar = {Baz Qux},
}
3 changes: 3 additions & 0 deletions scenarios/hover/latex/citation/foo.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@article{foo, }

@article{bar, }
3 changes: 3 additions & 0 deletions scenarios/hover/latex/citation/foo.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\bibliography{foo}

\cite{foo}
4 changes: 4 additions & 0 deletions scenarios/hover/latex/component/foo.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\documentclass{article}

\usepackage{amsmath}
\usepackage{foo}
3 changes: 2 additions & 1 deletion src/hover/latex_component.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::data::component::ComponentDocumentation;
use crate::feature::FeatureRequest;
use crate::syntax::latex::LatexIncludeKind;
use crate::syntax::text::SyntaxNode;
use crate::syntax::SyntaxTree;
use lsp_types::{Hover, HoverContents, TextDocumentPositionParams};

Expand All @@ -16,7 +17,7 @@ impl LatexComponentHoverProvider {
include.kind == LatexIncludeKind::Package
|| include.kind == LatexIncludeKind::Class
})
.find(|include| include.command.range.contains(request.params.position))
.find(|include| include.path().range().contains(request.params.position))
.map(|include| include.path().text())
.map(|name| ComponentDocumentation::lookup(name))?)?;

Expand Down
109 changes: 109 additions & 0 deletions tests/hover.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#![feature(await_macro, async_await)]

mod common;

use crate::common::Scenario;
use futures::executor::block_on;
use lsp_types::*;
use std::borrow::Cow;
use texlab::data::bibtex_entry_type;
use texlab::data::bibtex_field;

pub async fn run(
scenario: &'static str,
file: &'static str,
position: Position,
) -> Option<HoverContents> {
let scenario = format!("hover/{}", scenario);
let scenario = await!(Scenario::new(&scenario));
await!(scenario.open(file));
let identifier = TextDocumentIdentifier::new(scenario.uri(file));
let params = TextDocumentPositionParams::new(identifier, position);
await!(scenario.server.hover(params))
.unwrap()
.map(|hover| hover.contents)
}

#[test]
fn test_entry_type_known() {
block_on(async move {
let contents = await!(run("bibtex/entry_type", "foo.bib", Position::new(0, 5))).unwrap();
assert_eq!(
contents,
HoverContents::Markup(MarkupContent {
kind: MarkupKind::Markdown,
value: Cow::from(bibtex_entry_type::get_documentation("article").unwrap())
})
);
});
}

#[test]
fn test_entry_type_unknown() {
block_on(async move {
let contents = await!(run("bibtex/entry_type", "foo.bib", Position::new(2, 2)));
assert_eq!(contents, None);
});
}

#[test]
fn test_field_known() {
block_on(async move {
let contents = await!(run("bibtex/field", "foo.bib", Position::new(1, 4))).unwrap();
assert_eq!(
contents,
HoverContents::Markup(MarkupContent {
kind: MarkupKind::Markdown,
value: Cow::from(bibtex_field::get_documentation("author").unwrap())
})
)
});
}

#[test]
fn test_field_unknown() {
block_on(async move {
let contents = await!(run("bibtex/field", "foo.bib", Position::new(2, 5)));
assert_eq!(contents, None);
});
}

#[test]
fn test_citation_bibtex() {
block_on(async move {
let contents = await!(run("latex/citation", "foo.bib", Position::new(0, 10)));
assert_eq!(contents.is_some(), true);
});
}

#[test]
fn test_citation_latex() {
block_on(async move {
let contents = await!(run("latex/citation", "foo.tex", Position::new(2, 8)));
assert_eq!(contents.is_some(), true);
});
}

#[test]
fn test_component_class() {
block_on(async move {
let contents = await!(run("latex/component", "foo.tex", Position::new(0, 19)));
assert_eq!(contents.is_some(), true);
});
}

#[test]
fn test_component_package() {
block_on(async move {
let contents = await!(run("latex/component", "foo.tex", Position::new(2, 16)));
assert_eq!(contents.is_some(), true);
});
}

#[test]
fn test_component_package_unknown() {
block_on(async move {
let contents = await!(run("latex/component", "foo.tex", Position::new(3, 14)));
assert_eq!(contents, None);
});
}

0 comments on commit 8dd93b4

Please sign in to comment.