aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils')
-rw-r--r--crates/test_utils/src/fixture.rs58
-rw-r--r--crates/test_utils/src/minicore.rs36
2 files changed, 71 insertions, 23 deletions
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index 6ba112de8..005a5c092 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -129,8 +129,18 @@ impl Fixture {
129 if line.starts_with("//-") { 129 if line.starts_with("//-") {
130 let meta = Fixture::parse_meta_line(line); 130 let meta = Fixture::parse_meta_line(line);
131 res.push(meta) 131 res.push(meta)
132 } else if let Some(entry) = res.last_mut() { 132 } else {
133 entry.text.push_str(line); 133 if line.starts_with("// ")
134 && line.contains(":")
135 && !line.contains("::")
136 && line.chars().all(|it| !it.is_uppercase())
137 {
138 panic!("looks like invalid metadata line: {:?}", line)
139 }
140
141 if let Some(entry) = res.last_mut() {
142 entry.text.push_str(line);
143 }
134 } 144 }
135 } 145 }
136 146
@@ -154,7 +164,9 @@ impl Fixture {
154 let mut env = FxHashMap::default(); 164 let mut env = FxHashMap::default();
155 let mut introduce_new_source_root = false; 165 let mut introduce_new_source_root = false;
156 for component in components[1..].iter() { 166 for component in components[1..].iter() {
157 let (key, value) = component.split_once(':').unwrap(); 167 let (key, value) = component
168 .split_once(':')
169 .unwrap_or_else(|| panic!("invalid meta line: {:?}", meta));
158 match key { 170 match key {
159 "crate" => krate = Some(value.to_string()), 171 "crate" => krate = Some(value.to_string()),
160 "deps" => deps = value.split(',').map(|it| it.to_string()).collect(), 172 "deps" => deps = value.split(',').map(|it| it.to_string()).collect(),
@@ -276,38 +288,44 @@ impl MiniCore {
276 } 288 }
277 } 289 }
278 290
279 let mut curr_region = ""; 291 let mut active_regions = Vec::new();
280 let mut seen_regions = Vec::new(); 292 let mut seen_regions = Vec::new();
281 for line in lines { 293 for line in lines {
282 let trimmed = line.trim(); 294 let trimmed = line.trim();
283 if let Some(region) = trimmed.strip_prefix("// region:") { 295 if let Some(region) = trimmed.strip_prefix("// region:") {
284 assert_eq!(curr_region, ""); 296 active_regions.push(region);
285 curr_region = region;
286 continue; 297 continue;
287 } 298 }
288 if let Some(region) = trimmed.strip_prefix("// endregion:") { 299 if let Some(region) = trimmed.strip_prefix("// endregion:") {
289 assert_eq!(curr_region, region); 300 let prev = active_regions.pop().unwrap();
290 curr_region = ""; 301 assert_eq!(prev, region);
291 continue; 302 continue;
292 } 303 }
293 seen_regions.push(curr_region);
294 304
295 let mut flag = curr_region; 305 let mut line_region = false;
296 if let Some(idx) = trimmed.find("// :") { 306 if let Some(idx) = trimmed.find("// :") {
297 flag = &trimmed[idx + "// :".len()..]; 307 line_region = true;
308 active_regions.push(&trimmed[idx + "// :".len()..]);
298 } 309 }
299 310
300 let skip = if flag == "" { 311 let mut keep = true;
301 false 312 for &region in &active_regions {
302 } else { 313 assert!(
303 assert!(!flag.starts_with(' '), "region marker starts with a space: {:?}", flag); 314 !region.starts_with(' '),
304 self.assert_valid_flag(flag); 315 "region marker starts with a space: {:?}",
305 !self.has_flag(flag) 316 region
306 }; 317 );
318 self.assert_valid_flag(region);
319 seen_regions.push(region);
320 keep &= self.has_flag(region);
321 }
307 322
308 if !skip { 323 if keep {
309 buf.push_str(line) 324 buf.push_str(line)
310 } 325 }
326 if line_region {
327 active_regions.pop().unwrap();
328 }
311 } 329 }
312 330
313 for flag in &self.valid_flags { 331 for flag in &self.valid_flags {
@@ -315,7 +333,7 @@ impl MiniCore {
315 panic!("unused minicore flag: {:?}", flag); 333 panic!("unused minicore flag: {:?}", flag);
316 } 334 }
317 } 335 }
318 336 format!("{}", buf);
319 buf 337 buf
320 } 338 }
321} 339}
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs
index 5ff60178c..e04ca58d2 100644
--- a/crates/test_utils/src/minicore.rs
+++ b/crates/test_utils/src/minicore.rs
@@ -9,11 +9,13 @@
9//! 9//!
10//! Available flags: 10//! Available flags:
11//! sized: 11//! sized:
12//! unsize: sized
13//! coerce_unsized: unsize
12//! slice: 14//! slice:
13//! range: 15//! range:
14//! unsize: sized
15//! deref: sized 16//! deref: sized
16//! coerce_unsized: unsize 17//! deref_mut: deref
18//! fn:
17//! pin: 19//! pin:
18//! future: pin 20//! future: pin
19//! option: 21//! option:
@@ -64,9 +66,16 @@ pub mod ops {
64 type Target: ?Sized; 66 type Target: ?Sized;
65 fn deref(&self) -> &Self::Target; 67 fn deref(&self) -> &Self::Target;
66 } 68 }
69 // region:deref_mut
70 #[lang = "deref_mut"]
71 pub trait DerefMut: Deref {
72 fn deref_mut(&mut self) -> &mut Self::Target;
73 }
74 // endregion:deref_mut
67 } 75 }
68 pub use self::deref::Deref; 76 pub use self::deref::Deref;
69 // endregion:deref 77 pub use self::deref::DerefMut; //:deref_mut
78 // endregion:deref
70 79
71 // region:range 80 // region:range
72 mod range { 81 mod range {
@@ -104,6 +113,26 @@ pub mod ops {
104 pub use self::range::{Range, RangeFrom, RangeFull, RangeTo}; 113 pub use self::range::{Range, RangeFrom, RangeFull, RangeTo};
105 pub use self::range::{RangeInclusive, RangeToInclusive}; 114 pub use self::range::{RangeInclusive, RangeToInclusive};
106 // endregion:range 115 // endregion:range
116
117 // region:fn
118 mod function {
119 #[lang = "fn"]
120 #[fundamental]
121 pub trait Fn<Args>: FnMut<Args> {}
122
123 #[lang = "fn_mut"]
124 #[fundamental]
125 pub trait FnMut<Args>: FnOnce<Args> {}
126
127 #[lang = "fn_once"]
128 #[fundamental]
129 pub trait FnOnce<Args> {
130 #[lang = "fn_once_output"]
131 type Output;
132 }
133 }
134 pub use self::function::{Fn, FnMut, FnOnce};
135 // endregion:fn
107} 136}
108 137
109// region:slice 138// region:slice
@@ -181,6 +210,7 @@ pub mod prelude {
181 pub mod v1 { 210 pub mod v1 {
182 pub use crate::{ 211 pub use crate::{
183 marker::Sized, // :sized 212 marker::Sized, // :sized
213 ops::{Fn, FnMut, FnOnce}, // :fn
184 option::Option::{self, None, Some}, // :option 214 option::Option::{self, None, Some}, // :option
185 result::Result::{self, Err, Ok}, // :result 215 result::Result::{self, Err, Ok}, // :result
186 }; 216 };