Skip to content

Commit 2ce76ac

Browse files
committed
Add: Test for color output
1 parent c903699 commit 2ce76ac

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

tests/Diff/Renderer/Text/TextRenderersTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ public function testUnifiedCli(): void
104104
$this->assertStringEqualsFile('tests/resources/textUnifiedCli.txt', $result);
105105
}
106106

107+
/**
108+
* Test the output of the CLI Unified renderer with colors.
109+
*
110+
* @covers \jblond\Diff\Renderer\Text\UnifiedCli
111+
*/
112+
public function testUnifiedCliColorOption(): void
113+
{
114+
$diff = new Diff(
115+
file_get_contents('tests/resources/a.txt'),
116+
file_get_contents('tests/resources/b.txt')
117+
);
118+
119+
$renderer = new Diff\Renderer\Text\UnifiedCli(['cliColor' => true]);
120+
$result = $diff->render($renderer);
121+
if ($this->genOutputFiles) {
122+
file_put_contents('textUnifiedCliColor.txt', $result);
123+
}
124+
$this->assertStringEqualsFile('tests/resources/textUnifiedCliColor.txt', $result);
125+
}
126+
107127
/**
108128
* Test the output of the CLI text-inline renderer.
109129
*
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@@ -1,22 +1,22 @@
2+
 <html>
3+
<head>
4+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5+
- <title>Hello World!</title>
6+
+ <title>Hello You!</title>
7+
 </head>
8+
<body>
9+
<h1>This is demo content to show features of the php-diff package.</h1>
10+
- <h2>This line is removed from version2.</h2>
11+
 <h2>This line is the same for both versions.</h2>
12+
- <h2>this line has inline differences between both versions.</h2>
13+
+ <h2>This line has differences between both versions.</h2>
14+
 <h2>This line is the same for both versions.</h2>
15+
- <h2>This line also has inline differences between both versions.</h2>
16+
+ <h2>This line also has InLine differences between both versions.</h2>
17+
 <h2>This line is the same for both versions.</h2>
18+
+ <h2>This line is added to version2.</h2>
19+

20+
<p>
21+
It's also compatible with multibyte characters (like Chinese and emoji) as shown below:
22+
- 另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
23+
- Do you know what "金槍魚罐頭" means in Chinese?
24+
- 🍏🍎🙂
25+
+ 另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
26+
+ Do you know what "魚の缶詰" means in Chinese?
27+
+ 🍎🍏🙂
28+
 </p>
29+
30+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
31+
@@ -25,9 +25,9 @@
32+
 <p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
33+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
34+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
35+
- <h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
36+
+ <h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
37+
 <h2>This line is the same for both versions.</h2>
38+
- <h2>This line also has inline differences between both versions.</h2>
39+
+ <h2>This line also has inline differences between both versions!</h2>
40+
 </body>
41+
</html>
42+
43+


0 commit comments

Comments
 (0)