From 309716cffe93d065bcad0344b0f332425576c1e5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 25 Mar 2019 14:28:04 +0300 Subject: move tests to where they belong --- crates/ra_ide_api/tests/test/main.rs | 16 ------------- .../test__unresolved_module_diagnostic.snap | 28 ---------------------- 2 files changed, 44 deletions(-) delete mode 100644 crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap (limited to 'crates/ra_ide_api/tests') diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs index 0f0766f62..d4ff21c09 100644 --- a/crates/ra_ide_api/tests/test/main.rs +++ b/crates/ra_ide_api/tests/test/main.rs @@ -1,4 +1,3 @@ -use insta::assert_debug_snapshot_matches; use ra_ide_api::{ mock_analysis::{single_file, single_file_with_position, single_file_with_range, MockAnalysis}, AnalysisChange, CrateGraph, Edition::Edition2018, Query, NavigationTarget, @@ -6,21 +5,6 @@ use ra_ide_api::{ }; use ra_syntax::SmolStr; -#[test] -fn test_unresolved_module_diagnostic() { - let (analysis, file_id) = single_file("mod foo;"); - let diagnostics = analysis.diagnostics(file_id).unwrap(); - assert_debug_snapshot_matches!("unresolved_module_diagnostic", &diagnostics); -} - -// FIXME: move this test to hir -#[test] -fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() { - let (analysis, file_id) = single_file("mod foo {}"); - let diagnostics = analysis.diagnostics(file_id).unwrap(); - assert!(diagnostics.is_empty()); -} - #[test] fn test_resolve_crate_root() { let mock = MockAnalysis::with_files( diff --git a/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap b/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap deleted file mode 100644 index 5bb953892..000000000 --- a/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap +++ /dev/null @@ -1,28 +0,0 @@ ---- -created: "2019-01-22T14:45:01.486985900+00:00" -creator: insta@0.4.0 -expression: "&diagnostics" -source: "crates\\ra_ide_api\\tests\\test\\main.rs" ---- -[ - Diagnostic { - message: "unresolved module", - range: [0; 8), - fix: Some( - SourceChange { - label: "create module", - source_file_edits: [], - file_system_edits: [ - CreateFile { - source_root: SourceRootId( - 0 - ), - path: "foo.rs" - } - ], - cursor_position: None - } - ), - severity: Error - } -] -- cgit v1.2.3 From e03189c1109573bec9600eb20efd9291d69f1d5c Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Mon, 25 Mar 2019 21:03:32 +0100 Subject: Move ra_ide_api unit tests --- crates/ra_ide_api/tests/test/main.rs | 376 ----------------------------------- 1 file changed, 376 deletions(-) delete mode 100644 crates/ra_ide_api/tests/test/main.rs (limited to 'crates/ra_ide_api/tests') diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs deleted file mode 100644 index d4ff21c09..000000000 --- a/crates/ra_ide_api/tests/test/main.rs +++ /dev/null @@ -1,376 +0,0 @@ -use ra_ide_api::{ - mock_analysis::{single_file, single_file_with_position, single_file_with_range, MockAnalysis}, - AnalysisChange, CrateGraph, Edition::Edition2018, Query, NavigationTarget, - ReferenceSearchResult, -}; -use ra_syntax::SmolStr; - -#[test] -fn test_resolve_crate_root() { - let mock = MockAnalysis::with_files( - " - //- /bar.rs - mod foo; - //- /foo.rs - // empty <|> - ", - ); - let root_file = mock.id_of("/bar.rs"); - let mod_file = mock.id_of("/foo.rs"); - let mut host = mock.analysis_host(); - assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); - - let mut crate_graph = CrateGraph::default(); - let crate_id = crate_graph.add_crate_root(root_file, Edition2018); - let mut change = AnalysisChange::new(); - change.set_crate_graph(crate_graph); - host.apply_change(change); - - assert_eq!(host.analysis().crate_for(mod_file).unwrap(), vec![crate_id]); -} - -fn get_all_refs(text: &str) -> ReferenceSearchResult { - let (analysis, position) = single_file_with_position(text); - analysis.find_all_refs(position).unwrap().unwrap() -} - -fn get_symbols_matching(text: &str, query: &str) -> Vec { - let (analysis, _) = single_file(text); - analysis.symbol_search(Query::new(query.into())).unwrap() -} - -#[test] -fn test_find_all_refs_for_local() { - let code = r#" - fn main() { - let mut i = 1; - let j = 1; - i = i<|> + j; - - { - i = 0; - } - - i = 5; - }"#; - - let refs = get_all_refs(code); - assert_eq!(refs.len(), 5); -} - -#[test] -fn test_find_all_refs_for_param_inside() { - let code = r#" - fn foo(i : u32) -> u32 { - i<|> - }"#; - - let refs = get_all_refs(code); - assert_eq!(refs.len(), 2); -} - -#[test] -fn test_find_all_refs_for_fn_param() { - let code = r#" - fn foo(i<|> : u32) -> u32 { - i - }"#; - - let refs = get_all_refs(code); - assert_eq!(refs.len(), 2); -} - -#[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_syntax_tree_without_range() { - // Basic syntax - let (analysis, file_id) = single_file(r#"fn foo() {}"#); - let syn = analysis.syntax_tree(file_id, None); - - assert_eq!( - syn.trim(), - r#" -SOURCE_FILE@[0; 11) - FN_DEF@[0; 11) - FN_KW@[0; 2) - WHITESPACE@[2; 3) - NAME@[3; 6) - IDENT@[3; 6) "foo" - PARAM_LIST@[6; 8) - L_PAREN@[6; 7) - R_PAREN@[7; 8) - WHITESPACE@[8; 9) - BLOCK@[9; 11) - L_CURLY@[9; 10) - R_CURLY@[10; 11) - "# - .trim() - ); - - let (analysis, file_id) = single_file( - r#" -fn test() { - assert!(" - fn foo() { - } - ", ""); -}"# - .trim(), - ); - let syn = analysis.syntax_tree(file_id, None); - - assert_eq!( - syn.trim(), - r#" -SOURCE_FILE@[0; 60) - FN_DEF@[0; 60) - FN_KW@[0; 2) - WHITESPACE@[2; 3) - NAME@[3; 7) - IDENT@[3; 7) "test" - PARAM_LIST@[7; 9) - L_PAREN@[7; 8) - R_PAREN@[8; 9) - WHITESPACE@[9; 10) - BLOCK@[10; 60) - L_CURLY@[10; 11) - WHITESPACE@[11; 16) - EXPR_STMT@[16; 58) - MACRO_CALL@[16; 57) - PATH@[16; 22) - PATH_SEGMENT@[16; 22) - NAME_REF@[16; 22) - IDENT@[16; 22) "assert" - EXCL@[22; 23) - TOKEN_TREE@[23; 57) - L_PAREN@[23; 24) - STRING@[24; 52) - COMMA@[52; 53) - WHITESPACE@[53; 54) - STRING@[54; 56) - R_PAREN@[56; 57) - SEMI@[57; 58) - WHITESPACE@[58; 59) - R_CURLY@[59; 60) - "# - .trim() - ); -} - -#[test] -fn test_syntax_tree_with_range() { - let (analysis, range) = single_file_with_range(r#"<|>fn foo() {}<|>"#.trim()); - let syn = analysis.syntax_tree(range.file_id, Some(range.range)); - - assert_eq!( - syn.trim(), - r#" -FN_DEF@[0; 11) - FN_KW@[0; 2) - WHITESPACE@[2; 3) - NAME@[3; 6) - IDENT@[3; 6) "foo" - PARAM_LIST@[6; 8) - L_PAREN@[6; 7) - R_PAREN@[7; 8) - WHITESPACE@[8; 9) - BLOCK@[9; 11) - L_CURLY@[9; 10) - R_CURLY@[10; 11) - "# - .trim() - ); - - let (analysis, range) = single_file_with_range( - r#"fn test() { - <|>assert!(" - fn foo() { - } - ", "");<|> -}"# - .trim(), - ); - let syn = analysis.syntax_tree(range.file_id, Some(range.range)); - - assert_eq!( - syn.trim(), - r#" -EXPR_STMT@[16; 58) - MACRO_CALL@[16; 57) - PATH@[16; 22) - PATH_SEGMENT@[16; 22) - NAME_REF@[16; 22) - IDENT@[16; 22) "assert" - EXCL@[22; 23) - TOKEN_TREE@[23; 57) - L_PAREN@[23; 24) - STRING@[24; 52) - COMMA@[52; 53) - WHITESPACE@[53; 54) - STRING@[54; 56) - R_PAREN@[56; 57) - SEMI@[57; 58) - "# - .trim() - ); -} - -#[test] -fn test_syntax_tree_inside_string() { - let (analysis, range) = single_file_with_range( - r#"fn test() { - assert!(" -<|>fn foo() { -}<|> -fn bar() { -} - ", ""); -}"# - .trim(), - ); - let syn = analysis.syntax_tree(range.file_id, Some(range.range)); - assert_eq!( - syn.trim(), - r#" -SOURCE_FILE@[0; 12) - FN_DEF@[0; 12) - FN_KW@[0; 2) - WHITESPACE@[2; 3) - NAME@[3; 6) - IDENT@[3; 6) "foo" - PARAM_LIST@[6; 8) - L_PAREN@[6; 7) - R_PAREN@[7; 8) - WHITESPACE@[8; 9) - BLOCK@[9; 12) - L_CURLY@[9; 10) - WHITESPACE@[10; 11) - R_CURLY@[11; 12) -"# - .trim() - ); - - // With a raw string - let (analysis, range) = single_file_with_range( - r###"fn test() { - assert!(r#" -<|>fn foo() { -}<|> -fn bar() { -} - "#, ""); -}"### - .trim(), - ); - let syn = analysis.syntax_tree(range.file_id, Some(range.range)); - assert_eq!( - syn.trim(), - r#" -SOURCE_FILE@[0; 12) - FN_DEF@[0; 12) - FN_KW@[0; 2) - WHITESPACE@[2; 3) - NAME@[3; 6) - IDENT@[3; 6) "foo" - PARAM_LIST@[6; 8) - L_PAREN@[6; 7) - R_PAREN@[7; 8) - WHITESPACE@[8; 9) - BLOCK@[9; 12) - L_CURLY@[9; 10) - WHITESPACE@[10; 11) - R_CURLY@[11; 12) -"# - .trim() - ); - - // With a raw string - let (analysis, range) = single_file_with_range( - r###"fn test() { - assert!(r<|>#" -fn foo() { -} -fn bar() { -}"<|>#, ""); -}"### - .trim(), - ); - let syn = analysis.syntax_tree(range.file_id, Some(range.range)); - assert_eq!( - syn.trim(), - r#" -SOURCE_FILE@[0; 25) - FN_DEF@[0; 12) - FN_KW@[0; 2) - WHITESPACE@[2; 3) - NAME@[3; 6) - IDENT@[3; 6) "foo" - PARAM_LIST@[6; 8) - L_PAREN@[6; 7) - R_PAREN@[7; 8) - WHITESPACE@[8; 9) - BLOCK@[9; 12) - L_CURLY@[9; 10) - WHITESPACE@[10; 11) - R_CURLY@[11; 12) - WHITESPACE@[12; 13) - FN_DEF@[13; 25) - FN_KW@[13; 15) - WHITESPACE@[15; 16) - NAME@[16; 19) - IDENT@[16; 19) "bar" - PARAM_LIST@[19; 21) - L_PAREN@[19; 20) - R_PAREN@[20; 21) - WHITESPACE@[21; 22) - BLOCK@[22; 25) - L_CURLY@[22; 23) - WHITESPACE@[23; 24) - R_CURLY@[24; 25) - -"# - .trim() - ); -} -- cgit v1.2.3