Add tests for splitting Hungarian dates
This commit is contained in:
parent
d56d47aee1
commit
14b0d8037d
|
@ -388,11 +388,11 @@ final class NodaTimeSplitter {
|
||||||
$end = $start;
|
$end = $start;
|
||||||
$start = $startToSet;
|
$start = $startToSet;
|
||||||
}
|
}
|
||||||
return [$start, $end, $output[2], $output[3], '-'];
|
return [$start, $end, $output[2], $output[3], '-', ""];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match("/^[0-9][0-9][0-9][0-9]\-től(\ |\-)[0-9][0-9][0-9][0-9]\-ig$/", $datum)) {
|
if (preg_match("/^[0-9][0-9][0-9][0-9]\-t(ő|ó)l(\ |\-)[0-9][0-9][0-9][0-9]\-ig$/", $datum)) {
|
||||||
$start = substr($datum, 0, 4);
|
$start = substr($datum, 0, 4);
|
||||||
$end = substr($datum, -7, 4);
|
$end = substr($datum, -7, 4);
|
||||||
return [$start, $end, "00", "00", "+", ""];
|
return [$start, $end, "00", "00", "+", ""];
|
||||||
|
|
177
tests/NodaTimeSplitterTest.php
Normal file
177
tests/NodaTimeSplitterTest.php
Normal file
|
@ -0,0 +1,177 @@
|
||||||
|
<?PHP
|
||||||
|
/**
|
||||||
|
* This script contains tests for the home page.
|
||||||
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
|
*/
|
||||||
|
declare(strict_types = 1);
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
require_once __DIR__ . "/../src/NodaTimeSplitter.php";
|
||||||
|
require_once __DIR__ . "/../../MD_STD/MD_STD.php";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for home page.
|
||||||
|
*/
|
||||||
|
final class NodaTimeSplitterTest extends TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to check whether the HTML page is correctly generated.
|
||||||
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
|
* @group ValidOutput
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSplitSimpleDatesHungarian():void {
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("2020.01.02.");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "2020",
|
||||||
|
1 => "2020",
|
||||||
|
2 => "01",
|
||||||
|
3 => "02",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("2020. Januar 2.");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "2020",
|
||||||
|
1 => "2020",
|
||||||
|
2 => "01",
|
||||||
|
3 => "02",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "02.01.2020");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("1920-tól 1929-ig");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "1920",
|
||||||
|
1 => "1929",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("1920-1929 között");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "1920",
|
||||||
|
1 => "1929",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("1920-től 1929-ig");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "1920",
|
||||||
|
1 => "1929",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("1920-es évek");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "1920",
|
||||||
|
1 => "1929",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("2020. Januar");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "2020",
|
||||||
|
1 => "2020",
|
||||||
|
2 => "01",
|
||||||
|
3 => "00",
|
||||||
|
4 => "+",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 2020. Januar");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "-2020",
|
||||||
|
1 => "-2020",
|
||||||
|
2 => "01",
|
||||||
|
3 => "00",
|
||||||
|
4 => "-",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Januar 2020 v. Chr.");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20. század");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "-2000",
|
||||||
|
1 => "-1901",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "-",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1901 v. Chr.");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "-2000",
|
||||||
|
1 => "-1801",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "-",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "2000-1801 v. Chr.");
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század-ig");
|
||||||
|
self::assertEquals($output, [
|
||||||
|
0 => "?",
|
||||||
|
1 => "-1801",
|
||||||
|
2 => "00",
|
||||||
|
3 => "00",
|
||||||
|
4 => "-",
|
||||||
|
5 => "",
|
||||||
|
]);
|
||||||
|
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Bis 1801 v. Chr.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to check whether the HTML page is correctly generated.
|
||||||
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
|
* @group ValidOutput
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSplitDoesNotWorkWhenItShouldNot():void {
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("");
|
||||||
|
self::assertEquals($output, []);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("1.2.2020-2.2.2020");
|
||||||
|
self::assertEquals($output, []);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("2020 Januar 2-2020 Februar 2");
|
||||||
|
self::assertEquals($output, []);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("2020 Januar-2020 Februar");
|
||||||
|
self::assertEquals($output, []);
|
||||||
|
|
||||||
|
$output = NodaTimeSplitter::attempt_splitting("Januar-Februar");
|
||||||
|
self::assertEquals($output, []);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user