Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

standardize EOLs to output diffs properly on Windows

git-svn-id: https://svn.domain51.com/test/Core/trunk@709 54d25d7b-d40e-47af-a99d-8d4037bc02b6
  • Loading branch information...
commit 5e842f31477141ce13c1f13e3ce08c08b0d47e20 1 parent 827459f
tswicegood authored
Showing with 26 additions and 2 deletions.
  1. +8 −2 src/PHPT/Util/Diff.php
  2. +18 −0 tests/Util/Diff/standardizes-eols.phpt
10 src/PHPT/Util/Diff.php
View
@@ -13,8 +13,9 @@ public function __construct($wanted, $actual)
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 @@ public function __toString()
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;
18 tests/Util/Diff/standardizes-eols.phpt
View
@@ -0,0 +1,18 @@
+--TEST--
+All \n and \r\n markers are standardized to whatever PHP_EOL is
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . '/../../_setup.inc';
+
+$wanted = "foo\r\nbar\r\n";
+$actual = "foo\nbar\n";
+
+assert('(string)new PHPT_Util_Diff($wanted, $actual) === ""');
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.