switch to insta for testing

This commit is contained in:
Aleksey Kladov 2019-01-14 16:27:08 +03:00
parent 8caff4e034
commit d79a9b17dc
20 changed files with 495 additions and 195 deletions

78
Cargo.lock generated
View File

@ -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"

View File

@ -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"

View File

@ -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()));
}
}

View File

@ -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())
}
}

View File

@ -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"
}
]

View File

@ -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"
}
]

View File

@ -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"
}
}
]

View File

@ -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"
}
}
]

View File

@ -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"
}
}
]

View File

@ -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"
}
}
]

View File

@ -34,7 +34,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<Hi
#[cfg(test)]
mod tests {
use crate::mock_analysis::single_file;
use test_utils::assert_eq_dbg;
use insta::assert_debug_snapshot_matches;
#[test]
fn highlights_code_inside_macros() {
@ -47,25 +48,7 @@ mod tests {
",
);
let highlights = analysis.highlight(file_id).unwrap();
assert_eq_dbg(
r#"[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" }]"#,
&highlights,
)
assert_debug_snapshot_matches!("highlights_code_inside_macros", &highlights);
}
// FIXME: this test is not really necessary: artifact of the inital hacky
@ -80,13 +63,6 @@ mod tests {
",
);
let highlights = analysis.highlight(file_id).unwrap();
assert_eq_dbg(
r#"[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" }]"#,
&highlights,
)
assert_debug_snapshot_matches!("highlight_query_group_macro", &highlights);
}
}

View File

@ -1,7 +1,6 @@
mod runnables;
use ra_syntax::TextRange;
use test_utils::{assert_eq_dbg, assert_eq_text};
use test_utils::assert_eq_text;
use insta::assert_debug_snapshot_matches;
use ra_ide_api::{
mock_analysis::{single_file, single_file_with_position, MockAnalysis},
@ -12,18 +11,7 @@ use ra_ide_api::{
fn test_unresolved_module_diagnostic() {
let (analysis, file_id) = single_file("mod foo;");
let diagnostics = analysis.diagnostics(file_id).unwrap();
assert_eq_dbg(
r#"[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 }]"#,
&diagnostics,
);
assert_debug_snapshot_matches!("unresolved_module_diagnostic", &diagnostics);
}
// FIXME: move this test to hir
@ -31,7 +19,7 @@ fn test_unresolved_module_diagnostic() {
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_eq_dbg(r#"[]"#, &diagnostics);
assert!(diagnostics.is_empty());
}
#[test]

View File

@ -1,109 +0,0 @@
use test_utils::assert_eq_dbg;
use ra_ide_api::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_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)
}

View File

@ -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
}
]

View File

@ -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"

View File

@ -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]

View File

@ -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
}
]

View File

@ -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"
}
]

View File

@ -87,7 +87,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
#[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);
}
}

View File

@ -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"),