1
0
mirror of https://tildegit.org/sbgodin/HtmGem.git synced 2023-08-25 13:53:12 +02:00
HtmGem/tests/translateToGemtextTest.php

66 lines
1.9 KiB
PHP
Raw Normal View History

2021-03-24 10:53:12 +01:00
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
$dirname_file = dirname(__FILE__);
require_once "$dirname_file/../lib-htmgem.inc.php";
2021-03-24 10:53:12 +01:00
require_once "$dirname_file/utils.inc.php";
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 {
2021-04-04 22:23:38 +02:00
foreach(getFiles(dirname(__FILE__)."/..", "gmi") as $filePathname) {
2021-03-24 10:53:12 +01:00
$fileContent = file_get_contents($filePathname);
\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"
);
}
}
}