|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace SlayerBirden\DFCodeGeneration\Util; |
|
5
|
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
final class LexerTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @param string $fullName |
|
12
|
|
|
* @param string $expected |
|
13
|
|
|
* |
|
14
|
|
|
* @dataProvider getNames |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testGetBaseName(string $fullName, string $expected): void |
|
17
|
|
|
{ |
|
18
|
|
|
$this->assertSame($expected, Lexer::getBaseName($fullName)); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function getNames(): array |
|
22
|
|
|
{ |
|
23
|
|
|
return [ |
|
24
|
|
|
['\\', ''], |
|
25
|
|
|
['Something\Else', 'Else'], |
|
26
|
|
|
['Something\Else\\', ''], |
|
27
|
|
|
['\Something\Else', 'Else'], |
|
28
|
|
|
['JustName', 'JustName'], |
|
29
|
|
|
]; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $fullName |
|
34
|
|
|
* @param string $expected |
|
35
|
|
|
* |
|
36
|
|
|
* @dataProvider getRefNames |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testGetRefName(string $fullName, string $expected): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->assertSame($expected, Lexer::getRefName($fullName)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getRefNames(): array |
|
44
|
|
|
{ |
|
45
|
|
|
return [ |
|
46
|
|
|
['\\', ''], |
|
47
|
|
|
['Something\Else', 'else'], |
|
48
|
|
|
['\Something\ElseY', 'else_y'], |
|
49
|
|
|
['JustName', 'just_name'], |
|
50
|
|
|
['Boo\jLib', 'j_lib'], |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $single |
|
56
|
|
|
* @param string $expected |
|
57
|
|
|
* |
|
58
|
|
|
* @dataProvider getNamesForTransform |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testGetPluralForm(string $single, string $expected): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->assertSame($expected, Lexer::getPluralForm($single)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getNamesForTransform(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return [ |
|
68
|
|
|
['cat', 'cats'], |
|
69
|
|
|
['bus', 'buses'], |
|
70
|
|
|
['village', 'villages'], |
|
71
|
|
|
['registry', 'registries'], |
|
72
|
|
|
]; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param string $expected |
|
77
|
|
|
* @param string $plural |
|
78
|
|
|
* |
|
79
|
|
|
* @dataProvider getNamesForTransform |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testGetSingularForm(string $expected, string $plural): void |
|
82
|
|
|
{ |
|
83
|
|
|
$this->assertSame($expected, Lexer::getSingularForm($plural)); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|