1<?php 2// use no mbstring help here 3if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1); 4require_once DOKU_INC.'inc/utf8.php'; 5 6class utf8_correctidx_test extends DokuWikiTest { 7 8 9 function test_singlebyte(){ 10 // we test multiple cases here - format: in, offset, length, out 11 $tests = array(); 12 13 // single byte, should return current index 14 $tests[] = array('aaживπά우리をあöä',0,false,0); 15 $tests[] = array('aaживπά우리をあöä',1,false,1); 16 $tests[] = array('aaживπά우리をあöä',1,true,1); 17 18 foreach($tests as $test){ 19 $this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]); 20 } 21 } 22 23 function test_twobyte(){ 24 // we test multiple cases here - format: in, offset, length, out 25 $tests = array(); 26 27 // two byte, should move to boundary, expect even number 28 $tests[] = array('aaживπά우리をあöä',2,false,2); 29 $tests[] = array('aaживπά우리をあöä',3,false,2); 30 $tests[] = array('aaживπά우리をあöä',4,false,4); 31 32 $tests[] = array('aaживπά우리をあöä',2,true,2); 33 $tests[] = array('aaживπά우리をあöä',3,true,4); 34 $tests[] = array('aaживπά우리をあöä',4,true,4); 35 36 foreach($tests as $test){ 37 $this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]); 38 } 39 } 40 41 function test_threebyte(){ 42 // we test multiple cases here - format: in, offset, length, out 43 $tests = array(); 44 45 // three byte, should move to boundary 10 or 13 46 $tests[] = array('aaживπά우리をあöä',10,false,10); 47 $tests[] = array('aaживπά우리をあöä',11,false,10); 48 $tests[] = array('aaживπά우리をあöä',12,false,10); 49 $tests[] = array('aaживπά우리をあöä',13,false,13); 50 51 $tests[] = array('aaживπά우리をあöä',10,true,10); 52 $tests[] = array('aaживπά우리をあöä',11,true,13); 53 $tests[] = array('aaживπά우리をあöä',12,true,13); 54 $tests[] = array('aaживπά우리をあöä',13,true,13); 55 56 foreach($tests as $test){ 57 $this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]); 58 } 59 } 60 61 function test_bounds(){ 62 // we test multiple cases here - format: in, offset, length, out 63 $tests = array(); 64 65 // bounds checking 66 $tests[] = array('aaживπά우리をあöä',-2,false,0); 67 $tests[] = array('aaживπά우리をあöä',128,false,29); 68 69 $tests[] = array('aaживπά우리をあöä',-2,true,0); 70 $tests[] = array('aaживπά우리をあöä',128,true,29); 71 72 foreach($tests as $test){ 73 $this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]); 74 } 75 } 76 77} 78//Setup VIM: ex: et ts=4 : 79