From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/camino/tests/integration_tests.rs | 115 +++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 vendor/camino/tests/integration_tests.rs (limited to 'vendor/camino/tests') diff --git a/vendor/camino/tests/integration_tests.rs b/vendor/camino/tests/integration_tests.rs new file mode 100644 index 000000000..a8b00f2fe --- /dev/null +++ b/vendor/camino/tests/integration_tests.rs @@ -0,0 +1,115 @@ +// Copyright (c) The camino Contributors +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use camino::{Utf8Path, Utf8PathBuf}; +use std::{ + collections::hash_map::DefaultHasher, + hash::{Hash, Hasher}, + path::Path, +}; + +static PATH_CORPUS: &[&str] = &[ + "", + "foo", + "foo/bar", + "foo//bar", + "foo/bar/baz", + "foo/bar/./baz", + "foo/bar/../baz", + "../foo/bar/./../baz", + "/foo", + "/foo/bar", + "/", + "///", + // --- + // Windows-only paths + // --- + #[cfg(windows)] + "foo\\bar", + #[cfg(windows)] + "\\foo\\bar", + #[cfg(windows)] + "C:\\foo", + #[cfg(windows)] + "C:foo\\bar", + #[cfg(windows)] + "C:\\foo\\..\\.\\bar", + #[cfg(windows)] + "\\\\server\\foo\\bar", + #[cfg(windows)] + "\\\\.\\C:\\foo\\bar.txt", +]; + +#[test] +fn test_borrow_eq_ord() { + // Utf8PathBuf implements Borrow so equality and ordering comparisons should + // match. + for (idx, &path1) in PATH_CORPUS.iter().enumerate() { + for &path2 in &PATH_CORPUS[idx..] { + let borrowed1 = Utf8Path::new(path1); + let borrowed2 = Utf8Path::new(path2); + let owned1 = Utf8PathBuf::from(path1); + let owned2 = Utf8PathBuf::from(path2); + + assert_eq!( + borrowed1 == borrowed2, + owned1 == owned2, + "Eq impls match: {} == {}", + borrowed1, + borrowed2 + ); + assert_eq!( + borrowed1.cmp(borrowed2), + owned1.cmp(&owned2), + "Ord impls match: {} and {}", + borrowed1, + borrowed2 + ); + + // Also check against std paths. + let std1 = Path::new(path1); + let std2 = Path::new(path2); + assert_eq!( + borrowed1, std1, + "Eq between Path and Utf8Path: {}", + borrowed1 + ); + assert_eq!( + borrowed1 == borrowed2, + std1 == std2, + "Eq impl matches Path: {} == {}", + borrowed1, + borrowed2 + ); + assert_eq!( + borrowed1.cmp(borrowed2), + std1.cmp(std2), + "Ord impl matches Path: {} and {}", + borrowed1, + borrowed2 + ); + } + } +} + +#[test] +fn test_borrow_hash() { + // Utf8PathBuf implements Borrow so hash comparisons should match. + fn hash_output(x: impl Hash) -> u64 { + let mut hasher = DefaultHasher::new(); + x.hash(&mut hasher); + hasher.finish() + } + + for &path in PATH_CORPUS { + let borrowed = Utf8Path::new(path); + let owned = Utf8PathBuf::from(path); + + assert_eq!( + hash_output(&owned), + hash_output(borrowed), + "consistent Hash: {}", + borrowed + ); + } +} -- cgit v1.2.3