aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-23 17:20:32 +0100
committerAleksey Kladov <[email protected]>2020-06-23 17:37:26 +0100
commit30748161f0b4699ba9bc699a38ac9fc2fae49461 (patch)
treeeaa4c2ab2076ce6bb2b641edaaa971787aec1d69 /crates/test_utils
parent6996ec860bde7e6186ba8609b68ef51b8713e2ea (diff)
Simplify
Diffstat (limited to 'crates/test_utils')
-rw-r--r--crates/test_utils/src/fixture.rs62
-rw-r--r--crates/test_utils/src/lib.rs2
2 files changed, 4 insertions, 60 deletions
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index 0dbeb01b1..a07d057e1 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -4,16 +4,11 @@ use stdx::split1;
4 4
5#[derive(Debug, Eq, PartialEq)] 5#[derive(Debug, Eq, PartialEq)]
6pub struct FixtureEntry { 6pub struct FixtureEntry {
7 pub meta: FixtureMeta, 7 pub meta: FileMeta,
8 pub text: String, 8 pub text: String,
9} 9}
10 10
11#[derive(Debug, Eq, PartialEq)] 11#[derive(Debug, Eq, PartialEq)]
12pub enum FixtureMeta {
13 File(FileMeta),
14}
15
16#[derive(Debug, Eq, PartialEq)]
17pub struct FileMeta { 12pub struct FileMeta {
18 pub path: String, 13 pub path: String,
19 pub crate_name: Option<String>, 14 pub crate_name: Option<String>,
@@ -23,57 +18,6 @@ pub struct FileMeta {
23 pub env: FxHashMap<String, String>, 18 pub env: FxHashMap<String, String>,
24} 19}
25 20
26impl FixtureMeta {
27 pub fn path(&self) -> &str {
28 match self {
29 FixtureMeta::File(f) => &f.path,
30 }
31 }
32
33 pub fn crate_name(&self) -> Option<&String> {
34 match self {
35 FixtureMeta::File(f) => f.crate_name.as_ref(),
36 }
37 }
38
39 pub fn cfg_options(&self) -> Option<&CfgOptions> {
40 match self {
41 FixtureMeta::File(f) => Some(&f.cfg),
42 }
43 }
44
45 pub fn edition(&self) -> Option<&String> {
46 match self {
47 FixtureMeta::File(f) => f.edition.as_ref(),
48 }
49 }
50
51 pub fn env(&self) -> impl Iterator<Item = (&String, &String)> {
52 struct EnvIter<'a> {
53 iter: Option<std::collections::hash_map::Iter<'a, String, String>>,
54 }
55
56 impl<'a> EnvIter<'a> {
57 fn new(meta: &'a FixtureMeta) -> Self {
58 Self {
59 iter: match meta {
60 FixtureMeta::File(f) => Some(f.env.iter()),
61 },
62 }
63 }
64 }
65
66 impl<'a> Iterator for EnvIter<'a> {
67 type Item = (&'a String, &'a String);
68 fn next(&mut self) -> Option<Self::Item> {
69 self.iter.as_mut().and_then(|i| i.next())
70 }
71 }
72
73 EnvIter::new(self)
74 }
75}
76
77/// Same as `parse_fixture`, except it allow empty fixture 21/// Same as `parse_fixture`, except it allow empty fixture
78pub fn parse_single_fixture(ra_fixture: &str) -> Option<FixtureEntry> { 22pub fn parse_single_fixture(ra_fixture: &str) -> Option<FixtureEntry> {
79 if !ra_fixture.lines().any(|it| it.trim_start().starts_with("//-")) { 23 if !ra_fixture.lines().any(|it| it.trim_start().starts_with("//-")) {
@@ -137,7 +81,7 @@ The offending line: {:?}"#,
137} 81}
138 82
139//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo 83//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo
140fn parse_meta(meta: &str) -> FixtureMeta { 84fn parse_meta(meta: &str) -> FileMeta {
141 let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); 85 let components = meta.split_ascii_whitespace().collect::<Vec<_>>();
142 86
143 let path = components[0].to_string(); 87 let path = components[0].to_string();
@@ -173,7 +117,7 @@ fn parse_meta(meta: &str) -> FixtureMeta {
173 } 117 }
174 } 118 }
175 119
176 FixtureMeta::File(FileMeta { path, crate_name: krate, deps, edition, cfg, env }) 120 FileMeta { path, crate_name: krate, deps, edition, cfg, env }
177} 121}
178 122
179/// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines. 123/// Adjusts the indentation of the first line to the minimum indentation of the rest of the lines.
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index f22fcc8b2..f99786606 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -22,7 +22,7 @@ pub use difference::Changeset as __Changeset;
22pub use ra_cfg::CfgOptions; 22pub use ra_cfg::CfgOptions;
23pub use rustc_hash::FxHashMap; 23pub use rustc_hash::FxHashMap;
24 24
25pub use crate::fixture::{parse_fixture, parse_single_fixture, FixtureEntry, FixtureMeta}; 25pub use crate::fixture::{parse_fixture, parse_single_fixture, FileMeta, FixtureEntry};
26 26
27pub const CURSOR_MARKER: &str = "<|>"; 27pub const CURSOR_MARKER: &str = "<|>";
28 28