mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-16 09:17:09 +00:00
Use slicing instead of future slice_last
This commit is contained in:
parent
e8ea96ee86
commit
7f53da73b7
21
src/file.rs
21
src/file.rs
@ -174,16 +174,15 @@ impl<'dir> File<'dir> {
|
|||||||
let components: Vec<Component> = self.path.components().collect();
|
let components: Vec<Component> = self.path.components().collect();
|
||||||
let mut path_prefix = String::new();
|
let mut path_prefix = String::new();
|
||||||
|
|
||||||
if let Some((_, components_init)) = components.split_last() {
|
// This slicing is safe as components always has the RootComponent
|
||||||
for component in components_init.iter() {
|
// as the first element.
|
||||||
|
for component in components[..(components.len() - 1)].iter() {
|
||||||
path_prefix.push_str(&*component.as_os_str().to_string_lossy());
|
path_prefix.push_str(&*component.as_os_str().to_string_lossy());
|
||||||
|
|
||||||
if component != &Component::RootDir {
|
if component != &Component::RootDir {
|
||||||
path_prefix.push_str("/");
|
path_prefix.push_str("/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
path_prefix
|
path_prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,6 +515,8 @@ pub mod fields {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::ext;
|
use super::ext;
|
||||||
|
use super::File;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn extension() {
|
fn extension() {
|
||||||
@ -531,4 +532,16 @@ mod test {
|
|||||||
fn no_extension() {
|
fn no_extension() {
|
||||||
assert_eq!(None, ext("jarlsberg"))
|
assert_eq!(None, ext("jarlsberg"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_no_prefix() {
|
||||||
|
let f = File::from_path(Path::new("Cargo.toml"), None).unwrap();
|
||||||
|
assert_eq!("", f.path_prefix());
|
||||||
|
let f2 = File::from_path(Path::new("src/main.rs"), None).unwrap();
|
||||||
|
assert_eq!("src/", f2.path_prefix());
|
||||||
|
let f3 = File::from_path(Path::new("src"), None).unwrap();
|
||||||
|
assert_eq!("", f3.path_prefix());
|
||||||
|
let f4 = File::from_path(Path::new("/"), None).unwrap();
|
||||||
|
assert_eq!("", f4.path_prefix());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user