From d79a9b17dc4fb132443aa4ec1ca0ab278d2a217c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 14 Jan 2019 16:27:08 +0300 Subject: switch to insta for testing --- Cargo.lock | 78 +++++++++++++-- crates/ra_ide_api/Cargo.toml | 3 + crates/ra_ide_api/src/extend_selection.rs | 5 +- crates/ra_ide_api/src/runnables.rs | 97 ++++++++++++++++++ .../tests__highlight_query_group_macro.snap | 26 +++++ .../tests__highlights_code_inside_macros.snap | 70 +++++++++++++ .../ra_ide_api/src/snapshots/tests__runnables.snap | 22 +++++ .../src/snapshots/tests__runnables_module.snap | 18 ++++ .../tests__runnables_multiple_depth_module.snap | 18 ++++ .../tests__runnables_one_depth_layer_module.snap | 18 ++++ crates/ra_ide_api/src/syntax_highlighting.rs | 32 +----- crates/ra_ide_api/tests/test/main.rs | 20 +--- crates/ra_ide_api/tests/test/runnables.rs | 109 --------------------- .../test__unresolved_module_diagnostic.snap | 26 +++++ crates/ra_ide_api_light/Cargo.toml | 1 + crates/ra_ide_api_light/src/lib.rs | 13 +-- .../src/snapshots/tests__file_structure.snap | 80 +++++++++++++++ .../src/snapshots/tests__highlighting.snap | 30 ++++++ crates/ra_ide_api_light/src/structure.rs | 16 +-- crates/test_utils/src/lib.rs | 8 -- 20 files changed, 495 insertions(+), 195 deletions(-) create mode 100644 crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap create mode 100644 crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap create mode 100644 crates/ra_ide_api/src/snapshots/tests__runnables.snap create mode 100644 crates/ra_ide_api/src/snapshots/tests__runnables_module.snap create mode 100644 crates/ra_ide_api/src/snapshots/tests__runnables_multiple_depth_module.snap create mode 100644 crates/ra_ide_api/src/snapshots/tests__runnables_one_depth_layer_module.snap delete mode 100644 crates/ra_ide_api/tests/test/runnables.rs create mode 100644 crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap create mode 100644 crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap create mode 100644 crates/ra_ide_api_light/src/snapshots/tests__highlighting.snap diff --git a/Cargo.lock b/Cargo.lock index 504a5633f..2c4337a70 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,7 +118,7 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -155,6 +155,17 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clicolors-control" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -163,6 +174,23 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "console" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-channel" version = "0.3.6" @@ -259,6 +287,11 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "encode_unicode" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "error-chain" version = "0.12.0" @@ -340,7 +373,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lsp-types 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -393,6 +426,20 @@ name = "indexmap" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "insta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "console 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itertools" version = "0.8.0" @@ -448,7 +495,7 @@ dependencies = [ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -688,6 +735,7 @@ name = "ra_ide_api" version = "0.1.0" dependencies = [ "fst 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "insta 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -708,6 +756,7 @@ dependencies = [ name = "ra_ide_api_light" version = "0.1.0" dependencies = [ + "insta 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -742,7 +791,7 @@ dependencies = [ "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "test_utils 0.1.0", "thread_worker 0.1.0", @@ -1081,7 +1130,7 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1187,7 +1236,7 @@ dependencies = [ "pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", "slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "unic-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1214,13 +1263,21 @@ dependencies = [ "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "termios" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "test_utils" version = "0.1.0" dependencies = [ "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1494,7 +1551,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" +"checksum clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "73abfd4c73d003a674ce5d2933fca6ce6c42480ea84a5ffe0a2dc39ed56300f9" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum console 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ecc3753530b959618f617b0cd6494526008d98687f1af5d8f9fa83fa9cdbb594" "checksum crossbeam-channel 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "137bc235f622ffaa0428e3854e24acb53291fc0b3ff6fb2cb75a8be6fb02f06b" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" @@ -1507,6 +1566,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "69b26e475fd29098530e709294e94e661974c851aed42512793f120fed4e199f" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" "checksum ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f56c93cc076508c549d9bb747f79aa9b4eb098be7b8cad8830c3137ef52d1e00" +"checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" @@ -1523,6 +1583,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9c7f9bb8aee47fc16d535a705f7867a9fc83bb822e5e1043bb98e77ffeed3c" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" +"checksum insta 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "60e94ba6dd3521d953caeed96f6ba06f4cdc9e30e398b3ee7acdd680294f87dc" "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" "checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" "checksum join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc7a5290e8c2606ce2be49f456d50f69173cb96d1541e4f66e34ac8b331a98f" @@ -1586,7 +1647,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)" = "0e732ed5a5592c17d961555e3b552985baf98d50ce418b7b655f31f6ba7eb1b7" "checksum serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d6115a3ca25c224e409185325afc16a0d5aaaabc15c42b09587d6f1ba39a5b" -"checksum serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)" = "bdf540260cfee6da923831f4776ddc495ada940c30117977c70f1313a6130545" +"checksum serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "dfb1277d4d0563e4593e0b8b5d23d744d277b55d2bc0bf1c38d0d8a6589d38aa" "checksum sha-1 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "51b9d1f3b5de8a167ab06834a7c883bd197f2191e1dda1a22d9ccfeedbf9aded" "checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" "checksum smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b73ea3738b47563803ef814925e69be00799a8c07420be8b996f8e98fb2336db" @@ -1600,6 +1661,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" "checksum teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d89ad4617d1dec55331067fadaa041e813479e1779616f3d3ce9308bf46184e" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" +"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" "checksum text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "158bb1c22b638b1da3c95a8ad9f061ea40d4d39fd0301be3a520f92efeeb189e" "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml index d42a664b6..f7013c3c1 100644 --- a/crates/ra_ide_api/Cargo.toml +++ b/crates/ra_ide_api/Cargo.toml @@ -21,3 +21,6 @@ ra_text_edit = { path = "../ra_text_edit" } ra_db = { path = "../ra_db" } hir = { path = "../ra_hir", package = "ra_hir" } test_utils = { path = "../test_utils" } + +[dev-dependencies] +insta = "0.1.4" diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index c3c809c9f..9f0ab2f1c 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -38,8 +38,9 @@ fn find_macro_call(node: &SyntaxNode, range: TextRange) -> Option<&ast::MacroCal #[cfg(test)] mod tests { + use ra_syntax::TextRange; + use crate::mock_analysis::single_file_with_range; - use test_utils::assert_eq_dbg; #[test] fn extend_selection_inside_macros() { @@ -51,6 +52,6 @@ mod tests { ", ); let r = analysis.extend_selection(frange); - assert_eq_dbg("[51; 56)", &r); + assert_eq!(r, TextRange::from_to(51.into(), 56.into())); } } diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index 53e49da5b..f1de28094 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs @@ -92,3 +92,100 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Opt kind: RunnableKind::TestMod { path }, }) } + +#[cfg(test)] +mod tests { + use insta::assert_debug_snapshot_matches; + + use crate::mock_analysis::analysis_and_position; + + #[test] + fn test_runnables() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + fn main() {} + + #[test] + fn test_foo() {} + + #[test] + #[ignore] + fn test_foo() {} + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_debug_snapshot_matches!("runnables", &runnables) + } + + #[test] + fn test_runnables_module() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + mod test_mod { + #[test] + fn test_foo1() {} + } + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_debug_snapshot_matches!("runnables_module", &runnables) + } + + #[test] + fn test_runnables_one_depth_layer_module() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + mod foo { + mod test_mod { + #[test] + fn test_foo1() {} + } + } + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_debug_snapshot_matches!("runnables_one_depth_layer_module", &runnables) + } + + #[test] + fn test_runnables_multiple_depth_module() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + mod foo { + mod bar { + mod test_mod { + #[test] + fn test_foo1() {} + } + } + } + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_debug_snapshot_matches!("runnables_multiple_depth_module", &runnables) + } + + #[test] + fn test_runnables_no_test_function_in_module() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + mod test_mod { + fn foo1() {} + } + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert!(runnables.is_empty()) + } + +} diff --git a/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap b/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap new file mode 100644 index 000000000..b84aa9c78 --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap @@ -0,0 +1,26 @@ +Created: 2019-01-15T11:15:20.732493641+00:00 +Creator: insta@0.1.4 +Source: crates/ra_ide_api/src/syntax_highlighting.rs + +[ + HighlightedRange { + range: [20; 32), + tag: "macro" + }, + HighlightedRange { + range: [13; 18), + tag: "text" + }, + HighlightedRange { + range: [51; 54), + tag: "keyword" + }, + HighlightedRange { + range: [55; 60), + tag: "keyword" + }, + HighlightedRange { + range: [61; 72), + tag: "function" + } +] diff --git a/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap b/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap new file mode 100644 index 000000000..14c6e5a4e --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap @@ -0,0 +1,70 @@ +Created: 2019-01-15T11:15:20.732523231+00:00 +Creator: insta@0.1.4 +Source: crates/ra_ide_api/src/syntax_highlighting.rs + +[ + HighlightedRange { + range: [13; 15), + tag: "keyword" + }, + HighlightedRange { + range: [16; 20), + tag: "function" + }, + HighlightedRange { + range: [41; 46), + tag: "macro" + }, + HighlightedRange { + range: [49; 52), + tag: "keyword" + }, + HighlightedRange { + range: [57; 59), + tag: "literal" + }, + HighlightedRange { + range: [82; 86), + tag: "macro" + }, + HighlightedRange { + range: [89; 92), + tag: "keyword" + }, + HighlightedRange { + range: [97; 99), + tag: "literal" + }, + HighlightedRange { + range: [49; 52), + tag: "keyword" + }, + HighlightedRange { + range: [53; 54), + tag: "function" + }, + HighlightedRange { + range: [57; 59), + tag: "literal" + }, + HighlightedRange { + range: [61; 62), + tag: "text" + }, + HighlightedRange { + range: [89; 92), + tag: "keyword" + }, + HighlightedRange { + range: [93; 94), + tag: "function" + }, + HighlightedRange { + range: [97; 99), + tag: "literal" + }, + HighlightedRange { + range: [101; 102), + tag: "text" + } +] diff --git a/crates/ra_ide_api/src/snapshots/tests__runnables.snap b/crates/ra_ide_api/src/snapshots/tests__runnables.snap new file mode 100644 index 000000000..ba6cba0ab --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/tests__runnables.snap @@ -0,0 +1,22 @@ +Created: 2019-01-15T11:15:20.732460119+00:00 +Creator: insta@0.1.4 +Source: crates/ra_ide_api/src/runnables.rs + +[ + Runnable { + range: [1; 21), + kind: Bin + }, + Runnable { + range: [22; 46), + kind: Test { + name: "test_foo" + } + }, + Runnable { + range: [47; 81), + kind: Test { + name: "test_foo" + } + } +] diff --git a/crates/ra_ide_api/src/snapshots/tests__runnables_module.snap b/crates/ra_ide_api/src/snapshots/tests__runnables_module.snap new file mode 100644 index 000000000..b3f2d4d6e --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/tests__runnables_module.snap @@ -0,0 +1,18 @@ +Created: 2019-01-15T11:15:20.732460109+00:00 +Creator: insta@0.1.4 +Source: crates/ra_ide_api/src/runnables.rs + +[ + Runnable { + range: [1; 59), + kind: TestMod { + path: "test_mod" + } + }, + Runnable { + range: [28; 57), + kind: Test { + name: "test_foo1" + } + } +] diff --git a/crates/ra_ide_api/src/snapshots/tests__runnables_multiple_depth_module.snap b/crates/ra_ide_api/src/snapshots/tests__runnables_multiple_depth_module.snap new file mode 100644 index 000000000..6eba482e7 --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/tests__runnables_multiple_depth_module.snap @@ -0,0 +1,18 @@ +Created: 2019-01-15T11:15:20.732522773+00:00 +Creator: insta@0.1.4 +Source: crates/ra_ide_api/src/runnables.rs + +[ + Runnable { + range: [41; 115), + kind: TestMod { + path: "foo::bar::test_mod" + } + }, + Runnable { + range: [68; 105), + kind: Test { + name: "test_foo1" + } + } +] diff --git a/crates/ra_ide_api/src/snapshots/tests__runnables_one_depth_layer_module.snap b/crates/ra_ide_api/src/snapshots/tests__runnables_one_depth_layer_module.snap new file mode 100644 index 000000000..f40c762f3 --- /dev/null +++ b/crates/ra_ide_api/src/snapshots/tests__runnables_one_depth_layer_module.snap @@ -0,0 +1,18 @@ +Created: 2019-01-15T11:15:20.732480089+00:00 +Creator: insta@0.1.4 +Source: crates/ra_ide_api/src/runnables.rs + +[ + Runnable { + range: [23; 85), + kind: TestMod { + path: "foo::test_mod" + } + }, + Runnable { + range: [46; 79), + kind: Test { + name: "test_foo1" + } + } +] diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index cb19e9515..480b78dce 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -34,7 +34,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable //empty - fn main() {} - - #[test] - fn test_foo() {} - - #[test] - #[ignore] - fn test_foo() {} - "#, - ); - let runnables = analysis.runnables(pos.file_id).unwrap(); - assert_eq_dbg( - r#"[Runnable { range: [1; 21), kind: Bin }, - Runnable { range: [22; 46), kind: Test { name: "test_foo" } }, - Runnable { range: [47; 81), kind: Test { name: "test_foo" } }]"#, - &runnables, - ) -} - -#[test] -fn test_runnables_module() { - let (analysis, pos) = analysis_and_position( - r#" - //- /lib.rs - <|> //empty - mod test_mod { - #[test] - fn test_foo1() {} - } - "#, - ); - let runnables = analysis.runnables(pos.file_id).unwrap(); - assert_eq_dbg( - r#"[Runnable { range: [1; 59), kind: TestMod { path: "test_mod" } }, - Runnable { range: [28; 57), kind: Test { name: "test_foo1" } }]"#, - &runnables, - ) -} - -#[test] -fn test_runnables_one_depth_layer_module() { - let (analysis, pos) = analysis_and_position( - r#" - //- /lib.rs - <|> //empty - mod foo { - mod test_mod { - #[test] - fn test_foo1() {} - } - } - "#, - ); - let runnables = analysis.runnables(pos.file_id).unwrap(); - assert_eq_dbg( - r#"[Runnable { range: [23; 85), kind: TestMod { path: "foo::test_mod" } }, - Runnable { range: [46; 79), kind: Test { name: "test_foo1" } }]"#, - &runnables, - ) -} - -#[test] -fn test_runnables_multiple_depth_module() { - let (analysis, pos) = analysis_and_position( - r#" - //- /lib.rs - <|> //empty - mod foo { - mod bar { - mod test_mod { - #[test] - fn test_foo1() {} - } - } - } - "#, - ); - let runnables = analysis.runnables(pos.file_id).unwrap(); - assert_eq_dbg( - r#"[Runnable { range: [41; 115), kind: TestMod { path: "foo::bar::test_mod" } }, - Runnable { range: [68; 105), kind: Test { name: "test_foo1" } }]"#, - &runnables, - ) -} - -#[test] -fn test_runnables_no_test_function_in_module() { - let (analysis, pos) = analysis_and_position( - r#" - //- /lib.rs - <|> //empty - mod test_mod { - fn foo1() {} - } - "#, - ); - let runnables = analysis.runnables(pos.file_id).unwrap(); - assert_eq_dbg(r#"[]"#, &runnables) -} 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 new file mode 100644 index 000000000..1b41e2b00 --- /dev/null +++ b/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap @@ -0,0 +1,26 @@ +Created: 2019-01-15T11:15:20.891129945+00:00 +Creator: insta@0.1.4 +Source: crates/ra_ide_api/tests/test/main.rs + +[ + Diagnostic { + message: "unresolved module", + range: [4; 7), + 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 + } +] diff --git a/crates/ra_ide_api_light/Cargo.toml b/crates/ra_ide_api_light/Cargo.toml index 8c192fca6..16cf228e7 100644 --- a/crates/ra_ide_api_light/Cargo.toml +++ b/crates/ra_ide_api_light/Cargo.toml @@ -17,3 +17,4 @@ ra_text_edit = { path = "../ra_text_edit" } [dev-dependencies] test_utils = { path = "../test_utils" } proptest = "0.8.7" +insta = "0.1.4" diff --git a/crates/ra_ide_api_light/src/lib.rs b/crates/ra_ide_api_light/src/lib.rs index 72fba9402..9dd72701d 100644 --- a/crates/ra_ide_api_light/src/lib.rs +++ b/crates/ra_ide_api_light/src/lib.rs @@ -132,8 +132,9 @@ pub fn syntax_tree(file: &SourceFile) -> String { #[cfg(test)] mod tests { use ra_syntax::AstNode; + use insta::assert_debug_snapshot_matches; - use crate::test_utils::{add_cursor, assert_eq_dbg, assert_eq_text, extract_offset}; + use crate::test_utils::{add_cursor, assert_eq_text, extract_offset}; use super::*; @@ -147,15 +148,7 @@ fn main() {} "#, ); let hls = highlight(file.syntax()); - assert_eq_dbg( - r#"[HighlightedRange { range: [1; 11), tag: "comment" }, - HighlightedRange { range: [12; 14), tag: "keyword" }, - HighlightedRange { range: [15; 19), tag: "function" }, - HighlightedRange { range: [29; 37), tag: "macro" }, - HighlightedRange { range: [38; 50), tag: "string" }, - HighlightedRange { range: [52; 54), tag: "literal" }]"#, - &hls, - ); + assert_debug_snapshot_matches!("highlighting", hls); } #[test] diff --git a/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap b/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap new file mode 100644 index 000000000..10eb5c724 --- /dev/null +++ b/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap @@ -0,0 +1,80 @@ +Created: 2019-01-15T11:15:21.073862814+00:00 +Creator: insta@0.1.4 +Source: crates/ra_ide_api_light/src/structure.rs + +[ + StructureNode { + parent: None, + label: "Foo", + navigation_range: [8; 11), + node_range: [1; 26), + kind: STRUCT_DEF + }, + StructureNode { + parent: Some( + 0 + ), + label: "x", + navigation_range: [18; 19), + node_range: [18; 24), + kind: NAMED_FIELD_DEF + }, + StructureNode { + parent: None, + label: "m", + navigation_range: [32; 33), + node_range: [28; 53), + kind: MODULE + }, + StructureNode { + parent: Some( + 2 + ), + label: "bar", + navigation_range: [43; 46), + node_range: [40; 51), + kind: FN_DEF + }, + StructureNode { + parent: None, + label: "E", + navigation_range: [60; 61), + node_range: [55; 75), + kind: ENUM_DEF + }, + StructureNode { + parent: None, + label: "T", + navigation_range: [81; 82), + node_range: [76; 88), + kind: TYPE_DEF + }, + StructureNode { + parent: None, + label: "S", + navigation_range: [96; 97), + node_range: [89; 108), + kind: STATIC_DEF + }, + StructureNode { + parent: None, + label: "C", + navigation_range: [115; 116), + node_range: [109; 127), + kind: CONST_DEF + }, + StructureNode { + parent: None, + label: "impl E", + navigation_range: [134; 135), + node_range: [129; 138), + kind: IMPL_BLOCK + }, + StructureNode { + parent: None, + label: "impl fmt::Debug for E", + navigation_range: [160; 161), + node_range: [140; 164), + kind: IMPL_BLOCK + } +] diff --git a/crates/ra_ide_api_light/src/snapshots/tests__highlighting.snap b/crates/ra_ide_api_light/src/snapshots/tests__highlighting.snap new file mode 100644 index 000000000..d8f44a713 --- /dev/null +++ b/crates/ra_ide_api_light/src/snapshots/tests__highlighting.snap @@ -0,0 +1,30 @@ +Created: 2019-01-15T11:15:21.073858657+00:00 +Creator: insta@0.1.4 +Source: crates/ra_ide_api_light/src/lib.rs + +[ + HighlightedRange { + range: [1; 11), + tag: "comment" + }, + HighlightedRange { + range: [12; 14), + tag: "keyword" + }, + HighlightedRange { + range: [15; 19), + tag: "function" + }, + HighlightedRange { + range: [29; 37), + tag: "macro" + }, + HighlightedRange { + range: [38; 50), + tag: "string" + }, + HighlightedRange { + range: [52; 54), + tag: "literal" + } +] diff --git a/crates/ra_ide_api_light/src/structure.rs b/crates/ra_ide_api_light/src/structure.rs index 8bd57555f..3c6f39e16 100644 --- a/crates/ra_ide_api_light/src/structure.rs +++ b/crates/ra_ide_api_light/src/structure.rs @@ -87,7 +87,7 @@ fn structure_node(node: &SyntaxNode) -> Option { #[cfg(test)] mod tests { use super::*; - use test_utils::assert_eq_dbg; + use insta::assert_debug_snapshot_matches; #[test] fn test_file_structure() { @@ -112,18 +112,6 @@ impl fmt::Debug for E {} "#, ); let structure = file_structure(&file); - assert_eq_dbg( - r#"[StructureNode { parent: None, label: "Foo", navigation_range: [8; 11), node_range: [1; 26), kind: STRUCT_DEF }, - StructureNode { parent: Some(0), label: "x", navigation_range: [18; 19), node_range: [18; 24), kind: NAMED_FIELD_DEF }, - StructureNode { parent: None, label: "m", navigation_range: [32; 33), node_range: [28; 53), kind: MODULE }, - StructureNode { parent: Some(2), label: "bar", navigation_range: [43; 46), node_range: [40; 51), kind: FN_DEF }, - StructureNode { parent: None, label: "E", navigation_range: [60; 61), node_range: [55; 75), kind: ENUM_DEF }, - StructureNode { parent: None, label: "T", navigation_range: [81; 82), node_range: [76; 88), kind: TYPE_DEF }, - StructureNode { parent: None, label: "S", navigation_range: [96; 97), node_range: [89; 108), kind: STATIC_DEF }, - StructureNode { parent: None, label: "C", navigation_range: [115; 116), node_range: [109; 127), kind: CONST_DEF }, - StructureNode { parent: None, label: "impl E", navigation_range: [134; 135), node_range: [129; 138), kind: IMPL_BLOCK }, - StructureNode { parent: None, label: "impl fmt::Debug for E", navigation_range: [160; 161), node_range: [140; 164), kind: IMPL_BLOCK }]"#, - &structure, - ) + assert_debug_snapshot_matches!("file_structure", structure); } } diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 9b1c9c9a0..6489033dd 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -1,8 +1,6 @@ -use std::fmt; use std::fs; use std::path::{Path, PathBuf}; -use itertools::Itertools; use text_unit::{TextRange, TextUnit}; use serde_json::Value; @@ -31,12 +29,6 @@ macro_rules! assert_eq_text { }}; } -pub fn assert_eq_dbg(expected: &str, actual: &impl fmt::Debug) { - let actual = format!("{:?}", actual); - let expected = expected.lines().map(|l| l.trim()).join(" "); - assert_eq!(expected, actual); -} - pub fn extract_offset(text: &str) -> (TextUnit, String) { match try_extract_offset(text) { None => panic!("text should contain cursor marker"), -- cgit v1.2.3