Debian Codegraph @

lib/php/test/Unit/Lib/StringFunc/MbStringTest.php

raw
1 <?php
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 */
22
23 namespace Test\Thrift\Unit\Lib\StringFunc;
24
25 use PHPUnit\Framework\TestCase;
26 use Thrift\StringFunc\Mbstring;
27
28 class MbStringTest extends TestCase
29 {
30 /**
31 * @dataProvider substrDataProvider
32 */
33 public function testSubstr(
34 $expected,
35 $str,
36 $start = 0,
37 $length = null
38 ) {
39 $core = new Mbstring();
40 $this->assertEquals($expected, $core->substr($str, $start, $length));
41 }
42
43 /**
44 * @dataProvider strlenDataProvider
45 */
46 public function testStrlen(
47 $expectedLength,
48 $str
49 ) {
50 $core = new Mbstring();
51 $this->assertEquals($expectedLength, $core->strlen($str));
52 }
53
54 public function substrDataProvider()
55 {
56 yield 'Afrikaans' => [
57 'expected' => 'Afrikaans',
58 'str' => 'Afrikaans',
59 ];
60 yield 'Alemannisch' => [
61 'expected' => 'Alemannisch',
62 'str' => 'Alemannisch',
63 ];
64 yield 'Aragonés' => [
65 'expected' => 'Aragonés',
66 'str' => 'Aragonés',
67 ];
68 yield 'العربية' => [
69 'expected' => 'العربية',
70 'str' => 'العربية',
71 ];
72 yield 'مصرى' => [
73 'expected' => 'مصرى',
74 'str' => 'مصرى',
75 ];
76 yield 'മലയാളം' => [
77 'expected' => 'മലയാളം',
78 'str' => 'മലയാളം',
79 ];
80 yield 'Slovenščina' => [
81 'expected' => 'Slovenščina',
82 'str' => 'Slovenščina',
83 ];
84 yield 'Українська' => [
85 'expected' => 'Українська',
86 'str' => 'Українська',
87 ];
88 yield 'اردو' => [
89 'expected' => 'اردو',
90 'str' => 'اردو',
91 ];
92 yield '中文' => [
93 'expected' => '中文',
94 'str' => '中文',
95 ];
96 yield '粵語' => [
97 'expected' => '粵語',
98 'str' => '粵語',
99 ];
100 yield 'Afrikaans_SUB' => [
101 'expected' => 'rikaan',
102 'str' => 'Afrikaans',
103 'start' => 2,
104 'length' => 6,
105 ];
106 yield 'Alemannisch_SUB' => [
107 'expected' => 'emanni',
108 'str' => 'Alemannisch',
109 'start' => 2,
110 'length' => 6,
111 ];
112 yield 'Aragonés_SUB' => [
113 'expected' => 'agoné',
114 'str' => 'Aragonés',
115 'start' => 2,
116 'length' => 6,
117 ];
118 yield 'العربية_SUB' => [
119 'expected' => 'لعر',
120 'str' => 'العربية',
121 'start' => 2,
122 'length' => 6,
123 ];
124 yield 'مصرى_SUB' => [
125 'expected' => 'صرى',
126 'str' => 'مصرى',
127 'start' => 2,
128 'length' => 6,
129 ];
130 yield 'മലയാളം_SUB' => [
131 'expected' => 'ലയ',
132 'str' => 'മലയാളം',
133 'start' => 3,
134 'length' => 6,
135 ];
136 yield 'Slovenščina_SUB' => [
137 'expected' => 'ovenš',
138 'str' => 'Slovenščina',
139 'start' => 2,
140 'length' => 6,
141 ];
142 yield 'Українська_SUB' => [
143 'expected' => 'кра',
144 'str' => 'Українська',
145 'start' => 2,
146 'length' => 6,
147 ];
148 yield 'اردو_SUB' => [
149 'expected' => 'ردو',
150 'str' => 'اردو',
151 'start' => 2,
152 'length' => 6,
153 ];
154 yield '中文_SUB' => [
155 'expected' => '文',
156 'str' => '中文',
157 'start' => 3,
158 'length' => 3,
159 ];
160 yield '粵語_SUB' => [
161 'expected' => '語',
162 'str' => '粵語',
163 'start' => 3,
164 'length' => 3,
165 ];
166 }
167
168 public function strlenDataProvider()
169 {
170 yield 'Afrikaans' => [
171 'expectedLength' => 9,
172 'str' => 'Afrikaans',
173 ];
174 yield 'Alemannisch' => [
175 'expectedLength' => 11,
176 'str' => 'Alemannisch',
177 ];
178 yield 'Aragonés' => [
179 'expectedLength' => 9,
180 'str' => 'Aragonés',
181 ];
182 yield 'العربية' => [
183 'expectedLength' => 14,
184 'str' => 'العربية',
185 ];
186 yield 'مصرى' => [
187 'expectedLength' => 8,
188 'str' => 'مصرى',
189 ];
190 yield 'മലയാളം' => [
191 'expectedLength' => 18,
192 'str' => 'മലയാളം',
193 ];
194 yield 'Slovenščina' => [
195 'expectedLength' => 13,
196 'str' => 'Slovenščina',
197 ];
198 yield 'Українська' => [
199 'expectedLength' => 20,
200 'str' => 'Українська',
201 ];
202 yield 'اردو' => [
203 'expectedLength' => 8,
204 'str' => 'اردو',
205 ];
206 yield '中文' => [
207 'expectedLength' => 6,
208 'str' => '中文',
209 ];
210 yield '粵語' => [
211 'expectedLength' => 6,
212 'str' => '粵語',
213 ];
214 }
215 }