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.
This commit is contained in:
parent
224ce0b19b
commit
eecb6f7476
22 changed files with 91 additions and 54 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -22,3 +22,4 @@ regex = "1.11.1"
|
|||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.13.0"
|
||||
pretty_assertions = "1.4.1"
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ impl Display for Cursor<'_> {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_cursor() {
|
||||
|
|
|
|||
|
|
@ -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::<IdleState>::test_extract_all(&input);
|
||||
|
||||
if actual != expected {
|
||||
dbg!(&input, &actual, &expected);
|
||||
dbg!(&input);
|
||||
}
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ enum Class {
|
|||
mod tests {
|
||||
use super::ArbitraryValueMachine;
|
||||
use crate::extractor::machine::Machine;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -199,6 +199,7 @@ fn drop_covered_spans(mut spans: Vec<Span>) -> Vec<Span> {
|
|||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ enum Class {
|
|||
mod tests {
|
||||
use super::ModifierMachine;
|
||||
use crate::extractor::machine::Machine;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::<IdleState>::test_extract_all(input);
|
||||
if actual != expected {
|
||||
dbg!(&input, &actual, &expected);
|
||||
dbg!(&input);
|
||||
}
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -10,16 +10,16 @@ use std::sync;
|
|||
|
||||
static TEMPLATE_START_REGEX: sync::LazyLock<Regex> = 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<Regex> = 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::<Vec<_>>();
|
||||
let ends = TEMPLATE_END_REGEX.captures_iter(content_as_str).collect::<Vec<_>>();
|
||||
let starts = TEMPLATE_START_REGEX
|
||||
.captures_iter(content_as_str)
|
||||
.collect::<Vec<_>>();
|
||||
let ends = TEMPLATE_END_REGEX
|
||||
.captures_iter(content_as_str)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ enum Class {
|
|||
mod tests {
|
||||
use super::StringMachine;
|
||||
use crate::extractor::machine::Machine;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ enum Class {
|
|||
mod tests {
|
||||
use super::VariantMachine;
|
||||
use crate::extractor::machine::Machine;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -664,6 +664,7 @@ fn create_walker(sources: Sources) -> Option<WalkBuilder> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ChangedContent, Scanner};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_positions() {
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue