Skip to content

Commit eecb6f7

Browse files
authored
A bit of cleanup (#17394)
Was working on another issue and noticed that I wanted these but they aren't related to any of the issues. So opening a separate PR to do some internal cleanup.
1 parent 224ce0b commit eecb6f7

22 files changed

+89
-52
lines changed

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/oxide/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ regex = "1.11.1"
2222

2323
[dev-dependencies]
2424
tempfile = "3.13.0"
25+
pretty_assertions = "1.4.1"

crates/oxide/src/cursor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl Display for Cursor<'_> {
119119
#[cfg(test)]
120120
mod test {
121121
use super::*;
122+
use pretty_assertions::assert_eq;
122123

123124
#[test]
124125
fn test_cursor() {

crates/oxide/src/extractor/arbitrary_property_machine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ enum Class {
307307
mod tests {
308308
use super::{ArbitraryPropertyMachine, IdleState};
309309
use crate::extractor::machine::Machine;
310+
use pretty_assertions::assert_eq;
310311

311312
#[test]
312313
#[ignore]
@@ -413,7 +414,7 @@ mod tests {
413414
let actual = ArbitraryPropertyMachine::<IdleState>::test_extract_all(&input);
414415

415416
if actual != expected {
416-
dbg!(&input, &actual, &expected);
417+
dbg!(&input);
417418
}
418419
assert_eq!(actual, expected);
419420
}

crates/oxide/src/extractor/arbitrary_value_machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ enum Class {
149149
mod tests {
150150
use super::ArbitraryValueMachine;
151151
use crate::extractor::machine::Machine;
152+
use pretty_assertions::assert_eq;
152153

153154
#[test]
154155
#[ignore]

crates/oxide/src/extractor/arbitrary_variable_machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ enum Class {
336336
mod tests {
337337
use super::ArbitraryVariableMachine;
338338
use crate::extractor::{arbitrary_variable_machine::IdleState, machine::Machine};
339+
use pretty_assertions::assert_eq;
339340

340341
#[test]
341342
#[ignore]

crates/oxide/src/extractor/candidate_machine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ impl CandidateMachine {
181181
mod tests {
182182
use super::CandidateMachine;
183183
use crate::extractor::machine::Machine;
184+
use pretty_assertions::assert_eq;
184185

185186
#[test]
186187
#[ignore]
@@ -307,7 +308,7 @@ mod tests {
307308
actual.sort();
308309

309310
if actual != expected {
310-
dbg!(&input, &expected, &actual);
311+
dbg!(&input);
311312
}
312313

313314
assert_eq!(actual, expected);

crates/oxide/src/extractor/css_variable_machine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ enum Class {
116116
mod tests {
117117
use super::CssVariableMachine;
118118
use crate::extractor::machine::Machine;
119+
use pretty_assertions::assert_eq;
119120

120121
#[test]
121122
#[ignore]
@@ -203,7 +204,7 @@ mod tests {
203204
let actual = CssVariableMachine::test_extract_all(&input);
204205

205206
if actual != expected {
206-
dbg!(&input, &actual, &expected);
207+
dbg!(&input);
207208
}
208209

209210
assert_eq!(actual, expected);

crates/oxide/src/extractor/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ fn drop_covered_spans(mut spans: Vec<Span>) -> Vec<Span> {
199199
mod tests {
200200
use super::{Extracted, Extractor};
201201
use crate::throughput::Throughput;
202+
use pretty_assertions::assert_eq;
202203
use std::hint::black_box;
203204

204205
fn pre_process_input(input: &str, extension: &str) -> String {
@@ -244,7 +245,7 @@ mod tests {
244245
expected.dedup();
245246

246247
if actual != expected {
247-
dbg!(&input, &actual, &expected);
248+
dbg!(&input);
248249
}
249250
assert_eq!(actual, expected);
250251
}
@@ -272,7 +273,7 @@ mod tests {
272273
expected.sort();
273274

274275
if actual != expected {
275-
dbg!(&input, &actual, &expected);
276+
dbg!(&input);
276277
}
277278
assert_eq!(actual, expected);
278279
}

crates/oxide/src/extractor/modifier_machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ enum Class {
121121
mod tests {
122122
use super::ModifierMachine;
123123
use crate::extractor::machine::Machine;
124+
use pretty_assertions::assert_eq;
124125

125126
#[test]
126127
#[ignore]

crates/oxide/src/extractor/named_utility_machine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ enum Class {
386386
mod tests {
387387
use super::{IdleState, NamedUtilityMachine};
388388
use crate::extractor::machine::Machine;
389+
use pretty_assertions::assert_eq;
389390

390391
#[test]
391392
#[ignore]
@@ -515,7 +516,7 @@ mod tests {
515516
actual.sort();
516517

517518
if actual != expected {
518-
dbg!(&input, &expected, &actual);
519+
dbg!(&input);
519520
}
520521
assert_eq!(actual, expected);
521522
}

crates/oxide/src/extractor/named_variant_machine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ enum Class {
367367
mod tests {
368368
use super::{IdleState, NamedVariantMachine};
369369
use crate::extractor::machine::Machine;
370+
use pretty_assertions::assert_eq;
370371

371372
#[test]
372373
#[ignore]
@@ -413,7 +414,7 @@ mod tests {
413414
] {
414415
let actual = NamedVariantMachine::<IdleState>::test_extract_all(input);
415416
if actual != expected {
416-
dbg!(&input, &actual, &expected);
417+
dbg!(&input);
417418
}
418419
assert_eq!(actual, expected);
419420
}

crates/oxide/src/extractor/pre_processors/haml.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl PreProcessor for Haml {
9393
mod tests {
9494
use super::Haml;
9595
use crate::extractor::pre_processors::pre_processor::PreProcessor;
96+
use pretty_assertions::assert_eq;
9697

9798
#[test]
9899
fn test_haml_pre_processor() {

crates/oxide/src/extractor/pre_processors/pre_processor.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pub trait PreProcessor: Sized + Default {
33

44
#[cfg(test)]
55
fn test(input: &str, expected: &str) {
6+
use pretty_assertions::assert_eq;
7+
68
let input = input.as_bytes();
79
let expected = expected.as_bytes();
810

@@ -15,10 +17,6 @@ pub trait PreProcessor: Sized + Default {
1517
let actual = String::from_utf8_lossy(&actual);
1618
let expected = String::from_utf8_lossy(expected);
1719

18-
if actual != expected {
19-
dbg!((&input, &actual, &expected));
20-
}
21-
2220
// The input and output should have the exact same length.
2321
assert_eq!(input.len(), actual.len());
2422
assert_eq!(actual.len(), expected.len());

crates/oxide/src/extractor/pre_processors/ruby.rs

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ use std::sync;
1010

1111
static TEMPLATE_START_REGEX: sync::LazyLock<Regex> = sync::LazyLock::new(|| {
1212
RegexBuilder::new(r#"\s*([a-z0-9_-]+)_template\s*<<[-~]?([A-Z]+)$"#)
13-
.multi_line(true)
14-
.build()
15-
.unwrap()
13+
.multi_line(true)
14+
.build()
15+
.unwrap()
1616
});
1717

1818
static TEMPLATE_END_REGEX: sync::LazyLock<Regex> = sync::LazyLock::new(|| {
19-
RegexBuilder::new(r#"^\s*([A-Z]+)"#)
20-
.multi_line(true)
21-
.build()
22-
.unwrap()
19+
RegexBuilder::new(r#"^\s*([A-Z]+)"#)
20+
.multi_line(true)
21+
.build()
22+
.unwrap()
2323
});
2424

2525
#[derive(Debug, Default)]
@@ -36,39 +36,43 @@ impl PreProcessor for Ruby {
3636
// https://viewcomponent.org/guide/templates.html#interpolations
3737
let content_as_str = std::str::from_utf8(content).unwrap();
3838

39-
let starts = TEMPLATE_START_REGEX.captures_iter(content_as_str).collect::<Vec<_>>();
40-
let ends = TEMPLATE_END_REGEX.captures_iter(content_as_str).collect::<Vec<_>>();
39+
let starts = TEMPLATE_START_REGEX
40+
.captures_iter(content_as_str)
41+
.collect::<Vec<_>>();
42+
let ends = TEMPLATE_END_REGEX
43+
.captures_iter(content_as_str)
44+
.collect::<Vec<_>>();
4145

4246
for start in starts.iter() {
43-
// The language for this block
44-
let lang = start.get(1).unwrap().as_str();
47+
// The language for this block
48+
let lang = start.get(1).unwrap().as_str();
4549

46-
// The HEREDOC delimiter
47-
let delimiter_start = start.get(2).unwrap().as_str();
50+
// The HEREDOC delimiter
51+
let delimiter_start = start.get(2).unwrap().as_str();
4852

49-
// Where the "body" starts for the HEREDOC block
50-
let body_start = start.get(0).unwrap().end();
53+
// Where the "body" starts for the HEREDOC block
54+
let body_start = start.get(0).unwrap().end();
5155

52-
// Look through all of the ends to find a matching language
53-
for end in ends.iter() {
54-
// 1. This must appear after the start
55-
let body_end = end.get(0).unwrap().start();
56-
if body_end < body_start {
57-
continue;
58-
}
56+
// Look through all of the ends to find a matching language
57+
for end in ends.iter() {
58+
// 1. This must appear after the start
59+
let body_end = end.get(0).unwrap().start();
60+
if body_end < body_start {
61+
continue;
62+
}
5963

60-
// The languages must match otherwise we haven't found the end
61-
let delimiter_end = end.get(1).unwrap().as_str();
62-
if delimiter_end != delimiter_start {
63-
continue;
64-
}
64+
// The languages must match otherwise we haven't found the end
65+
let delimiter_end = end.get(1).unwrap().as_str();
66+
if delimiter_end != delimiter_start {
67+
continue;
68+
}
6569

66-
let body = &content_as_str[body_start..body_end];
67-
let replaced = pre_process_input(body.as_bytes(), &lang.to_ascii_lowercase());
70+
let body = &content_as_str[body_start..body_end];
71+
let replaced = pre_process_input(body.as_bytes(), &lang.to_ascii_lowercase());
6872

69-
result.replace_range(body_start..body_end, replaced);
70-
break;
71-
}
73+
result.replace_range(body_start..body_end, replaced);
74+
break;
75+
}
7276
}
7377

7478
// Ruby extraction

crates/oxide/src/extractor/string_machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ enum Class {
8787
mod tests {
8888
use super::StringMachine;
8989
use crate::extractor::machine::Machine;
90+
use pretty_assertions::assert_eq;
9091

9192
#[test]
9293
#[ignore]

crates/oxide/src/extractor/utility_machine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ enum Class {
192192
mod tests {
193193
use super::UtilityMachine;
194194
use crate::extractor::machine::Machine;
195+
use pretty_assertions::assert_eq;
195196

196197
#[test]
197198
#[ignore]
@@ -336,7 +337,7 @@ mod tests {
336337
actual.sort();
337338

338339
if actual != expected {
339-
dbg!(&input, &expected, &actual);
340+
dbg!(&input);
340341
}
341342
assert_eq!(actual, expected);
342343
}

crates/oxide/src/extractor/variant_machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ enum Class {
8080
mod tests {
8181
use super::VariantMachine;
8282
use crate::extractor::machine::Machine;
83+
use pretty_assertions::assert_eq;
8384

8485
#[test]
8586
#[ignore]

crates/oxide/src/glob.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ mod tests {
191191
use super::optimize_patterns;
192192
use crate::GlobEntry;
193193
use bexpand::Expression;
194+
use pretty_assertions::assert_eq;
194195
use std::process::Command;
195196
use std::{fs, path};
196197
use tempfile::tempdir;

crates/oxide/src/scanner/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ fn create_walker(sources: Sources) -> Option<WalkBuilder> {
664664
#[cfg(test)]
665665
mod tests {
666666
use super::{ChangedContent, Scanner};
667+
use pretty_assertions::assert_eq;
667668

668669
#[test]
669670
fn test_positions() {

crates/oxide/src/scanner/sources.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,8 @@ impl PublicSourceEntry {
128128
.to_string_lossy()
129129
.to_string();
130130
// Ensure leading slash, otherwise it will match against all files in all folders/
131-
self.pattern = format!(
132-
"/{}",
133-
resolved_path
134-
.file_name()
135-
.unwrap()
136-
.to_string_lossy()
137-
.to_string()
138-
);
131+
self.pattern =
132+
format!("/{}", resolved_path.file_name().unwrap().to_string_lossy());
139133
}
140134
_ => {}
141135
}

crates/oxide/tests/scanner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[cfg(test)]
22
mod scanner {
3+
use pretty_assertions::assert_eq;
34
use std::path::{Path, PathBuf};
45
use std::process::Command;
56
use std::thread::sleep;

0 commit comments

Comments
 (0)