diff options
Diffstat (limited to 'support/texlab/crates/links/src/tests.rs')
-rw-r--r-- | support/texlab/crates/links/src/tests.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/support/texlab/crates/links/src/tests.rs b/support/texlab/crates/links/src/tests.rs new file mode 100644 index 0000000000..d083b33be6 --- /dev/null +++ b/support/texlab/crates/links/src/tests.rs @@ -0,0 +1,57 @@ +use expect_test::{expect, Expect}; + +fn check(input: &str, expect: Expect) { + let fixture = test_utils::fixture::Fixture::parse(input); + let (params, _) = fixture.make_params().unwrap(); + let links = crate::find_links(params); + + let actual_ranges = links.iter().map(|link| link.range).collect::<Vec<_>>(); + + let expected_ranges = fixture + .locations() + .map(|location| location.range) + .collect::<Vec<_>>(); + + assert_eq!(actual_ranges, expected_ranges); + + let actual_targets = links + .iter() + .map(|link| link.document.uri.as_str()) + .collect::<Vec<_>>(); + + expect.assert_debug_eq(&actual_targets); +} + +#[test] +fn test_document_include() { + check( + r#" +%! foo.tex +\input{bar.tex} + ^^^^^^^ + +%! bar.tex"#, + expect![[r#" + [ + "file:///texlab/bar.tex", + ] + "#]], + ); +} + +#[test] +fn test_document_import() { + check( + r#" +%! foo.tex +\import{.}{bar/baz} + ^^^^^^^ + +%! bar/baz.tex"#, + expect![[r#" + [ + "file:///texlab/bar/baz.tex", + ] + "#]], + ); +} |