Merge pull request #4230 from dokuwiki-translate/lang_update_830_1709550808
[dokuwiki.git] / _test / tests / inc / utf8_correctidx.test.php
blob5a24af737580cac8bec55cd80fcae9779fb1fd29
1 <?php
2 // use no mbstring help here
3 if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1);
5 class utf8_correctidx_test extends DokuWikiTest {
8 function test_singlebyte(){
9 // we test multiple cases here - format: in, offset, length, out
10 $tests = array();
12 // single byte, should return current index
13 $tests[] = array('aaживπά우리をあöä',0,false,0);
14 $tests[] = array('aaживπά우리をあöä',1,false,1);
15 $tests[] = array('aaживπά우리をあöä',1,true,1);
17 foreach($tests as $test){
18 $this->assertEquals(\dokuwiki\Utf8\Clean::correctIdx($test[0],$test[1],$test[2]),$test[3]);
22 function test_twobyte(){
23 // we test multiple cases here - format: in, offset, length, out
24 $tests = array();
26 // two byte, should move to boundary, expect even number
27 $tests[] = array('aaживπά우리をあöä',2,false,2);
28 $tests[] = array('aaживπά우리をあöä',3,false,2);
29 $tests[] = array('aaживπά우리をあöä',4,false,4);
31 $tests[] = array('aaживπά우리をあöä',2,true,2);
32 $tests[] = array('aaживπά우리をあöä',3,true,4);
33 $tests[] = array('aaживπά우리をあöä',4,true,4);
35 foreach($tests as $test){
36 $this->assertEquals(\dokuwiki\Utf8\Clean::correctIdx($test[0],$test[1],$test[2]),$test[3]);
40 function test_threebyte(){
41 // we test multiple cases here - format: in, offset, length, out
42 $tests = array();
44 // three byte, should move to boundary 10 or 13
45 $tests[] = array('aaживπά우리をあöä',10,false,10);
46 $tests[] = array('aaживπά우리をあöä',11,false,10);
47 $tests[] = array('aaживπά우리をあöä',12,false,10);
48 $tests[] = array('aaживπά우리をあöä',13,false,13);
50 $tests[] = array('aaживπά우리をあöä',10,true,10);
51 $tests[] = array('aaживπά우리をあöä',11,true,13);
52 $tests[] = array('aaживπά우리をあöä',12,true,13);
53 $tests[] = array('aaживπά우리をあöä',13,true,13);
55 foreach($tests as $test){
56 $this->assertEquals(\dokuwiki\Utf8\Clean::correctIdx($test[0],$test[1],$test[2]),$test[3]);
60 function test_bounds(){
61 // we test multiple cases here - format: in, offset, length, out
62 $tests = array();
64 // bounds checking
65 $tests[] = array('aaживπά우리をあöä',-2,false,0);
66 $tests[] = array('aaживπά우리をあöä',128,false,29);
68 $tests[] = array('aaживπά우리をあöä',-2,true,0);
69 $tests[] = array('aaживπά우리をあöä',128,true,29);
71 foreach($tests as $test){
72 $this->assertEquals(\dokuwiki\Utf8\Clean::correctIdx($test[0],$test[1],$test[2]),$test[3]);
77 //Setup VIM: ex: et ts=4 :