From ec580ddf8ce561d5b4a6f02aba1a19c95833e9ae Mon Sep 17 00:00:00 2001 From: belliash Date: Wed, 17 Apr 2019 08:32:19 +0200 Subject: [PATCH] Path splitting test. --- tests/path_split.aer | 32 ++++++++++++++++++++++++++++++++ tests/path_split.exp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/path_split.aer create mode 100644 tests/path_split.exp diff --git a/tests/path_split.aer b/tests/path_split.aer new file mode 100644 index 0000000..487115e --- /dev/null +++ b/tests/path_split.aer @@ -0,0 +1,32 @@ +class Program { + + string[] parsePathComponents(string $path, bool $endSlash=true, bool $base=false) { + string[] $retArray; + $path = trim($path); + string $str, $temp; + char $char; + for(int $x = 0; $char = $path[$x]; $x++) { + if(!strstr('/', $char)) $temp += $char; + else if($temp) { + $str += $temp; + $retArray[$temp] = $str + ($endSlash ? '/' : ''); + $str += '/'; + $temp = ''; + } + } + ($base && $temp) ? $retArray[$temp] = $str + $temp : NULL; + return $retArray; + } + + void main() { + string $path = '/my//stupid//path/to///some/file.php'; + print_r($this->parsePathComponents($path)); + + $path = 'my/other//path/'; + print_r($this->parsePathComponents($path, false)); + + $path = '/my//other/path/to///file.php'; + print_r($this->parsePathComponents($path, true, true)); + } + +} diff --git a/tests/path_split.exp b/tests/path_split.exp new file mode 100644 index 0000000..c99eb2a --- /dev/null +++ b/tests/path_split.exp @@ -0,0 +1,32 @@ +Array(5) { + [my] => + my/ + [stupid] => + my/stupid/ + [path] => + my/stupid/path/ + [to] => + my/stupid/path/to/ + [some] => + my/stupid/path/to/some/ + } +Array(3) { + [my] => + my + [other] => + my/other + [path] => + my/other/path + } +Array(5) { + [my] => + my/ + [other] => + my/other/ + [path] => + my/other/path/ + [to] => + my/other/path/to/ + [file.php] => + my/other/path/to/file.php + }