Skip to content

Commit

Permalink
some win tests, commented out still
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Mar 14, 2024
1 parent c6a4009 commit 74fdcee
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 19 deletions.
14 changes: 9 additions & 5 deletions crates/backend/src/choose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,9 @@ impl BackendChoice for SupportedBackend {

#[cfg(test)]
mod tests {

use rstest::rstest;

use super::*;
use rstest::rstest;
use std::error::Error;

#[rstest]
#[case("local", SupportedBackend::Local)]
Expand All @@ -213,8 +212,13 @@ mod tests {
#[case("rest", SupportedBackend::Rest)]
#[cfg(feature = "opendal")]
#[case("opendal", SupportedBackend::OpenDAL)]
fn test_try_from_is_ok(#[case] input: &str, #[case] expected: SupportedBackend) {
assert_eq!(SupportedBackend::try_from(input).unwrap(), expected);
fn test_try_from_is_ok(
#[case] input: &str,
#[case] expected: SupportedBackend,
) -> Result<(), Box<dyn Error>> {
assert_eq!(SupportedBackend::try_from(input)?, expected);

Ok(())
}

#[test]
Expand Down
79 changes: 65 additions & 14 deletions crates/core/src/backend/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::str::FromStr;

#[cfg(not(windows))]
use std::fmt::Write;

#[cfg(not(windows))]
use std::os::unix::ffi::OsStrExt;

Expand Down Expand Up @@ -520,18 +521,34 @@ fn take<I: Iterator<Item = char>>(iterator: &mut I, n: usize) -> String {
#[cfg(test)]
mod tests {
use super::*;

use quickcheck_macros::quickcheck;
use rstest::rstest;
use std::error::Error;
// #[cfg(windows)]
// use std::os::windows::prelude::*;

// #[cfg(windows)]
// use std::os::windows::ffi::OsStrExt;
// #[cfg(windows)]
// use std::os::windows::ffi::OsStringExt;

#[quickcheck]
#[allow(clippy::needless_pass_by_value)]
fn escape_unescape_is_identity(bytes: Vec<u8>) -> bool {
let name = OsStr::from_bytes(&bytes);
name == match unescape_filename(&escape_filename(name)) {
Ok(s) => s,
Err(_) => return false,
fn escape_unescape_is_identity(bytes: Vec<u8>) -> Result<bool, Box<dyn Error>> {
#[cfg(not(windows))]
{
let name = OsStr::from_bytes(&bytes);
let res = name == unescape_filename(&escape_filename(name)?)?;
Ok(res)
}

// #[cfg(windows)]
// #[allow(unsafe_code)]
// unsafe {
// let name = OsStr::from_encoded_bytes_unchecked(bytes.as_slice());
// let res = name == unescape_filename(&escape_filename(name)?)?;
// Ok(res)
// }
}

#[rstest]
Expand All @@ -552,9 +569,21 @@ mod tests {
#[case(b"\xc3\x9f", "\u{00df}")]
#[case(b"\xe2\x9d\xa4", "\u{2764}")]
#[case(b"\xf0\x9f\x92\xaf", "\u{01f4af}")]
fn escape_cases(#[case] input: &[u8], #[case] expected: &str) {
let name = OsStr::from_bytes(input);
assert_eq!(expected, escape_filename(name));
fn escape_cases(#[case] input: &[u8], #[case] expected: &str) -> Result<(), Box<dyn Error>> {
#[cfg(not(windows))]
{
let name = OsStr::from_bytes(input);
assert_eq!(expected, escape_filename(name)?);
}

// #[cfg(windows)]
// #[allow(unsafe_code)]
// unsafe {
// let name = OsStr::from_encoded_bytes_unchecked(input);
// assert_eq!(expected, escape_filename(name)?);
// }

Ok(())
}

#[rstest]
Expand All @@ -576,15 +605,37 @@ mod tests {
#[case(r#"\u00DF"#, b"\xc3\x9f")]
#[case(r#"\u2764"#, b"\xe2\x9d\xa4")]
#[case(r#"\U0001f4af"#, b"\xf0\x9f\x92\xaf")]
fn unescape_cases(#[case] input: &str, #[case] expected: &[u8]) {
let expected = OsStr::from_bytes(expected);
assert_eq!(expected, unescape_filename(input).unwrap());
fn unescape_cases(#[case] input: &str, #[case] expected: &[u8]) -> Result<(), Box<dyn Error>> {
#[cfg(not(windows))]
{
let expected = OsStr::from_bytes(expected);
assert_eq!(expected, unescape_filename(input)?);
}

// #[cfg(windows)]
// #[allow(unsafe_code)]
// unsafe {
// let expected = OsStr::from_encoded_bytes_unchecked(expected);
// assert_eq!(expected, unescape_filename(input)?);
// }

Ok(())
}

#[quickcheck]
#[allow(clippy::needless_pass_by_value)]
fn from_link_to_link_is_identity(bytes: Vec<u8>) -> RusticResult<bool> {
let path = Path::new(OsStr::from_bytes(&bytes));
Ok(path == NodeType::from_link(path).to_link()?)
#[cfg(not(windows))]
{
let path = Path::new(OsStr::from_bytes(&bytes));
Ok(path == NodeType::from_link(path).to_link()?)
}

// #[cfg(windows)]
// #[allow(unsafe_code)]
// unsafe {
// let path = Path::new(OsStr::from_encoded_bytes_unchecked(bytes.as_slice()));
// Ok(path == NodeType::from_link(path).to_link()?)
// }
}
}

0 comments on commit 74fdcee

Please sign in to comment.