summaryrefslogtreecommitdiff
path: root/support/texlab/tests/integration/workspace_symbol.rs
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-05-23 03:00:39 +0000
committerNorbert Preining <norbert@preining.info>2021-05-23 03:00:39 +0000
commitf1261b349e875b842745b63258c3e338cb1fe3bf (patch)
treeb5d402b3e80818cde2c079a42249f3dcb9732247 /support/texlab/tests/integration/workspace_symbol.rs
parent58aa1ac09b1d9e4769d0a0661cf12e2b2db41b14 (diff)
CTAN sync 202105230300
Diffstat (limited to 'support/texlab/tests/integration/workspace_symbol.rs')
-rw-r--r--support/texlab/tests/integration/workspace_symbol.rs323
1 files changed, 107 insertions, 216 deletions
diff --git a/support/texlab/tests/integration/workspace_symbol.rs b/support/texlab/tests/integration/workspace_symbol.rs
index 5eb8e1ace7..54a0a8808d 100644
--- a/support/texlab/tests/integration/workspace_symbol.rs
+++ b/support/texlab/tests/integration/workspace_symbol.rs
@@ -1,228 +1,119 @@
-use indoc::indoc;
-use texlab::{
- protocol::{Location, Range, RangeExt, SymbolInformation, WorkspaceSymbolParams},
- test::{TestBed, TestBedBuilder, TestLspClient, PULL_CAPABILITIES},
-};
-
-pub fn verify_symbol_info(
- symbol: &SymbolInformation,
- test_bed: &TestBed,
- relative_path: &str,
- name: &str,
- start_line: u64,
- start_character: u64,
- end_line: u64,
- end_character: u64,
-) {
- assert_eq!(symbol.name, name);
- let range = Range::new_simple(start_line, start_character, end_line, end_character);
- assert_eq!(
- symbol.location,
- Location::new(test_bed.uri(relative_path).into(), range)
- );
-}
+use anyhow::Result;
+use insta::assert_json_snapshot;
+use lsp_types::{ClientCapabilities, SymbolInformation, Url};
+
+use crate::common::ServerTester;
+
+fn run(query: &str) -> Result<Vec<SymbolInformation>> {
+ let server = ServerTester::launch_new_instance()?;
+ server.initialize(ClientCapabilities::default(), None)?;
+ let uri = Url::parse("http://www.example.com/main.tex")?;
+ server.open_memory(
+ uri.clone(),
+ r#"
+ \documentclass{article}
+ \usepackage{caption}
+ \usepackage{amsmath}
+ \usepackage{amsthm}
+
+ \begin{document}
+
+ \section{Foo}\label{sec:foo}
+
+ \begin{equation}\label{eq:foo}
+ Foo
+ \end{equation}
+
+ \section{Bar}\label{sec:bar}
+
+ \begin{figure}
+ Bar
+ \caption{Bar}
+ \label{fig:bar}
+ \end{figure}
+
+ \section{Baz}\label{sec:baz}
+
+ \begin{enumerate}
+ \item\label{itm:foo} Foo
+ \item\label{itm:bar} Bar
+ \item\label{itm:baz} Baz
+ \end{enumerate}
+
+ \section{Qux}\label{sec:qux}
+
+ \newtheorem{lemma}{Lemma}
+
+ \begin{lemma}[Qux]\label{thm:qux}
+ Qux
+ \end{lemma}
+
+ \end{document}
+ "#,
+ "latex",
+ )?;
+ server.open_memory(
+ Url::parse("http://www.example.com/main.aux")?,
+ r#"
+ \relax
+ \@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Bar\relax }}{1}\protected@file@percent }
+ \providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}}
+ \newlabel{fig:bar}{{1}{1}}
+ \@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}\protected@file@percent }
+ \newlabel{sec:foo}{{1}{1}}
+ \newlabel{eq:foo}{{1}{1}}
+ \@writefile{toc}{\contentsline {section}{\numberline {2}Bar}{1}\protected@file@percent }
+ \newlabel{sec:bar}{{2}{1}}
+ \@writefile{toc}{\contentsline {section}{\numberline {3}Baz}{1}\protected@file@percent }
+ \newlabel{sec:baz}{{3}{1}}
+ \newlabel{itm:foo}{{1}{1}}
+ \newlabel{itm:bar}{{2}{1}}
+ \newlabel{itm:baz}{{3}{1}}
+ \@writefile{toc}{\contentsline {section}{\numberline {4}Qux}{1}\protected@file@percent }
+ \newlabel{sec:qux}{{4}{1}}
+ \newlabel{thm:qux}{{1}{1}}
+ "#,
+ "latex",
+ )?;
+ server.open_memory(
+ Url::parse("http://www.example.com/main.bib")?,
+ r#"
+ @article{foo,}
+
+ @string{bar = "bar"}
+ "#,
+ "bibtex",
+ )?;
-async fn run(query: &str) -> (TestBed, Vec<SymbolInformation>) {
- let mut test_bed = TestBedBuilder::new()
- .file(
- "foo.tex",
- indoc!(
- r#"
- \documentclass{article}
- \usepackage{caption}
- \usepackage{amsmath}
- \usepackage{amsthm}
- %
- \begin{document}
- %
- \section{Foo}\label{sec:foo}
- %
- \begin{equation}\label{eq:foo}
- Foo
- \end{equation}
- %
- \section{Bar}\label{sec:bar}
- %
- \begin{figure}
- Bar
- \caption{Bar}
- \label{fig:bar}
- \end{figure}
- %
- \section{Baz}\label{sec:baz}
- %
- \begin{enumerate}
- \item\label{itm:foo} Foo
- \item\label{itm:bar} Bar
- \item\label{itm:baz} Baz
- \end{enumerate}
- %
- \section{Qux}\label{sec:qux}
- %
- \newtheorem{lemma}{Lemma}
- %
- \begin{lemma}[Qux]\label{thm:qux}
- Qux
- \end{lemma}
- %
- \end{document}
- "#
- ),
- )
- .file(
- "foo.aux",
- indoc!(
- r#"
- \relax
- \@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Bar\relax }}{1}\protected@file@percent }
- \providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}}
- \newlabel{fig:bar}{{1}{1}}
- \@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}\protected@file@percent }
- \newlabel{sec:foo}{{1}{1}}
- \newlabel{eq:foo}{{1}{1}}
- \@writefile{toc}{\contentsline {section}{\numberline {2}Bar}{1}\protected@file@percent }
- \newlabel{sec:bar}{{2}{1}}
- \@writefile{toc}{\contentsline {section}{\numberline {3}Baz}{1}\protected@file@percent }
- \newlabel{sec:baz}{{3}{1}}
- \newlabel{itm:foo}{{1}{1}}
- \newlabel{itm:bar}{{2}{1}}
- \newlabel{itm:baz}{{3}{1}}
- \@writefile{toc}{\contentsline {section}{\numberline {4}Qux}{1}\protected@file@percent }
- \newlabel{sec:qux}{{4}{1}}
- \newlabel{thm:qux}{{1}{1}}
- "#
- ),
- )
- .file(
- "bar.bib",
- indoc!(
- r#"
- @article{foo,}
- %
- @string{bar = "bar"}
- "#
- ),
- )
- .build()
- .await;
- test_bed.spawn();
- test_bed.initialize(PULL_CAPABILITIES.clone()).await;
- test_bed.open("foo.tex").await;
- test_bed.open("foo.aux").await;
- test_bed.open("bar.bib").await;
-
- let params = WorkspaceSymbolParams {
- query: query.into(),
- ..WorkspaceSymbolParams::default()
- };
- let actual_symbols = test_bed.client.workspace_symbol(params).await.unwrap();
-
- test_bed.shutdown().await;
-
- (test_bed, actual_symbols)
+ server.find_workspace_symbols(query)
}
-#[tokio::test]
-async fn filter_type_section() {
- let (test_bed, actual_symbols) = run("section").await;
- assert_eq!(actual_symbols.len(), 4);
- verify_symbol_info(
- &actual_symbols[0],
- &test_bed,
- "foo.tex",
- "1 Foo",
- 7,
- 0,
- 13,
- 0,
- );
- verify_symbol_info(
- &actual_symbols[1],
- &test_bed,
- "foo.tex",
- "2 Bar",
- 13,
- 0,
- 21,
- 0,
- );
- verify_symbol_info(
- &actual_symbols[2],
- &test_bed,
- "foo.tex",
- "3 Baz",
- 21,
- 0,
- 29,
- 0,
- );
- verify_symbol_info(
- &actual_symbols[3],
- &test_bed,
- "foo.tex",
- "4 Qux",
- 29,
- 0,
- 37,
- 0,
- );
+#[test]
+fn test_filter_type_section() -> Result<()> {
+ assert_json_snapshot!(run("section")?);
+ Ok(())
}
-#[tokio::test]
-async fn filter_type_figure() {
- let (test_bed, actual_symbols) = run("figure").await;
- assert_eq!(actual_symbols.len(), 1);
- verify_symbol_info(
- &actual_symbols[0],
- &test_bed,
- "foo.tex",
- "Figure 1: Bar",
- 15,
- 0,
- 19,
- 12,
- );
+#[test]
+fn test_filter_type_figure() -> Result<()> {
+ assert_json_snapshot!(run("figure")?);
+ Ok(())
}
-#[tokio::test]
-async fn filter_type_item() {
- let (test_bed, actual_symbols) = run("item").await;
- assert_eq!(actual_symbols.len(), 3);
- verify_symbol_info(&actual_symbols[0], &test_bed, "foo.tex", "1", 24, 4, 25, 4);
- verify_symbol_info(&actual_symbols[1], &test_bed, "foo.tex", "2", 25, 4, 26, 4);
- verify_symbol_info(&actual_symbols[2], &test_bed, "foo.tex", "3", 26, 4, 27, 0);
+#[test]
+fn test_filter_type_item() -> Result<()> {
+ assert_json_snapshot!(run("item")?);
+ Ok(())
}
-#[tokio::test]
-async fn filter_type_math() {
- let (test_bed, actual_symbols) = run("math").await;
- assert_eq!(actual_symbols.len(), 2);
- verify_symbol_info(
- &actual_symbols[0],
- &test_bed,
- "foo.tex",
- "Equation (1)",
- 9,
- 0,
- 11,
- 14,
- );
- verify_symbol_info(
- &actual_symbols[1],
- &test_bed,
- "foo.tex",
- "Lemma 1 (Qux)",
- 33,
- 0,
- 35,
- 11,
- );
+#[test]
+fn test_filter_type_math() -> Result<()> {
+ assert_json_snapshot!(run("math")?);
+ Ok(())
}
-#[tokio::test]
-async fn filter_bibtex() {
- let (test_bed, actual_symbols) = run("bibtex").await;
- assert_eq!(actual_symbols.len(), 2);
- verify_symbol_info(&actual_symbols[0], &test_bed, "bar.bib", "foo", 0, 0, 0, 14);
- verify_symbol_info(&actual_symbols[1], &test_bed, "bar.bib", "bar", 2, 0, 2, 20);
+#[test]
+fn test_filter_bibtex() -> Result<()> {
+ assert_json_snapshot!(run("bibtex")?);
+ Ok(())
}