diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-20 14:47:31 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-20 15:08:49 +0900 |
| commit | dc43cb1c663378130d727d9cee414a6a37433047 (patch) | |
| tree | 73959dd1b293d42caa45239914d1c22cc67fafa8 | |
| parent | c854041bfca63f39ace6f0c01892e81889f90bb3 (diff) | |
| download | php-shirabe-dc43cb1c663378130d727d9cee414a6a37433047.tar.gz php-shirabe-dc43cb1c663378130d727d9cee414a6a37433047.tar.zst php-shirabe-dc43cb1c663378130d727d9cee414a6a37433047.zip | |
feat(php-shim): implement dirname()
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| -rw-r--r-- | crates/shirabe-php-shim/src/lib.rs | 13 | ||||
| -rw-r--r-- | crates/shirabe/tests/cli.rs | 2 |
2 files changed, 11 insertions, 4 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 609d320..362e20f 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -1053,8 +1053,17 @@ pub fn json_encode<T: serde::Serialize + ?Sized>(_value: &T) -> Option<String> { todo!() } -pub fn dirname(_path: &str) -> String { - todo!() +pub fn dirname(path: &str) -> String { + if path.is_empty() { + return String::new(); + } + match std::path::Path::new(path).parent() { + // No parent: the root itself, or a path made up solely of slashes. + None => "/".to_string(), + // Path::parent yields an empty path where PHP's dirname returns ".". + Some(parent) if parent.as_os_str().is_empty() => ".".to_string(), + Some(parent) => parent.to_str().expect("input was valid UTF-8").to_string(), + } } pub fn stream_get_contents(_stream: PhpMixed) -> Option<String> { diff --git a/crates/shirabe/tests/cli.rs b/crates/shirabe/tests/cli.rs index 196e93b..9fd6470 100644 --- a/crates/shirabe/tests/cli.rs +++ b/crates/shirabe/tests/cli.rs @@ -129,7 +129,6 @@ run_no_panic_tests! { run_audit => "audit", #[ignore = "currently panics"] run_browse => "browse", - #[ignore = "currently panics"] run_bump => "bump", #[ignore = "currently panics"] run_check_platform_reqs => "check-platform-reqs", @@ -182,6 +181,5 @@ run_no_panic_tests! { run_suggests => "suggests", #[ignore = "currently panics"] run_update => "update", - #[ignore = "currently panics"] run_validate => "validate", } |
