2021-03-24 10:53:12 +01:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
$dirname_file = dirname(__FILE__);
|
2021-04-02 21:00:09 +02:00
|
|
|
require_once "$dirname_file/../lib-htmgem.inc.php";
|
2021-03-24 10:53:12 +01:00
|
|
|
require_once "$dirname_file/utils.inc.php";
|
2021-04-04 21:16:01 +02:00
|
|
|
require_once "$dirname_file/../lib-io.inc.php";
|
2021-03-24 10:53:12 +01:00
|
|
|
|
|
|
|
function translate($text): string {
|
|
|
|
return strval(new htmgem\GemtextTranslate_gemtext($text));
|
|
|
|
}
|
|
|
|
|
|
|
|
final class translateToGemtextTest extends TestCase {
|
|
|
|
|
|
|
|
public function test_translate_gemtext_smallTextSets(): void {
|
|
|
|
$line1 = " Hello, how are you? ";
|
|
|
|
$line2 = " Nice to meet you! ";
|
|
|
|
$rline1 = rtrim($line1);
|
|
|
|
$rline2 = rtrim($line2);
|
|
|
|
$this->assertSame(
|
|
|
|
"",
|
|
|
|
translate(null),
|
|
|
|
"Null line"
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
"",
|
|
|
|
translate(""),
|
|
|
|
"Empty line"
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
"$rline1\n",
|
|
|
|
translate($line1),
|
|
|
|
"Only one line"
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
"$rline1\n",
|
|
|
|
translate($line1),
|
|
|
|
"Only one line with a line feed"
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
"$rline1\n$rline2\n",
|
|
|
|
translate("$line1\n$line2"),
|
|
|
|
"Two lines, one line feed in between"
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
"$rline1\n$rline2\n",
|
|
|
|
translate("$line1\n$line2"),
|
|
|
|
"Two lines, one line feed after each"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#TODO: don't stop when problems are found, list all the faulty files
|
|
|
|
public function test_translate_gemtext_files(): void {
|
|
|
|
foreach(getGmiFiles(dirname(__FILE__)."/..") as $filePathname) {
|
|
|
|
$fileContent = file_get_contents($filePathname);
|
2021-04-04 21:16:01 +02:00
|
|
|
\htmgem\io\convertToUTF8($fileContent);
|
2021-03-24 10:53:12 +01:00
|
|
|
$this->assertSame(
|
|
|
|
$fileContent,
|
|
|
|
translate($fileContent),
|
|
|
|
"The same file without extra space translated into itself: $filePathname"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|