aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils')
-rw-r--r--crates/test_utils/src/lib.rs37
-rw-r--r--crates/test_utils/src/marks.rs5
2 files changed, 12 insertions, 30 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 35a679aea..09fc2e659 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -85,9 +85,7 @@ pub fn extract_ranges(mut text: &str, tag: &str) -> (Vec<TextRange>, String) {
85 stack.push(from); 85 stack.push(from);
86 } else if text.starts_with(&close) { 86 } else if text.starts_with(&close) {
87 text = &text[close.len()..]; 87 text = &text[close.len()..];
88 let from = stack 88 let from = stack.pop().unwrap_or_else(|| panic!("unmatched </{}>", tag));
89 .pop()
90 .unwrap_or_else(|| panic!("unmatched </{}>", tag));
91 let to = TextUnit::of_str(&res); 89 let to = TextUnit::of_str(&res);
92 ranges.push(TextRange::from_to(from, to)); 90 ranges.push(TextRange::from_to(from, to));
93 } 91 }
@@ -131,10 +129,7 @@ pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
131 macro_rules! flush { 129 macro_rules! flush {
132 () => { 130 () => {
133 if let Some(meta) = meta { 131 if let Some(meta) = meta {
134 res.push(FixtureEntry { 132 res.push(FixtureEntry { meta: meta.to_string(), text: buf.clone() });
135 meta: meta.to_string(),
136 text: buf.clone(),
137 });
138 buf.clear(); 133 buf.clear();
139 } 134 }
140 }; 135 };
@@ -226,15 +221,13 @@ pub fn find_mismatch<'a>(expected: &'a Value, actual: &'a Value) -> Option<(&'a
226 let mut l = l.iter().collect::<Vec<_>>(); 221 let mut l = l.iter().collect::<Vec<_>>();
227 let mut r = r.iter().collect::<Vec<_>>(); 222 let mut r = r.iter().collect::<Vec<_>>();
228 223
229 l.retain( 224 l.retain(|l| match r.iter().position(|r| find_mismatch(l, r).is_none()) {
230 |l| match r.iter().position(|r| find_mismatch(l, r).is_none()) { 225 Some(i) => {
231 Some(i) => { 226 r.remove(i);
232 r.remove(i); 227 false
233 false 228 }
234 } 229 None => true,
235 None => true, 230 });
236 },
237 );
238 231
239 if !l.is_empty() { 232 if !l.is_empty() {
240 assert!(!r.is_empty()); 233 assert!(!r.is_empty());
@@ -250,10 +243,7 @@ pub fn find_mismatch<'a>(expected: &'a Value, actual: &'a Value) -> Option<(&'a
250 return Some((expected, actual)); 243 return Some((expected, actual));
251 } 244 }
252 245
253 l.values() 246 l.values().zip(r.values()).filter_map(|(l, r)| find_mismatch(l, r)).nth(0)
254 .zip(r.values())
255 .filter_map(|(l, r)| find_mismatch(l, r))
256 .nth(0)
257 } 247 }
258 (&Null, &Null) => None, 248 (&Null, &Null) => None,
259 // magic string literal "{...}" acts as wildcard for any sub-JSON 249 // magic string literal "{...}" acts as wildcard for any sub-JSON
@@ -312,12 +302,7 @@ fn test_from_dir(dir: &Path) -> Vec<PathBuf> {
312 302
313pub fn project_dir() -> PathBuf { 303pub fn project_dir() -> PathBuf {
314 let dir = env!("CARGO_MANIFEST_DIR"); 304 let dir = env!("CARGO_MANIFEST_DIR");
315 PathBuf::from(dir) 305 PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned()
316 .parent()
317 .unwrap()
318 .parent()
319 .unwrap()
320 .to_owned()
321} 306}
322 307
323/// Read file and normalize newlines. 308/// Read file and normalize newlines.
diff --git a/crates/test_utils/src/marks.rs b/crates/test_utils/src/marks.rs
index ee47b5219..d2a84643c 100644
--- a/crates/test_utils/src/marks.rs
+++ b/crates/test_utils/src/marks.rs
@@ -64,10 +64,7 @@ pub struct MarkChecker {
64impl MarkChecker { 64impl MarkChecker {
65 pub fn new(mark: &'static AtomicUsize) -> MarkChecker { 65 pub fn new(mark: &'static AtomicUsize) -> MarkChecker {
66 let value_on_entry = mark.load(Ordering::SeqCst); 66 let value_on_entry = mark.load(Ordering::SeqCst);
67 MarkChecker { 67 MarkChecker { mark, value_on_entry }
68 mark,
69 value_on_entry,
70 }
71 } 68 }
72} 69}
73 70