#[path = "../../../os-vfs-paths/src/lib.rs"] mod paths; #[test] fn os_vfs_paths_components_positive() { let mut state = paths::PathState::new(); let absolute = state.chdir("/veri/çalışma/".as_bytes()).unwrap(); assert_eq!(absolute.depth(), 2); assert_eq!(absolute.component(0), Some("veri")); assert_eq!(absolute.component(1), Some("çalışma")); assert_eq!(absolute.component(2), None); assert_eq!(state.generation, 1); let relative = state.chdir("../örnek/./belge".as_bytes()).unwrap(); assert_eq!(relative.depth(), 3); assert_eq!(relative.component(0), Some("veri")); assert_eq!(relative.component(1), Some("örnek")); assert_eq!(relative.component(2), Some("belge")); assert_eq!(state.cwd, relative); assert_eq!(state.generation, 2); let root = state.resolve(b"/").unwrap(); assert_eq!(root.depth(), 0); assert_eq!(state.cwd, relative); } #[test] fn os_vfs_paths_components_negative() { let mut state = paths::PathState::new(); state.chdir("/sağlam".as_bytes()).unwrap(); let before = state; assert_eq!(state.chdir(&[b'/', 0xff]), Err(paths::Error::InvalidUtf8)); assert_eq!(state, before); let deep = format!("/{}", vec!["x"; paths::MAX_COMPONENTS + 1].join("/")); assert_eq!(state.chdir(deep.as_bytes()), Err(paths::Error::TooDeep)); assert_eq!(state, before); assert_eq!(state.chdir(b"/../no"), Err(paths::Error::AboveRoot)); assert_eq!(state, before); assert_eq!(state.chdir(b"/bad\0name"), Err(paths::Error::InvalidComponent)); assert_eq!(state, before); assert_eq!(state.chdir(&[]), Err(paths::Error::EmptyInput)); assert_eq!(state, before); let long_component = format!("/{}", "x".repeat(paths::MAX_COMPONENT_BYTES + 1)); assert_eq!(state.chdir(long_component.as_bytes()), Err(paths::Error::TooLong)); assert_eq!(state, before); let long_path = vec![b'x'; paths::MAX_PATH_BYTES + 1]; assert_eq!(state.chdir(&long_path), Err(paths::Error::TooLong)); assert_eq!(state, before); }