-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
integration.rs
83 lines (66 loc) · 1.83 KB
/
integration.rs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use std::convert::TryInto;
use std::env;
use std::fs::File;
use std::io;
use std::path::Path;
use normpath::BasePath;
use normpath::PathExt;
use tempfile::tempdir;
#[macro_use]
mod common;
#[cfg(windows)]
#[rustfmt::skip]
use windows_sys::Win32::Foundation::ERROR_INVALID_NAME;
#[cfg(not(windows))]
use libc::ENOENT as ERROR_INVALID_NAME;
#[test]
fn test_empty() -> io::Result<()> {
assert_eq!(
Some(Ok(ERROR_INVALID_NAME)),
common::normalize("")
.unwrap_err()
.raw_os_error()
.map(TryInto::try_into),
);
assert_eq!(
io::ErrorKind::NotFound,
Path::new("").normalize().unwrap_err().kind(),
);
let base = env::current_dir()?;
assert_eq!(&base, &BasePath::try_new(&base).unwrap().join(""));
Ok(())
}
#[test]
fn test_created() -> io::Result<()> {
let dir = tempdir()?;
let dir = dir.path().normalize().unwrap();
let file = dir.as_path().join("foo");
let _ = File::create(&file)?;
assert_eq!(file, dir.join("foo"));
common::assert_eq(&file, file.normalize());
Ok(())
}
#[cfg(feature = "serde")]
#[test]
fn test_serde() -> io::Result<()> {
use normpath::BasePathBuf;
// https://doc.rust-lang.org/std/ffi/struct.OsStr.html#examples-2
let path = {
#[cfg(windows)]
{
use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt;
OsString::from_wide(&[0x66, 0x66, 0xD800, 0x6F])
}
#[cfg(not(windows))]
{
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
OsStr::from_bytes(&[0x66, 0x66, 0x80, 0x6F]).to_owned()
}
};
let base = BasePathBuf::new(path)?;
let bytes = bincode::serialize(&base).unwrap();
assert_eq!(base, bincode::deserialize::<BasePathBuf>(&bytes).unwrap());
Ok(())
}