mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Move tests
This commit is contained in:
parent
2ca0e9e00e
commit
2c268b9a5f
2 changed files with 71 additions and 74 deletions
|
@ -418,3 +418,74 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) ->
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use expect::expect;
|
||||
|
||||
use crate::{mock_analysis::single_file, Query};
|
||||
|
||||
#[test]
|
||||
fn test_nav_for_symbol() {
|
||||
let (analysis, _) = single_file(
|
||||
r#"
|
||||
enum FooInner { }
|
||||
fn foo() { enum FooInner { } }
|
||||
"#,
|
||||
);
|
||||
|
||||
let navs = analysis.symbol_search(Query::new("FooInner".to_string())).unwrap();
|
||||
expect![[r#"
|
||||
[
|
||||
NavigationTarget {
|
||||
file_id: FileId(
|
||||
1,
|
||||
),
|
||||
full_range: 0..17,
|
||||
focus_range: Some(
|
||||
5..13,
|
||||
),
|
||||
name: "FooInner",
|
||||
kind: ENUM_DEF,
|
||||
container_name: None,
|
||||
description: Some(
|
||||
"enum FooInner",
|
||||
),
|
||||
docs: None,
|
||||
},
|
||||
NavigationTarget {
|
||||
file_id: FileId(
|
||||
1,
|
||||
),
|
||||
full_range: 29..46,
|
||||
focus_range: Some(
|
||||
34..42,
|
||||
),
|
||||
name: "FooInner",
|
||||
kind: ENUM_DEF,
|
||||
container_name: Some(
|
||||
"foo",
|
||||
),
|
||||
description: Some(
|
||||
"enum FooInner",
|
||||
),
|
||||
docs: None,
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
.assert_debug_eq(&navs);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_world_symbols_are_case_sensitive() {
|
||||
let (analysis, _) = single_file(
|
||||
r#"
|
||||
fn foo() {}
|
||||
struct Foo;
|
||||
"#,
|
||||
);
|
||||
|
||||
let navs = analysis.symbol_search(Query::new("foo".to_string())).unwrap();
|
||||
assert_eq!(navs.len(), 2)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -526,77 +526,3 @@ fn analysis_is_send() {
|
|||
fn is_send<T: Send>() {}
|
||||
is_send::<Analysis>();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{display::NavigationTarget, mock_analysis::single_file, Query};
|
||||
use ra_syntax::{
|
||||
SmolStr,
|
||||
SyntaxKind::{FN_DEF, STRUCT_DEF},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_world_symbols_with_no_container() {
|
||||
let code = r#"
|
||||
enum FooInner { }
|
||||
"#;
|
||||
|
||||
let mut symbols = get_symbols_matching(code, "FooInner");
|
||||
|
||||
let s = symbols.pop().unwrap();
|
||||
|
||||
assert_eq!(s.name, "FooInner");
|
||||
assert!(s.container_name.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_world_symbols_include_container_name() {
|
||||
let code = r#"
|
||||
fn foo() {
|
||||
enum FooInner { }
|
||||
}
|
||||
"#;
|
||||
|
||||
let mut symbols = get_symbols_matching(code, "FooInner");
|
||||
|
||||
let s = symbols.pop().unwrap();
|
||||
|
||||
assert_eq!(s.name, "FooInner");
|
||||
assert_eq!(s.container_name, Some(SmolStr::new("foo")));
|
||||
|
||||
let code = r#"
|
||||
mod foo {
|
||||
struct FooInner;
|
||||
}
|
||||
"#;
|
||||
|
||||
let mut symbols = get_symbols_matching(code, "FooInner");
|
||||
|
||||
let s = symbols.pop().unwrap();
|
||||
|
||||
assert_eq!(s.name, "FooInner");
|
||||
assert_eq!(s.container_name, Some(SmolStr::new("foo")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_world_symbols_are_case_sensitive() {
|
||||
let code = r#"
|
||||
fn foo() {}
|
||||
|
||||
struct Foo;
|
||||
"#;
|
||||
|
||||
let symbols = get_symbols_matching(code, "Foo");
|
||||
|
||||
let fn_match = symbols.iter().find(|s| s.name == "foo").map(|s| s.kind);
|
||||
let struct_match = symbols.iter().find(|s| s.name == "Foo").map(|s| s.kind);
|
||||
|
||||
assert_eq!(fn_match, Some(FN_DEF));
|
||||
assert_eq!(struct_match, Some(STRUCT_DEF));
|
||||
}
|
||||
|
||||
fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> {
|
||||
let (analysis, _) = single_file(text);
|
||||
analysis.symbol_search(Query::new(query.into())).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue