Fix tests
This commit is contained in:
parent
b86a3e1b53
commit
217c752581
1 changed files with 18 additions and 22 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
@ -106,34 +107,29 @@ impl Common {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prettier_windows_path(path_to_change: &Path) -> PathBuf {
|
pub fn prettier_windows_path(path_to_change: impl AsRef<Path>) -> PathBuf {
|
||||||
use std::path::{Component, Prefix};
|
let path = path_to_change.as_ref();
|
||||||
|
match path.to_str() {
|
||||||
let mut new_path = PathBuf::new();
|
Some(path) if path.is_char_boundary(1) => {
|
||||||
for component in path_to_change.components() {
|
let replaced = path.replace('\\', "/");
|
||||||
match component {
|
let mut new_path = OsString::new();
|
||||||
Component::Prefix(prefix) => match prefix.kind() {
|
if replaced[1..].starts_with(':') {
|
||||||
Prefix::Disk(letter) => {
|
new_path.push(replaced[..1].to_ascii_uppercase());
|
||||||
let drive = format!("{}:", letter.to_ascii_uppercase() as char);
|
new_path.push(replaced[1..].to_ascii_lowercase());
|
||||||
new_path.push(drive);
|
} else {
|
||||||
}
|
new_path.push(replaced);
|
||||||
_ => {
|
|
||||||
new_path.push(component);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
other => {
|
|
||||||
new_path.push(other);
|
|
||||||
}
|
}
|
||||||
|
PathBuf::from(new_path)
|
||||||
}
|
}
|
||||||
|
_ => path.to_path_buf(),
|
||||||
}
|
}
|
||||||
|
|
||||||
new_path
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::common::Common;
|
use crate::common::Common;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_regex() {
|
fn test_regex() {
|
||||||
|
@ -157,8 +153,8 @@ mod test {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_windows_path() {
|
fn test_windows_path() {
|
||||||
assert_eq!("C:/path.txt", Common::prettier_windows_path(&"c:/PATH.tXt".to_string()));
|
assert_eq!(PathBuf::from("C:/path.txt"), Common::prettier_windows_path("c:/PATH.tXt"));
|
||||||
assert_eq!("H:/reka/weza/roman.txt", Common::prettier_windows_path(&"h:/RekA/Weza\\roMan.Txt".to_string()));
|
assert_eq!(PathBuf::from("H:/reka/weza/roman.txt"), Common::prettier_windows_path("h:/RekA/Weza\\roMan.Txt"));
|
||||||
assert_eq!("T:/a", Common::prettier_windows_path(&"T:\\A".to_string()));
|
assert_eq!(PathBuf::from("T:/a"), Common::prettier_windows_path("T:\\A"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue