1
1
<?php declare (strict_types=1 );
2
2
/**
3
- * @copyright 2023 Roman Parpalak
3
+ * @copyright 2023-2024 Roman Parpalak
4
4
* @license MIT
5
5
*/
6
6
@@ -17,9 +17,9 @@ class StringHelperTest extends Unit
17
17
/**
18
18
* @dataProvider sentenceDataProvider
19
19
*/
20
- public function testSentences (string $ text , array $ sentences ): void
20
+ public function testSentences (string $ text , array $ sentences, bool $ hasFormatting = false ): void
21
21
{
22
- foreach (StringHelper::sentencesFromText ($ text , false ) as $ i => $ str ) {
22
+ foreach (StringHelper::sentencesFromText ($ text , $ hasFormatting ) as $ i => $ str ) {
23
23
$ this ->assertEquals ($ sentences [$ i ], $ str );
24
24
}
25
25
}
@@ -36,6 +36,9 @@ public function sentenceDataProvider(): array
36
36
'1, 2, 3 и т. д. ' ,
37
37
'Цифры, буквы, и т. п., могут встретиться. ' ,
38
38
]],
39
+ ['Sentence \i1. Sentence 2. Sentence\I 3. ' , ['Sentence \i1.\I ' , '\iSentence 2.\I ' , '\iSentence\I 3. ' ], true ],
40
+ ['Sentence \i1. Sentence 2. Sentence\B 3. ' , ['Sentence \i1.\I ' , '\iSentence 2.\I ' , '\b\iSentence\B 3.\I ' ], true ],
41
+ ['\i\uSentence \b1\B. Sentence 2. Sentence 3.\U\I ' , ['\i\uSentence \b1\B.\U\I ' , '\i\uSentence 2.\U\I ' , '\i\uSentence 3.\U\I ' ], true ],
39
42
[
40
43
'Поезд отправился из пункта А в пункт Б. Затем вернулся назад. ' ,
41
44
[
@@ -97,13 +100,49 @@ public function sentenceDataProvider(): array
97
100
];
98
101
}
99
102
100
- public function testFixUnbalancedInternalFormatting (): void
103
+ /**
104
+ * @dataProvider unbalancedInternalFormattingDataProvider
105
+ */
106
+ public function testFixUnbalancedInternalFormatting (string $ text , string $ expected , array $ expectedTags ): void
107
+ {
108
+ $ tags = [];
109
+ $ this ->assertEquals ($ expected , StringHelper::fixUnbalancedInternalFormatting ($ text , $ tags ));
110
+ $ this ->assertEquals ($ expectedTags , $ tags );
111
+ }
112
+
113
+ public function unbalancedInternalFormattingDataProvider (): array
101
114
{
102
- $ this ->assertEquals ('\\iThis is \\bformatted text \\I with \\Bspecial characters \\i. \\I ' , StringHelper::fixUnbalancedInternalFormatting ('\\iThis is \\bformatted text \\I with \\Bspecial characters \\i. ' ));
103
- $ this ->assertEquals ('' , StringHelper::fixUnbalancedInternalFormatting ('' ));
104
- $ this ->assertEquals ('456789i ' , StringHelper::fixUnbalancedInternalFormatting ('456789i ' ));
105
- $ this ->assertEquals ('\\i456789 \\I ' , StringHelper::fixUnbalancedInternalFormatting ('456789 \\I ' ));
106
- $ this ->assertEquals ('\\u456789 \\U ' , StringHelper::fixUnbalancedInternalFormatting ('\\u456789 ' ));
107
- $ this ->assertEquals ('\\i \\d \\u \\D \\\\I \\b \\B \\U ' , StringHelper::fixUnbalancedInternalFormatting ('\\u \\D \\\\I \\b ' ));
115
+ return [
116
+ [
117
+ '\\iThis is \\bformatted text \\I with \\Bspecial characters \\i. ' ,
118
+ '\\iThis is \\bformatted text \\I with \\Bspecial characters \\i. \\I ' ,
119
+ ['i ' => 1 , 'b ' => 0 ],
120
+ ],
121
+ [
122
+ '' ,
123
+ '' ,
124
+ [],
125
+ ],
126
+ [
127
+ '456789i ' ,
128
+ '456789i ' ,
129
+ [],
130
+ ],
131
+ [
132
+ '456789 \\I ' ,
133
+ '\\i456789 \\I ' ,
134
+ ['i ' => -1 ],
135
+ ],
136
+ [
137
+ '\\u456789 ' ,
138
+ '\\u456789 \\U ' ,
139
+ ['u ' => 1 ],
140
+ ],
141
+ [
142
+ '\\u \\D \\\\I \\b ' ,
143
+ '\\i \\d \\u \\D \\\\I \\b \\B \\U ' ,
144
+ ['i ' => -1 , 'd ' => -1 , 'u ' => 1 , 'b ' => 1 ],
145
+ ],
146
+ ];
108
147
}
109
148
}
0 commit comments