From 0711824b204d3cbcfa1411e5daf84b516305563e Mon Sep 17 00:00:00 2001 From: tswicegood Date: Sat, 9 Aug 2008 18:19:39 +0000 Subject: [PATCH] standardize EOLs to output diffs properly on Windows git-svn-id: https://svn.phpt.info/Core/trunk@709 54d25d7b-d40e-47af-a99d-8d4037bc02b6 --- src/PHPT/Util/Diff.php | 10 ++++++++-- tests/Util/Diff/standardizes-eols.phpt | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/Util/Diff/standardizes-eols.phpt diff --git a/src/PHPT/Util/Diff.php b/src/PHPT/Util/Diff.php index e3fa7f7..e96bf8c 100644 --- a/src/PHPT/Util/Diff.php +++ b/src/PHPT/Util/Diff.php @@ -13,8 +13,9 @@ class PHPT_Util_Diff if ($this->_invalidString($actual)) { throw new PHPT_Util_Diff_InvalidParameter('actual'); } - $this->_wanted = explode(PHP_EOL, $wanted); - $this->_actual = explode(PHP_EOL, $actual); + $standardize_eol = array($this, '_standardizeEol'); + $this->_wanted = array_map($standardize_eol, explode("\n", $wanted)); + $this->_actual = array_map($standardize_eol, explode("\n", $actual)); } public function __toString() @@ -48,6 +49,11 @@ class PHPT_Util_Diff return implode(PHP_EOL, $return); } + private function _standardizeEol($value) + { + return rtrim($value, "\r"); + } + private function _cheapComparison() { return strcmp(serialize($this->_wanted), serialize($this->_actual)) === 0; diff --git a/tests/Util/Diff/standardizes-eols.phpt b/tests/Util/Diff/standardizes-eols.phpt new file mode 100644 index 0000000..9e5de57 --- /dev/null +++ b/tests/Util/Diff/standardizes-eols.phpt @@ -0,0 +1,18 @@ +--TEST-- +All \n and \r\n markers are standardized to whatever PHP_EOL is +--FILE-- + +===DONE=== +--EXPECT-- +===DONE=== + + -- 2.11.4.GIT