blob: 0d7a01028267d9685f26a82f3871e265f74c1d33 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
use std::path::{Path, PathBuf};
#[derive(Debug)]
pub enum NormalizeError {
EmptyInput,
}
pub fn normalize_path(
_root: &Path,
_origin: &Path,
input: &Path,
) -> Result<PathBuf, NormalizeError> {
if input.as_os_str().is_empty() {
return Err(NormalizeError::EmptyInput);
}
Ok(input.to_path_buf())
}
#[cfg(test)]
mod tests {
use std::path::Path;
use super::{NormalizeError, normalize_path};
#[test]
fn empty_path_returns_error() {
let root = Path::new("/project");
let origin_dir = Path::new("/project");
let input = Path::new("");
let result = normalize_path(root, origin_dir, input);
assert!(matches!(result, Err(NormalizeError::EmptyInput)));
}
#[test]
fn plain_filename_with_root_at_cwd_returns_filename() {
let root = Path::new("/project");
let origin_dir = Path::new("/project");
let input = Path::new("main.rs");
let result = normalize_path(root, origin_dir, input);
assert!(result.is_ok());
assert_eq!(result.unwrap(), Path::new("main.rs"));
}
}
|