[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> utf8_correctidx.test.php (source)

   1  <?php
   2  // use no mbstring help here
   3  if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1);
   4  
   5  class utf8_correctidx_test extends DokuWikiTest {
   6  
   7  
   8      function test_singlebyte(){
   9          // we test multiple cases here - format: in, offset, length, out
  10          $tests   = array();
  11  
  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);
  16  
  17          foreach($tests as $test){
  18              $this->assertEquals(\dokuwiki\Utf8\Clean::correctIdx($test[0],$test[1],$test[2]),$test[3]);
  19          }
  20      }
  21  
  22      function test_twobyte(){
  23          // we test multiple cases here - format: in, offset, length, out
  24          $tests   = array();
  25  
  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);
  30  
  31          $tests[] = array('aaживπά우리をあöä',2,true,2);
  32          $tests[] = array('aaживπά우리をあöä',3,true,4);
  33          $tests[] = array('aaживπά우리をあöä',4,true,4);
  34  
  35          foreach($tests as $test){
  36              $this->assertEquals(\dokuwiki\Utf8\Clean::correctIdx($test[0],$test[1],$test[2]),$test[3]);
  37          }
  38      }
  39  
  40      function test_threebyte(){
  41          // we test multiple cases here - format: in, offset, length, out
  42          $tests   = array();
  43  
  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);
  49  
  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);
  54  
  55          foreach($tests as $test){
  56              $this->assertEquals(\dokuwiki\Utf8\Clean::correctIdx($test[0],$test[1],$test[2]),$test[3]);
  57          }
  58      }
  59  
  60      function test_bounds(){
  61          // we test multiple cases here - format: in, offset, length, out
  62          $tests   = array();
  63  
  64          // bounds checking
  65          $tests[] = array('aaживπά우리をあöä',-2,false,0);
  66          $tests[] = array('aaживπά우리をあöä',128,false,29);
  67  
  68          $tests[] = array('aaживπά우리をあöä',-2,true,0);
  69          $tests[] = array('aaживπά우리をあöä',128,true,29);
  70  
  71          foreach($tests as $test){
  72              $this->assertEquals(\dokuwiki\Utf8\Clean::correctIdx($test[0],$test[1],$test[2]),$test[3]);
  73          }
  74      }
  75  
  76  }
  77  //Setup VIM: ex: et ts=4 :