sort hash maps for tests

This commit is contained in:
Aleksey Kladov 2019-05-21 13:18:30 +03:00
parent 8b6f02d0d6
commit 0efb5364c3
6 changed files with 203 additions and 219 deletions

14
Cargo.lock generated
View file

@ -257,7 +257,7 @@ dependencies = [
"encode_unicode 0.3.5 (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.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.0 (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.6 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"termios 0.3.1 (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)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -551,7 +551,7 @@ dependencies = [
"console 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", "console 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.8.0 (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.6 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -1242,7 +1242,7 @@ dependencies = [
"ra_parser 0.1.0", "ra_parser 0.1.0",
"ra_text_edit 0.1.0", "ra_text_edit 0.1.0",
"rowan 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rowan 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"smol_str 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "smol_str 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"test_utils 0.1.0", "test_utils 0.1.0",
"text_unit 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "text_unit 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1262,7 +1262,7 @@ dependencies = [
name = "ra_tt" name = "ra_tt"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"smol_str 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "smol_str 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -1467,7 +1467,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"colosseum 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "colosseum 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smol_str 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "smol_str 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"text_unit 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "text_unit 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -1625,7 +1625,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "smol_str" name = "smol_str"
version = "0.1.10" version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2181,7 +2181,7 @@ dependencies = [
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" "checksum slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373"
"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be"
"checksum smol_str 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d077b3367211e9c6e2e012fb804c444e0d80ab5a51ae4137739b58e6446dcaef" "checksum smol_str 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e6507d018aa8dfcaa08aaab587605591cd2109df66a921486a2220e2daf9fa29"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
"checksum stacker 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb79482f57cf598af52094ec4cc3b3c42499d3ce5bd426f2ac41515b7e57404b" "checksum stacker 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb79482f57cf598af52094ec4cc3b3c42499d3ce5bd426f2ac41515b7e57404b"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"

View file

@ -5,7 +5,7 @@ use ra_syntax::{ast, SmolStr};
/// `Name` is a wrapper around string, which is used in hir for both references /// `Name` is a wrapper around string, which is used in hir for both references
/// and declarations. In theory, names should also carry hygiene info, but we are /// and declarations. In theory, names should also carry hygiene info, but we are
/// not there yet! /// not there yet!
#[derive(Clone, PartialEq, Eq, Hash)] #[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Name { pub struct Name {
text: SmolStr, text: SmolStr,
} }

View file

@ -8,7 +8,11 @@ use ra_db::SourceDatabase;
use test_utils::covers; use test_utils::covers;
use insta::assert_snapshot_matches; use insta::assert_snapshot_matches;
use crate::{Crate, mock::{MockDatabase, CrateGraphFixture}, nameres::Resolution}; use crate::{
Crate,
mock::{MockDatabase, CrateGraphFixture},
nameres::Resolution,
};
use super::*; use super::*;
@ -25,12 +29,15 @@ fn compute_crate_def_map(fixture: &str, graph: Option<CrateGraphFixture>) -> Arc
fn render_crate_def_map(map: &CrateDefMap) -> String { fn render_crate_def_map(map: &CrateDefMap) -> String {
let mut buf = String::new(); let mut buf = String::new();
go(&mut buf, map, "\ncrate", map.root); go(&mut buf, map, "\ncrate", map.root);
return buf; return buf.trim().to_string();
fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) { fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: CrateModuleId) {
*buf += path; *buf += path;
*buf += "\n"; *buf += "\n";
for (name, res) in map.modules[module].scope.items.iter() {
let mut entries = map.modules[module].scope.items.iter().collect::<Vec<_>>();
entries.sort_by_key(|(name, _)| *name);
for (name, res) in entries {
*buf += &format!("{}: {}\n", name, dump_resolution(res)) *buf += &format!("{}: {}\n", name, dump_resolution(res))
} }
for (name, child) in map.modules[module].children.iter() { for (name, child) in map.modules[module].children.iter() {
@ -79,21 +86,20 @@ fn crate_def_map_smoke_test() {
", ",
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
V: t v E: t
E: t S: t v
foo: t V: t v
S: t v foo: t
crate::foo crate::foo
bar: t bar: t
f: v f: v
crate::foo::bar crate::foo::bar
Baz: t v Baz: t v
E: t E: t
"### "###)
)
} }
#[test] #[test]
@ -113,12 +119,12 @@ fn bogus_paths() {
", ",
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
foo: t S: t v
S: t v foo: t
crate::foo crate::foo
"### "###
) )
} }
@ -137,13 +143,13 @@ fn use_as() {
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map,
@r###" @r###"
crate crate
Foo: t v Foo: t v
foo: t foo: t
crate::foo crate::foo
Baz: t v Baz: t v
"### "###
); );
} }
@ -164,21 +170,19 @@ fn use_trees() {
pub enum Quux {}; pub enum Quux {};
", ",
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate Baz: t v
Quux: t Quux: t
Baz: t v foo: t
foo: t
crate::foo
crate::foo bar: t
bar: t
crate::foo::bar
crate::foo::bar Baz: t v
Quux: t Quux: t
Baz: t v "###);
"###
);
} }
#[test] #[test]
@ -199,20 +203,18 @@ fn re_exports() {
pub struct Baz; pub struct Baz;
", ",
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate Baz: t v
Baz: t v foo: t
foo: t
crate::foo
crate::foo Baz: t v
bar: t bar: t
Baz: t v
crate::foo::bar
crate::foo::bar Baz: t v
Baz: t v "###);
"###
);
} }
#[test] #[test]
@ -237,10 +239,10 @@ fn std_prelude() {
}, },
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
Bar: t v Bar: t v
Baz: t v Baz: t v
"###); "###);
} }
#[test] #[test]
@ -254,10 +256,10 @@ fn can_import_enum_variant() {
", ",
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
V: t v E: t
E: t V: t v
"### "###
); );
} }
@ -285,20 +287,18 @@ fn edition_2015_imports() {
}, },
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate bar: t
bar: t foo: t
foo: t
crate::bar
crate::bar Bar: t v
Bar: t v
crate::foo
crate::foo Bar: t v
FromLib: t v FromLib: t v
Bar: t v "###);
"###
);
} }
#[test] #[test]
@ -317,16 +317,14 @@ fn module_resolution_works_for_non_standard_filenames() {
}, },
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate Bar: t v
Bar: t v foo: t
foo: t
crate::foo
crate::foo Bar: t v
Bar: t v "###);
"###
);
} }
#[test] #[test]
@ -348,12 +346,10 @@ fn name_res_works_for_broken_modules() {
pub struct Baz; pub struct Baz;
", ",
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate Baz: _
Baz: _ "###);
"###
);
} }
#[test] #[test]
@ -369,19 +365,17 @@ fn item_map_using_self() {
pub struct Baz; pub struct Baz;
", ",
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate Baz: t v
Baz: t v foo: t
foo: t
crate::foo
crate::foo bar: t
bar: t
crate::foo::bar
crate::foo::bar Baz: t v
Baz: t v "###);
"###
);
} }
#[test] #[test]
@ -400,12 +394,10 @@ fn item_map_across_crates() {
}, },
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate Baz: t v
Baz: t v "###);
"###
);
} }
#[test] #[test]
@ -430,12 +422,10 @@ fn extern_crate_rename() {
}, },
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate Arc: t v
Arc: t v "###);
"###
);
} }
#[test] #[test]
@ -462,9 +452,9 @@ fn extern_crate_rename_2015_edition() {
assert_snapshot_matches!(map, assert_snapshot_matches!(map,
@r###" @r###"
crate crate
Arc: t v Arc: t v
"### "###
); );
} }
@ -490,12 +480,10 @@ fn import_across_source_roots() {
}, },
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate C: t v
C: t v "###);
"###
);
} }
#[test] #[test]
@ -519,12 +507,10 @@ fn reexport_across_crates() {
}, },
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate Baz: t v
Baz: t v "###);
"###
);
} }
#[test] #[test]
@ -544,13 +530,11 @@ fn values_dont_shadow_extern_crates() {
}, },
); );
assert_snapshot_matches!(map, assert_snapshot_matches!(map, @r###"
@r###" crate
crate Bar: t v
Bar: t v foo: v
foo: v "###);
"###
);
} }
#[test] #[test]

View file

@ -18,20 +18,20 @@ fn glob_1() {
", ",
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
bar: t Baz: t v
Foo: t v Foo: t v
Baz: t v bar: t
foo: t foo: t
crate::foo crate::foo
bar: t Baz: t v
Foo: t v Foo: t v
Baz: t v bar: t
crate::foo::bar crate::foo::bar
Baz: t v Baz: t v
"### "###
); );
} }
@ -54,22 +54,22 @@ fn glob_2() {
", ",
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
bar: t Baz: t v
Foo: t v Foo: t v
Baz: t v bar: t
foo: t foo: t
crate::foo crate::foo
bar: t Baz: t v
Foo: t v Foo: t v
Baz: t v bar: t
crate::foo::bar crate::foo::bar
bar: t Baz: t v
Foo: t v Foo: t v
Baz: t v bar: t
"### "###
); );
} }
@ -90,9 +90,9 @@ fn glob_across_crates() {
}, },
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
Baz: t v Baz: t v
"### "###
); );
} }
@ -109,10 +109,10 @@ fn glob_enum() {
", ",
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
Foo: t Bar: t v
Bar: t v Baz: t v
Baz: t v Foo: t
"### "###
); );
} }

View file

@ -18,14 +18,14 @@ fn macro_rules_are_globally_visible() {
", ",
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
nested: t Foo: t v
Foo: t v nested: t
crate::nested crate::nested
Bar: t v Bar: t v
Baz: t v Baz: t v
"###); "###);
} }
#[test] #[test]
@ -45,15 +45,15 @@ fn macro_rules_can_define_modules() {
", ",
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
n1: t n1: t
crate::n1 crate::n1
n2: t n2: t
crate::n1::n2 crate::n1::n2
X: t v X: t v
"###); "###);
} }
#[test] #[test]
@ -81,14 +81,14 @@ fn macro_rules_from_other_crates_are_visible() {
}, },
); );
assert_snapshot_matches!(map, @r###" assert_snapshot_matches!(map, @r###"
crate crate
bar: t Bar: t v
Foo: t v Foo: t v
Bar: t v bar: t
crate::bar crate::bar
bar: t Bar: t v
Foo: t v Foo: t v
Bar: t v bar: t
"###); "###);
} }

View file

@ -18,7 +18,7 @@ rowan = "0.5.0"
# ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here # ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here
# to reduce number of compilations # to reduce number of compilations
text_unit = { version = "0.1.8", features = ["serde"] } text_unit = { version = "0.1.8", features = ["serde"] }
smol_str = { version = "0.1.9", features = ["serde"] } smol_str = { version = "0.1.11", features = ["serde"] }
ra_text_edit = { path = "../ra_text_edit" } ra_text_edit = { path = "../ra_text_edit" }
ra_parser = { path = "../ra_parser" } ra_parser = { path = "../ra_parser" }