diff --git a/Cargo.lock b/Cargo.lock index 3d28efbfe..51aaf4134 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,6 +134,12 @@ dependencies = [ "syn", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "dunce" version = "1.0.5" @@ -387,6 +393,16 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +[[package]] +name = "pretty_assertions" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" +dependencies = [ + "diff", + "yansi", +] + [[package]] name = "proc-macro2" version = "1.0.86" @@ -559,6 +575,7 @@ dependencies = [ "globwalk", "ignore 0.4.23", "log", + "pretty_assertions", "rayon", "regex", "rustc-hash", @@ -792,3 +809,9 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" diff --git a/crates/oxide/Cargo.toml b/crates/oxide/Cargo.toml index c2e0b7155..3c5624b45 100644 --- a/crates/oxide/Cargo.toml +++ b/crates/oxide/Cargo.toml @@ -22,3 +22,4 @@ regex = "1.11.1" [dev-dependencies] tempfile = "3.13.0" +pretty_assertions = "1.4.1" diff --git a/crates/oxide/src/cursor.rs b/crates/oxide/src/cursor.rs index ebda110a2..818a0ef1b 100644 --- a/crates/oxide/src/cursor.rs +++ b/crates/oxide/src/cursor.rs @@ -119,6 +119,7 @@ impl Display for Cursor<'_> { #[cfg(test)] mod test { use super::*; + use pretty_assertions::assert_eq; #[test] fn test_cursor() { diff --git a/crates/oxide/src/extractor/arbitrary_property_machine.rs b/crates/oxide/src/extractor/arbitrary_property_machine.rs index bf5373a3d..8ed3f1763 100644 --- a/crates/oxide/src/extractor/arbitrary_property_machine.rs +++ b/crates/oxide/src/extractor/arbitrary_property_machine.rs @@ -307,6 +307,7 @@ enum Class { mod tests { use super::{ArbitraryPropertyMachine, IdleState}; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] @@ -413,7 +414,7 @@ mod tests { let actual = ArbitraryPropertyMachine::::test_extract_all(&input); if actual != expected { - dbg!(&input, &actual, &expected); + dbg!(&input); } assert_eq!(actual, expected); } diff --git a/crates/oxide/src/extractor/arbitrary_value_machine.rs b/crates/oxide/src/extractor/arbitrary_value_machine.rs index b4370c2d2..f5a612df1 100644 --- a/crates/oxide/src/extractor/arbitrary_value_machine.rs +++ b/crates/oxide/src/extractor/arbitrary_value_machine.rs @@ -149,6 +149,7 @@ enum Class { mod tests { use super::ArbitraryValueMachine; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] diff --git a/crates/oxide/src/extractor/arbitrary_variable_machine.rs b/crates/oxide/src/extractor/arbitrary_variable_machine.rs index 355572769..6990e110b 100644 --- a/crates/oxide/src/extractor/arbitrary_variable_machine.rs +++ b/crates/oxide/src/extractor/arbitrary_variable_machine.rs @@ -336,6 +336,7 @@ enum Class { mod tests { use super::ArbitraryVariableMachine; use crate::extractor::{arbitrary_variable_machine::IdleState, machine::Machine}; + use pretty_assertions::assert_eq; #[test] #[ignore] diff --git a/crates/oxide/src/extractor/candidate_machine.rs b/crates/oxide/src/extractor/candidate_machine.rs index 33b67098f..c82cc3707 100644 --- a/crates/oxide/src/extractor/candidate_machine.rs +++ b/crates/oxide/src/extractor/candidate_machine.rs @@ -181,6 +181,7 @@ impl CandidateMachine { mod tests { use super::CandidateMachine; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] @@ -307,7 +308,7 @@ mod tests { actual.sort(); if actual != expected { - dbg!(&input, &expected, &actual); + dbg!(&input); } assert_eq!(actual, expected); diff --git a/crates/oxide/src/extractor/css_variable_machine.rs b/crates/oxide/src/extractor/css_variable_machine.rs index ab6ab3121..4e19c7111 100644 --- a/crates/oxide/src/extractor/css_variable_machine.rs +++ b/crates/oxide/src/extractor/css_variable_machine.rs @@ -116,6 +116,7 @@ enum Class { mod tests { use super::CssVariableMachine; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] @@ -203,7 +204,7 @@ mod tests { let actual = CssVariableMachine::test_extract_all(&input); if actual != expected { - dbg!(&input, &actual, &expected); + dbg!(&input); } assert_eq!(actual, expected); diff --git a/crates/oxide/src/extractor/mod.rs b/crates/oxide/src/extractor/mod.rs index 737189104..fc9a87086 100644 --- a/crates/oxide/src/extractor/mod.rs +++ b/crates/oxide/src/extractor/mod.rs @@ -199,6 +199,7 @@ fn drop_covered_spans(mut spans: Vec) -> Vec { mod tests { use super::{Extracted, Extractor}; use crate::throughput::Throughput; + use pretty_assertions::assert_eq; use std::hint::black_box; fn pre_process_input(input: &str, extension: &str) -> String { @@ -244,7 +245,7 @@ mod tests { expected.dedup(); if actual != expected { - dbg!(&input, &actual, &expected); + dbg!(&input); } assert_eq!(actual, expected); } @@ -272,7 +273,7 @@ mod tests { expected.sort(); if actual != expected { - dbg!(&input, &actual, &expected); + dbg!(&input); } assert_eq!(actual, expected); } diff --git a/crates/oxide/src/extractor/modifier_machine.rs b/crates/oxide/src/extractor/modifier_machine.rs index 3104a0b11..22668a828 100644 --- a/crates/oxide/src/extractor/modifier_machine.rs +++ b/crates/oxide/src/extractor/modifier_machine.rs @@ -121,6 +121,7 @@ enum Class { mod tests { use super::ModifierMachine; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] diff --git a/crates/oxide/src/extractor/named_utility_machine.rs b/crates/oxide/src/extractor/named_utility_machine.rs index e206cadc0..e92baac2a 100644 --- a/crates/oxide/src/extractor/named_utility_machine.rs +++ b/crates/oxide/src/extractor/named_utility_machine.rs @@ -386,6 +386,7 @@ enum Class { mod tests { use super::{IdleState, NamedUtilityMachine}; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] @@ -515,7 +516,7 @@ mod tests { actual.sort(); if actual != expected { - dbg!(&input, &expected, &actual); + dbg!(&input); } assert_eq!(actual, expected); } diff --git a/crates/oxide/src/extractor/named_variant_machine.rs b/crates/oxide/src/extractor/named_variant_machine.rs index 642c568a3..b6de8220b 100644 --- a/crates/oxide/src/extractor/named_variant_machine.rs +++ b/crates/oxide/src/extractor/named_variant_machine.rs @@ -367,6 +367,7 @@ enum Class { mod tests { use super::{IdleState, NamedVariantMachine}; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] @@ -413,7 +414,7 @@ mod tests { ] { let actual = NamedVariantMachine::::test_extract_all(input); if actual != expected { - dbg!(&input, &actual, &expected); + dbg!(&input); } assert_eq!(actual, expected); } diff --git a/crates/oxide/src/extractor/pre_processors/haml.rs b/crates/oxide/src/extractor/pre_processors/haml.rs index 37cb19054..2e535bf41 100644 --- a/crates/oxide/src/extractor/pre_processors/haml.rs +++ b/crates/oxide/src/extractor/pre_processors/haml.rs @@ -93,6 +93,7 @@ impl PreProcessor for Haml { mod tests { use super::Haml; use crate::extractor::pre_processors::pre_processor::PreProcessor; + use pretty_assertions::assert_eq; #[test] fn test_haml_pre_processor() { diff --git a/crates/oxide/src/extractor/pre_processors/pre_processor.rs b/crates/oxide/src/extractor/pre_processors/pre_processor.rs index 8c807c8c3..7b094129c 100644 --- a/crates/oxide/src/extractor/pre_processors/pre_processor.rs +++ b/crates/oxide/src/extractor/pre_processors/pre_processor.rs @@ -3,6 +3,8 @@ pub trait PreProcessor: Sized + Default { #[cfg(test)] fn test(input: &str, expected: &str) { + use pretty_assertions::assert_eq; + let input = input.as_bytes(); let expected = expected.as_bytes(); @@ -15,10 +17,6 @@ pub trait PreProcessor: Sized + Default { let actual = String::from_utf8_lossy(&actual); let expected = String::from_utf8_lossy(expected); - if actual != expected { - dbg!((&input, &actual, &expected)); - } - // The input and output should have the exact same length. assert_eq!(input.len(), actual.len()); assert_eq!(actual.len(), expected.len()); diff --git a/crates/oxide/src/extractor/pre_processors/ruby.rs b/crates/oxide/src/extractor/pre_processors/ruby.rs index 7db1f08f6..6bb1d4923 100644 --- a/crates/oxide/src/extractor/pre_processors/ruby.rs +++ b/crates/oxide/src/extractor/pre_processors/ruby.rs @@ -10,16 +10,16 @@ use std::sync; static TEMPLATE_START_REGEX: sync::LazyLock = sync::LazyLock::new(|| { RegexBuilder::new(r#"\s*([a-z0-9_-]+)_template\s*<<[-~]?([A-Z]+)$"#) - .multi_line(true) - .build() - .unwrap() + .multi_line(true) + .build() + .unwrap() }); static TEMPLATE_END_REGEX: sync::LazyLock = sync::LazyLock::new(|| { - RegexBuilder::new(r#"^\s*([A-Z]+)"#) - .multi_line(true) - .build() - .unwrap() + RegexBuilder::new(r#"^\s*([A-Z]+)"#) + .multi_line(true) + .build() + .unwrap() }); #[derive(Debug, Default)] @@ -36,39 +36,43 @@ impl PreProcessor for Ruby { // https://viewcomponent.org/guide/templates.html#interpolations let content_as_str = std::str::from_utf8(content).unwrap(); - let starts = TEMPLATE_START_REGEX.captures_iter(content_as_str).collect::>(); - let ends = TEMPLATE_END_REGEX.captures_iter(content_as_str).collect::>(); + let starts = TEMPLATE_START_REGEX + .captures_iter(content_as_str) + .collect::>(); + let ends = TEMPLATE_END_REGEX + .captures_iter(content_as_str) + .collect::>(); for start in starts.iter() { - // The language for this block - let lang = start.get(1).unwrap().as_str(); + // The language for this block + let lang = start.get(1).unwrap().as_str(); - // The HEREDOC delimiter - let delimiter_start = start.get(2).unwrap().as_str(); + // The HEREDOC delimiter + let delimiter_start = start.get(2).unwrap().as_str(); - // Where the "body" starts for the HEREDOC block - let body_start = start.get(0).unwrap().end(); + // Where the "body" starts for the HEREDOC block + let body_start = start.get(0).unwrap().end(); - // Look through all of the ends to find a matching language - for end in ends.iter() { - // 1. This must appear after the start - let body_end = end.get(0).unwrap().start(); - if body_end < body_start { - continue; + // Look through all of the ends to find a matching language + for end in ends.iter() { + // 1. This must appear after the start + let body_end = end.get(0).unwrap().start(); + if body_end < body_start { + continue; + } + + // The languages must match otherwise we haven't found the end + let delimiter_end = end.get(1).unwrap().as_str(); + if delimiter_end != delimiter_start { + continue; + } + + let body = &content_as_str[body_start..body_end]; + let replaced = pre_process_input(body.as_bytes(), &lang.to_ascii_lowercase()); + + result.replace_range(body_start..body_end, replaced); + break; } - - // The languages must match otherwise we haven't found the end - let delimiter_end = end.get(1).unwrap().as_str(); - if delimiter_end != delimiter_start { - continue; - } - - let body = &content_as_str[body_start..body_end]; - let replaced = pre_process_input(body.as_bytes(), &lang.to_ascii_lowercase()); - - result.replace_range(body_start..body_end, replaced); - break; - } } // Ruby extraction diff --git a/crates/oxide/src/extractor/string_machine.rs b/crates/oxide/src/extractor/string_machine.rs index 72a1a4c88..9148a1fbf 100644 --- a/crates/oxide/src/extractor/string_machine.rs +++ b/crates/oxide/src/extractor/string_machine.rs @@ -87,6 +87,7 @@ enum Class { mod tests { use super::StringMachine; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] diff --git a/crates/oxide/src/extractor/utility_machine.rs b/crates/oxide/src/extractor/utility_machine.rs index 26b7019c2..b9b1038cd 100644 --- a/crates/oxide/src/extractor/utility_machine.rs +++ b/crates/oxide/src/extractor/utility_machine.rs @@ -192,6 +192,7 @@ enum Class { mod tests { use super::UtilityMachine; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] @@ -336,7 +337,7 @@ mod tests { actual.sort(); if actual != expected { - dbg!(&input, &expected, &actual); + dbg!(&input); } assert_eq!(actual, expected); } diff --git a/crates/oxide/src/extractor/variant_machine.rs b/crates/oxide/src/extractor/variant_machine.rs index b7a0deb86..23aa61798 100644 --- a/crates/oxide/src/extractor/variant_machine.rs +++ b/crates/oxide/src/extractor/variant_machine.rs @@ -80,6 +80,7 @@ enum Class { mod tests { use super::VariantMachine; use crate::extractor::machine::Machine; + use pretty_assertions::assert_eq; #[test] #[ignore] diff --git a/crates/oxide/src/glob.rs b/crates/oxide/src/glob.rs index 5b6e0715f..9a6296bcb 100644 --- a/crates/oxide/src/glob.rs +++ b/crates/oxide/src/glob.rs @@ -191,6 +191,7 @@ mod tests { use super::optimize_patterns; use crate::GlobEntry; use bexpand::Expression; + use pretty_assertions::assert_eq; use std::process::Command; use std::{fs, path}; use tempfile::tempdir; diff --git a/crates/oxide/src/scanner/mod.rs b/crates/oxide/src/scanner/mod.rs index 416191c27..57624910f 100644 --- a/crates/oxide/src/scanner/mod.rs +++ b/crates/oxide/src/scanner/mod.rs @@ -664,6 +664,7 @@ fn create_walker(sources: Sources) -> Option { #[cfg(test)] mod tests { use super::{ChangedContent, Scanner}; + use pretty_assertions::assert_eq; #[test] fn test_positions() { diff --git a/crates/oxide/src/scanner/sources.rs b/crates/oxide/src/scanner/sources.rs index ea6c115a4..f28b16a49 100644 --- a/crates/oxide/src/scanner/sources.rs +++ b/crates/oxide/src/scanner/sources.rs @@ -128,14 +128,8 @@ impl PublicSourceEntry { .to_string_lossy() .to_string(); // Ensure leading slash, otherwise it will match against all files in all folders/ - self.pattern = format!( - "/{}", - resolved_path - .file_name() - .unwrap() - .to_string_lossy() - .to_string() - ); + self.pattern = + format!("/{}", resolved_path.file_name().unwrap().to_string_lossy()); } _ => {} } diff --git a/crates/oxide/tests/scanner.rs b/crates/oxide/tests/scanner.rs index c5ece5d75..ab91a8c72 100644 --- a/crates/oxide/tests/scanner.rs +++ b/crates/oxide/tests/scanner.rs @@ -1,5 +1,6 @@ #[cfg(test)] mod scanner { + use pretty_assertions::assert_eq; use std::path::{Path, PathBuf}; use std::process::Command; use std::thread::sleep;