Source for file utf8_position.test.php

Documentation is available at utf8_position.test.php

  1. <?php
  2. /**
  3. @version $Id: utf8_position.test.php,v 1.1 2007/09/09 20:39:50 pitlinz Exp $
  4. @package utf8
  5. @subpackage Tests
  6. */
  7.  
  8. //--------------------------------------------------------------------
  9. /**
  10. * Includes
  11. @package utf8
  12. @subpackage Tests
  13. */
  14. require_once(dirname(__FILE__).'/../config.php');
  15. require_once UTF8 '/utils/position.php';
  16.  
  17. //--------------------------------------------------------------------
  18. /**
  19. @package utf8
  20. @subpackage Tests
  21. */
  22. class test_utf8_position extends UnitTestCase {
  23.     
  24.     function test_ascii_char_to_byte({
  25.         $str 'testing';
  26.         $this->assertIdentical(utf8_byte_position($str3)3);
  27.         $this->assertIdentical(utf8_byte_position($str34)array(3,4));
  28.         $this->assertIdentical(utf8_byte_position($str-1)0);
  29.         $this->assertIdentical(utf8_byte_position($str8)7);
  30.     }
  31.     
  32.     function test_multibyte_char_to_byte({
  33.         $str 'Iñtërnâtiônàlizætiøn';
  34.         $this->assertIdentical(utf8_byte_position($str3)4);
  35.         $this->assertIdentical(utf8_byte_position($str35)array(4,7));
  36.         $this->assertIdentical(utf8_byte_position($str-1)0);
  37.         $this->assertIdentical(utf8_byte_position($str28)27);
  38.     }
  39.     
  40.     // tests for utf8_locate_current_chr & utf8_locate_next_chr
  41.     function test_singlebyte(){
  42.         $tests   array();
  43.         
  44.         // single byte, should return current index
  45.         $tests[array('aaживπά우리をあöä',0,0);
  46.         $tests[array('aaживπά우리をあöä',1,1);
  47.         
  48.         foreach($tests as $test){
  49.             $this->assertIdentical(utf8_locate_current_chr($test[0],$test[1]),$test[2]);
  50.         }
  51.         
  52.         $tests   array();
  53.         $tests[array('aaживπά우리をあöä',1,1);
  54.         
  55.         foreach($tests as $test){
  56.             $this->assertIdentical(utf8_locate_next_chr($test[0],$test[1]),$test[2]);
  57.         }
  58.         
  59.     }
  60.     
  61.     function test_twobyte(){
  62.         // two byte, should move to boundary, expect even number
  63.         $tests   array();
  64.         $tests[array('aaживπά우리をあöä',2,2);
  65.         $tests[array('aaживπά우리をあöä',3,2);
  66.         $tests[array('aaживπά우리をあöä',4,4);
  67.         
  68.         foreach($tests as $test){
  69.             $this->assertIdentical(utf8_locate_current_chr($test[0],$test[1]),$test[2]);
  70.         }
  71.         
  72.         $tests   array();
  73.         $tests[array('aaживπά우리をあöä',2,2);
  74.         $tests[array('aaживπά우리をあöä',3,4);
  75.         $tests[array('aaживπά우리をあöä',4,4);
  76.         
  77.         foreach($tests as $test){
  78.             $this->assertIdentical(utf8_locate_next_chr($test[0],$test[1]),$test[2]);
  79.         }
  80.     }
  81.  
  82.     function test_threebyte(){
  83.         // three byte, should move to boundary 10 or 13
  84.         $tests   array();
  85.         $tests[array('aaживπά우리をあöä',10,10);
  86.         $tests[array('aaживπά우리をあöä',11,10);
  87.         $tests[array('aaживπά우리をあöä',12,10);
  88.         $tests[array('aaживπά우리をあöä',13,13);
  89.         
  90.         foreach($tests as $test){
  91.             $this->assertIdentical(utf8_locate_current_chr($test[0],$test[1]),$test[2]);
  92.         }
  93.         
  94.         $tests   array();
  95.         $tests[array('aaживπά우리をあöä',10,10);
  96.         $tests[array('aaживπά우리をあöä',11,13);
  97.         $tests[array('aaживπά우리をあöä',12,13);
  98.         $tests[array('aaживπά우리をあöä',13,13);
  99.         
  100.         foreach($tests as $test){
  101.             $this->assertIdentical(utf8_locate_next_chr($test[0],$test[1]),$test[2]);
  102.         }
  103.     }
  104.  
  105.     function test_bounds(){
  106.         // bounds checking
  107.         $tests   array();
  108.         $tests[array('aaживπά우리をあöä',-2,0);
  109.         $tests[array('aaживπά우리をあöä',128,29);
  110.         
  111.         foreach($tests as $test){
  112.             $this->assertIdentical(utf8_locate_current_chr($test[0],$test[1]),$test[2]);
  113.         }
  114.         
  115.         $tests[array('aaживπά우리をあöä',-2,0);
  116.         $tests[array('aaживπά우리をあöä',128,29);
  117.         
  118.         foreach($tests as $test){
  119.             $this->assertIdentical(utf8_locate_next_chr($test[0],$test[1]),$test[2]);
  120.         }
  121.     }
  122.     
  123.     
  124. }
  125.  
  126. //--------------------------------------------------------------------
  127. /**
  128. @package utf8
  129. @subpackage Tests
  130. */
  131. if (!defined('TEST_RUNNING')) {
  132.     define('TEST_RUNNING'true);
  133.     $test &new test_utf8_position();
  134.     $reporter getTestReporter();
  135.     $test->run($reporter);
  136. }

Documentation generated on Thu, 08 Jan 2009 17:49:16 +0100 by phpDocumentor 1.4.0a2