mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Simplify
This commit is contained in:
parent
c544f9a137
commit
08e2149eab
@ -132,10 +132,17 @@ fn with_files(
|
||||
|
||||
let mut file_position = None;
|
||||
|
||||
for entry in fixture.iter() {
|
||||
let meta = match ParsedMeta::from(entry) {
|
||||
ParsedMeta::File(it) => it,
|
||||
for entry in fixture {
|
||||
let text = if entry.text.contains(CURSOR_MARKER) {
|
||||
let (range_or_offset, text) = extract_range_or_offset(&entry.text);
|
||||
assert!(file_position.is_none());
|
||||
file_position = Some((file_id, range_or_offset));
|
||||
text.to_string()
|
||||
} else {
|
||||
entry.text.clone()
|
||||
};
|
||||
|
||||
let meta = FileMeta::from(entry);
|
||||
assert!(meta.path.starts_with(&source_root_prefix));
|
||||
|
||||
if let Some(krate) = meta.krate {
|
||||
@ -157,15 +164,6 @@ fn with_files(
|
||||
default_crate_root = Some(file_id);
|
||||
}
|
||||
|
||||
let text = if entry.text.contains(CURSOR_MARKER) {
|
||||
let (range_or_offset, text) = extract_range_or_offset(&entry.text);
|
||||
assert!(file_position.is_none());
|
||||
file_position = Some((file_id, range_or_offset));
|
||||
text.to_string()
|
||||
} else {
|
||||
entry.text.to_string()
|
||||
};
|
||||
|
||||
db.set_file_text(file_id, Arc::new(text));
|
||||
db.set_file_source_root(file_id, source_root_id);
|
||||
let path = VfsPath::new_virtual_path(meta.path);
|
||||
@ -198,10 +196,6 @@ fn with_files(
|
||||
(file_position, files)
|
||||
}
|
||||
|
||||
enum ParsedMeta {
|
||||
File(FileMeta),
|
||||
}
|
||||
|
||||
struct FileMeta {
|
||||
path: String,
|
||||
krate: Option<String>,
|
||||
@ -211,22 +205,22 @@ struct FileMeta {
|
||||
env: Env,
|
||||
}
|
||||
|
||||
impl From<&Fixture> for ParsedMeta {
|
||||
fn from(f: &Fixture) -> Self {
|
||||
impl From<Fixture> for FileMeta {
|
||||
fn from(f: Fixture) -> FileMeta {
|
||||
let mut cfg = CfgOptions::default();
|
||||
f.cfg_atoms.iter().for_each(|it| cfg.insert_atom(it.into()));
|
||||
f.cfg_key_values.iter().for_each(|(k, v)| cfg.insert_key_value(k.into(), v.into()));
|
||||
|
||||
Self::File(FileMeta {
|
||||
path: f.path.to_owned(),
|
||||
krate: f.crate_name.to_owned(),
|
||||
deps: f.deps.to_owned(),
|
||||
FileMeta {
|
||||
path: f.path,
|
||||
krate: f.krate,
|
||||
deps: f.deps,
|
||||
cfg,
|
||||
edition: f
|
||||
.edition
|
||||
.as_ref()
|
||||
.map_or(Edition::Edition2018, |v| Edition::from_str(&v).unwrap()),
|
||||
env: Env::from(f.env.iter()),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use stdx::{lines_with_ends, split_delim, trim_indent};
|
||||
pub struct Fixture {
|
||||
pub path: String,
|
||||
pub text: String,
|
||||
pub crate_name: Option<String>,
|
||||
pub krate: Option<String>,
|
||||
pub deps: Vec<String>,
|
||||
pub cfg_atoms: Vec<String>,
|
||||
pub cfg_key_values: Vec<(String, String)>,
|
||||
@ -56,7 +56,7 @@ impl Fixture {
|
||||
}
|
||||
|
||||
//- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo
|
||||
pub fn parse_meta_line(meta: &str) -> Fixture {
|
||||
fn parse_meta_line(meta: &str) -> Fixture {
|
||||
assert!(meta.starts_with("//-"));
|
||||
let meta = meta["//-".len()..].trim();
|
||||
let components = meta.split_ascii_whitespace().collect::<Vec<_>>();
|
||||
@ -98,7 +98,7 @@ impl Fixture {
|
||||
Fixture {
|
||||
path,
|
||||
text: String::new(),
|
||||
crate_name: krate,
|
||||
krate: krate,
|
||||
deps,
|
||||
cfg_atoms,
|
||||
cfg_key_values,
|
||||
@ -136,7 +136,7 @@ fn parse_fixture_gets_full_meta() {
|
||||
let meta = &parsed[0];
|
||||
assert_eq!("mod m;\n", meta.text);
|
||||
|
||||
assert_eq!("foo", meta.crate_name.as_ref().unwrap());
|
||||
assert_eq!("foo", meta.krate.as_ref().unwrap());
|
||||
assert_eq!("/lib.rs", meta.path);
|
||||
assert_eq!(2, meta.env.len());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user