mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 12:45:05 +00:00
Remove old garbage code
This commit is contained in:
@@ -1,57 +1,5 @@
|
||||
use std::env::current_dir;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
/// Converts a path to a 'route', used as the paths in Rojo.
|
||||
pub fn path_to_route<A, B>(root: A, value: B) -> Option<Vec<String>>
|
||||
where
|
||||
A: AsRef<Path>,
|
||||
B: AsRef<Path>,
|
||||
{
|
||||
let root = root.as_ref();
|
||||
let value = value.as_ref();
|
||||
|
||||
let relative = match value.strip_prefix(root) {
|
||||
Ok(v) => v,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let result = relative
|
||||
.components()
|
||||
.map(|component| {
|
||||
component.as_os_str().to_string_lossy().into_owned()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Some(result)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_to_route() {
|
||||
fn t(root: &Path, value: &Path, result: Option<Vec<String>>) {
|
||||
assert_eq!(path_to_route(root, value), result);
|
||||
}
|
||||
|
||||
t(
|
||||
Path::new("/a/b/c"),
|
||||
Path::new("/a/b/c/d"),
|
||||
Some(vec!["d".to_string()]),
|
||||
);
|
||||
t(Path::new("/a/b"), Path::new("a"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "windows")]
|
||||
fn test_path_to_route_windows() {
|
||||
fn t(root: &Path, value: &Path, result: Option<Vec<String>>) {
|
||||
assert_eq!(path_to_route(root, value), result);
|
||||
}
|
||||
|
||||
t(
|
||||
Path::new("C:\\foo"),
|
||||
Path::new("C:\\foo\\bar\\baz"),
|
||||
Some(vec!["bar".to_string(), "baz".to_string()]),
|
||||
);
|
||||
}
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Turns the path into an absolute one, using the current working directory if
|
||||
/// necessary.
|
||||
@@ -63,7 +11,7 @@ pub fn canonicalish<T: AsRef<Path>>(value: T) -> PathBuf {
|
||||
|
||||
/// Converts the given path to be absolute if it isn't already using a given
|
||||
/// root.
|
||||
pub fn absoluteify<A, B>(root: A, value: B) -> PathBuf
|
||||
fn absoluteify<A, B>(root: A, value: B) -> PathBuf
|
||||
where
|
||||
A: AsRef<Path>,
|
||||
B: AsRef<Path>,
|
||||
@@ -77,44 +25,3 @@ where
|
||||
root.join(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Collapses any `.` values along with any `..` values not at the start of the
|
||||
/// path.
|
||||
pub fn collapse<T: AsRef<Path>>(value: T) -> PathBuf {
|
||||
let value = value.as_ref();
|
||||
|
||||
let mut buffer = Vec::new();
|
||||
|
||||
for component in value.components() {
|
||||
match component {
|
||||
Component::ParentDir => match buffer.pop() {
|
||||
Some(_) => {},
|
||||
None => buffer.push(component.as_os_str()),
|
||||
},
|
||||
Component::CurDir => {},
|
||||
_ => {
|
||||
buffer.push(component.as_os_str());
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
buffer.iter().fold(PathBuf::new(), |mut acc, &x| {
|
||||
acc.push(x);
|
||||
acc
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collapse() {
|
||||
fn identity(buf: PathBuf) {
|
||||
assert_eq!(buf, collapse(&buf));
|
||||
}
|
||||
|
||||
identity(PathBuf::from("C:\\foo\\bar"));
|
||||
identity(PathBuf::from("/a/b/c"));
|
||||
identity(PathBuf::from("a/b"));
|
||||
|
||||
assert_eq!(collapse(PathBuf::from("a/b/..")), PathBuf::from("a"));
|
||||
assert_eq!(collapse(PathBuf::from("./a/b/c/..")), PathBuf::from("a/b"));
|
||||
assert_eq!(collapse(PathBuf::from("../a")), PathBuf::from("../a"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user