lsp_store.rs

 1use std::path::Path;
 2
 3use language::{CodeLabel, HighlightId};
 4
 5use project::lsp_store::*;
 6
 7#[test]
 8fn test_glob_literal_prefix() {
 9    assert_eq!(glob_literal_prefix(Path::new("**/*.js")), Path::new(""));
10    assert_eq!(
11        glob_literal_prefix(Path::new("node_modules/**/*.js")),
12        Path::new("node_modules")
13    );
14    assert_eq!(
15        glob_literal_prefix(Path::new("foo/{bar,baz}.js")),
16        Path::new("foo")
17    );
18    assert_eq!(
19        glob_literal_prefix(Path::new("foo/bar/baz.js")),
20        Path::new("foo/bar/baz.js")
21    );
22
23    #[cfg(target_os = "windows")]
24    {
25        assert_eq!(glob_literal_prefix(Path::new("**\\*.js")), Path::new(""));
26        assert_eq!(
27            glob_literal_prefix(Path::new("node_modules\\**/*.js")),
28            Path::new("node_modules")
29        );
30        assert_eq!(
31            glob_literal_prefix(Path::new("foo/{bar,baz}.js")),
32            Path::new("foo")
33        );
34        assert_eq!(
35            glob_literal_prefix(Path::new("foo\\bar\\baz.js")),
36            Path::new("foo/bar/baz.js")
37        );
38    }
39}
40
41#[test]
42fn test_multi_len_chars_normalization() {
43    let mut label = CodeLabel::new(
44        "myElˇ (parameter) myElˇ: {\n    foo: string;\n}".to_string(),
45        0..6,
46        vec![(0..6, HighlightId(1))],
47    );
48    ensure_uniform_list_compatible_label(&mut label);
49    assert_eq!(
50        label,
51        CodeLabel::new(
52            "myElˇ (parameter) myElˇ: { foo: string; }".to_string(),
53            0..6,
54            vec![(0..6, HighlightId(1))],
55        )
56    );
57}
58
59#[test]
60fn test_trailing_newline_in_completion_documentation() {
61    let doc =
62        lsp::Documentation::String("Inappropriate argument value (of correct type).\n".to_string());
63    let completion_doc: CompletionDocumentation = doc.into();
64    assert!(
65        matches!(completion_doc, CompletionDocumentation::SingleLine(s) if s == "Inappropriate argument value (of correct type).")
66    );
67
68    let doc = lsp::Documentation::String("  some value  \n".to_string());
69    let completion_doc: CompletionDocumentation = doc.into();
70    assert!(matches!(
71        completion_doc,
72        CompletionDocumentation::SingleLine(s) if s == "some value"
73    ));
74}