Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/vfs/src/vfs_path.rs | 4 | ||||
| -rw-r--r-- | crates/vfs/src/vfs_path/tests.rs | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index 7e2c787afc..eb55081c20 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs @@ -337,9 +337,9 @@ impl PartialEq<VfsPath> for AbsPath { struct VirtualPath(String); impl VirtualPath { - /// Returns `true` if `other` is a prefix of `self` (as strings). + /// Returns `true` if `other` is a prefix of `self`. fn starts_with(&self, other: &VirtualPath) -> bool { - self.0.starts_with(&other.0) + <_ as AsRef<paths::Utf8Path>>::as_ref(&self.0).starts_with(&other.0) } fn strip_prefix(&self, base: &VirtualPath) -> Option<&RelPath> { diff --git a/crates/vfs/src/vfs_path/tests.rs b/crates/vfs/src/vfs_path/tests.rs index 2d89362ee0..c21fabfbf0 100644 --- a/crates/vfs/src/vfs_path/tests.rs +++ b/crates/vfs/src/vfs_path/tests.rs @@ -1,6 +1,14 @@ use super::*; #[test] +fn virtual_path_starts_with_is_component_based() { + let path = |path: &str| VfsPath::new_virtual_path(path.to_owned()); + + assert!(!path("/foobar").starts_with(&path("/foo"))); + assert!(path("/foo/bar").starts_with(&path("/foo"))); +} + +#[test] fn virtual_path_extensions() { assert_eq!(VirtualPath("/".to_owned()).name_and_extension(), None); assert_eq!( |