Skip to content

Commit 29dca67

Browse files
committed
test: add tests for Word line renderer
Signed-off-by: Jack Cherng <[email protected]>
1 parent 355952f commit 29dca67

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jfcherng\Diff\Test\Renderer\Html\LineRenderer;
6+
7+
use Jfcherng\Diff\Renderer\Html\LineRenderer\Word;
8+
use Jfcherng\Diff\Renderer\RendererConstant;
9+
use Jfcherng\Utility\MbString;
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* Test general methods from the Word.
14+
*
15+
* @coversNothing
16+
*
17+
* @internal
18+
*/
19+
final class WordTest extends TestCase
20+
{
21+
/**
22+
* Test the Word::render can work with "wordGlues".
23+
*
24+
* @covers \Jfcherng\Diff\Renderer\Html\LineRenderer\Word::render
25+
*/
26+
public function testRenderWordGlues1(): void
27+
{
28+
$word = new Word([], ['wordGlues' => [' ', '-']]);
29+
$mbOld = new MbString('good-looking-x');
30+
$mbNew = new MbString('good--y');
31+
32+
$word->render($mbOld, $mbNew);
33+
34+
$oldDiff = \str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_DEL, $mbOld->get());
35+
$newDiff = \str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_INS, $mbNew->get());
36+
37+
static::assertSame('good-<del>looking-x</del>', $oldDiff);
38+
static::assertSame('good-<ins>-y</ins>', $newDiff);
39+
}
40+
41+
/**
42+
* Test the Word::render can work with "wordGlues".
43+
*
44+
* @covers \Jfcherng\Diff\Renderer\Html\LineRenderer\Word::render
45+
*
46+
* @see https://github.com/jfcherng/php-diff/pull/25
47+
*/
48+
public function testRenderWordGlues2(): void
49+
{
50+
$word = new Word([], ['wordGlues' => [' ', '-']]);
51+
$mbOld = new MbString('of the Indo-Euopearn legguanas, Porto-Idno-Eorpuaen, did not have aieltrcs. Msot of the lanaguges in this flamiy do not hvae diiefnte or ieiinfntde atrciels: three is no actirle in Ltain or Ssknarit, nor in some meodrn Indo-Eoeapurn lgagaenus, scuh as the falmeiis of Salvic lnggaeuas (epexct for Bulraiagn and Mneiodaacn, whcih are reahtr dviiittcsne amnog the Saivlc lagauegns in thier gmrmaar), Btialc leaauggns and mnay Indo-Aaryn lgugneaas. Aluogthh Csiacslal Greek had a dtiniefe artlcie (wichh has srivvued itno Modren Gerek and wichh bears snotrg fcaiutonnl raeelmnscbe to the Gramen deiinfte arltcie, whcih it is rtealed to), the erailer Hmeoirc Geerk used this alctrie llrgeay as a prnuoon or dioravsttmnee, wareehs the erlaseit known form of Geerk konwn as Meayenacn Gerek did not have any acrlties. Atilcres dvlpeeoed inleenddpenty in svaeerl lagnauge fmieials. In mnay lagnuegas, the form of the atrlice may vary acdrocnig to the gneedr, nbmuer, or csae of its nuon. In smoe laganegus the artcile may be the only idiaitnocn of the case. Many languages do not utilize articles at all, and may use other ways of denoting old versus incipient information, such as topic comment constructions.');
52+
$mbNew = new MbString('of the Indo-European languages, Proto-Indo-European, did not have articles. Most of the languages in this family do not have definite or indefinite articles: there is no article in Latin or Sanskrit, nor in some modern Indo-European languages, such as the families of Slavic languages (epexct for Bulraiagn and Mneiodaacn, whcih are reahtr dviiittcsne amnog the Saivlc lagauegns in thier gmrmaar), Btialc leaauggns and mnay Indo-Aaryn lgugneaas. Aluogthh Csiacslal Greek had a dtiniefe artlcie (wichh has srivvued itno Modren Gerek and wichh bears snotrg fcaiutonnl raeelmnscbe to the Gramen deiinfte arltcie, whcih it is rtealed to), the erailer Hmeoirc Geerk used this alctrie llrgeay as a prnuoon or dioravsttmnee, wareehs the erlaseit known form of Geerk konwn as Meayenacn Gerek did not have any acrlties. Atilcres dvlpeeoed inleenddpenty in svaeerl lagnauge fmieials. In mnay lagnuegas, the form of the atrlice may vary acdrocnig to the gneedr, nbmuer, or csae of its nuon. In smoe laganegus the artcile may be the only idiaitnocn of the case. Many languages do not utilize articles at all, and may use other ways of denoting old versus incipient information, such as topic comment constructions.');
53+
54+
$word->render($mbOld, $mbNew);
55+
56+
$oldDiff = \str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_DEL, $mbOld->get());
57+
$newDiff = \str_replace(RendererConstant::HTML_CLOSURES, RendererConstant::HTML_CLOSURES_INS, $mbNew->get());
58+
59+
static::assertSame('of the Indo-<del>Euopearn legguanas, Porto-Idno-Eorpuaen, did not have aieltrcs. Msot of the lanaguges in this flamiy do not hvae diiefnte or ieiinfntde atrciels: three is no actirle in Ltain or Ssknarit, nor in some meodrn </del>Indo-<del>Eoeapurn lgagaenus, scuh</del> as the <del>falmeiis of Salvic lnggaeuas</del> (epexct for Bulraiagn and Mneiodaacn, whcih are reahtr dviiittcsne amnog the Saivlc lagauegns in thier gmrmaar), Btialc leaauggns and mnay Indo-Aaryn lgugneaas. Aluogthh Csiacslal Greek had a dtiniefe artlcie (wichh has srivvued itno Modren Gerek and wichh bears snotrg fcaiutonnl raeelmnscbe to the Gramen deiinfte arltcie, whcih it is rtealed to), the erailer Hmeoirc Geerk used this alctrie llrgeay as a prnuoon or dioravsttmnee, wareehs the erlaseit known form of Geerk konwn as Meayenacn Gerek did not have any acrlties. Atilcres dvlpeeoed inleenddpenty in svaeerl lagnauge fmieials. In mnay lagnuegas, the form of the atrlice may vary acdrocnig to the gneedr, nbmuer, or csae of its nuon. In smoe laganegus the artcile may be the only idiaitnocn of the case. Many languages do not utilize articles at all, and may use other ways of denoting old versus incipient information, such as topic comment constructions.', $oldDiff);
60+
static::assertSame('of the Indo-<ins>European languages, Proto-</ins>Indo-<ins>European, did not have articles. Most of the languages in this family do not have definite or indefinite articles: there is no article in Latin or Sanskrit, nor in some modern Indo-European languages, such</ins> as the <ins>families of Slavic languages</ins> (epexct for Bulraiagn and Mneiodaacn, whcih are reahtr dviiittcsne amnog the Saivlc lagauegns in thier gmrmaar), Btialc leaauggns and mnay Indo-Aaryn lgugneaas. Aluogthh Csiacslal Greek had a dtiniefe artlcie (wichh has srivvued itno Modren Gerek and wichh bears snotrg fcaiutonnl raeelmnscbe to the Gramen deiinfte arltcie, whcih it is rtealed to), the erailer Hmeoirc Geerk used this alctrie llrgeay as a prnuoon or dioravsttmnee, wareehs the erlaseit known form of Geerk konwn as Meayenacn Gerek did not have any acrlties. Atilcres dvlpeeoed inleenddpenty in svaeerl lagnauge fmieials. In mnay lagnuegas, the form of the atrlice may vary acdrocnig to the gneedr, nbmuer, or csae of its nuon. In smoe laganegus the artcile may be the only idiaitnocn of the case. Many languages do not utilize articles at all, and may use other ways of denoting old versus incipient information, such as topic comment constructions.', $newDiff);
61+
}
62+
}

0 commit comments

Comments
 (0)