/lib/limb/i18n/tests/cases/charset/lmbMultiByteStringDriverTestBase.class.php

https://github.com/limb-php-framework/limb-app-buildman · PHP · 233 lines · 173 code · 48 blank · 12 comment · 22 complexity · e72d8b210ad0ef0d7ab72a6ca0a33dfb MD5 · raw file

  1. <?php
  2. /**
  3. * Limb Web Application Framework
  4. *
  5. * @link http://limb-project.com
  6. *
  7. * @copyright Copyright &copy; 2004-2007 BIT
  8. * @license LGPL http://www.gnu.org/copyleft/lesser.html
  9. * @version $Id: lmbMultiByteStringDriverTestBase.class.php 4998 2007-02-08 15:36:32Z pachanga $
  10. * @package i18n
  11. */
  12. abstract class lmbMultiByteStringDriverTestBase extends UnitTestCase
  13. {
  14. function & _createDriver() {
  15. return null;
  16. }
  17. function test_substr() {
  18. if(!is_object($driver = $this->_createDriver()))
  19. return;
  20. $this->assertEqual($driver->_substr("это просто тест", 1), "то просто тест");
  21. $this->assertEqual($driver->_substr("ääääσαφ", 0, 400), "ääääσαφ");
  22. $this->assertEqual($driver->_substr("ääääσαφ", 2, 400), "ääσαφ");
  23. $this->assertEqual($driver->_substr("ääääσαφ", 1, 4), "äääσ");
  24. $this->assertEqual($driver->_substr("ääääσαφ", -1), "φ");
  25. $this->assertEqual($driver->_substr("ääääσαφ", 0, -1), "ääääσα");
  26. $this->assertEqual($driver->_substr("ääääσαφ", 1, -1), "äääσα");
  27. }
  28. function test_rtrim() {
  29. if(!is_object($driver = $this->_createDriver()))
  30. return;
  31. $this->assertEqual($driver->_rtrim("τελευτατελ\0\n\n\t"), "τελευτατελ");
  32. $this->assertEqual($driver->_rtrim("τελευτατε?++.*?", ".*?+"), "τελευτατε");
  33. //intervals stuff not working yet, and it's not clear how it should work
  34. //$this->assertEqual($driver->_rtrim("τελευτατε\n\t", "\0x00..\0x1F"), "τελευτατε");
  35. }
  36. function test_ltrim() {
  37. if(!is_object($driver = $this->_createDriver()))
  38. return;
  39. $this->assertEqual($driver->_ltrim("\0\n\n\tτελευτατελ"), "τελευτατελ");
  40. $this->assertEqual($driver->_ltrim("λτελευτατε", "λ"), "τελευτατε");
  41. $this->assertEqual($driver->_ltrim("?+.*+?τελευτατε", "?.*+"), "τελευτατε");
  42. }
  43. function test_trim() {
  44. if(!is_object($driver = $this->_createDriver()))
  45. return;
  46. $this->assertEqual($driver->_trim(" \n\t\0 τελευτατελ\0\n\n\t"), "τελευτατελ");
  47. $this->assertEqual($driver->_trim("pτελεpυτατελp", "p"), "τελεpυτατελ");
  48. $this->assertEqual($driver->_trim("pτελεpυτατελp", "pλ"), "τελεpυτατε");
  49. $this->assertEqual($driver->_trim("?*++?τελευτατε?+.+?", "?.+*"), "τελευτατε");
  50. }
  51. function test_str_replace() {
  52. if(!is_object($driver = $this->_createDriver()))
  53. return;
  54. $this->assertEqual($driver->_str_replace("ελx", "", "τελxευτατελx"),
  55. "τευτατ");
  56. $this->assertEqual($driver->_str_replace("τ", "υ", "τελευτατελ"),
  57. "υελευυαυελ");
  58. $search = array("τ", "υ");
  59. $this->assertEqual($driver->_str_replace($search, "λ", "τελευτατελ"),
  60. "λελελλαλελ");
  61. $replace = array("α", "ε");
  62. $this->assertEqual($driver->_str_replace($search, $replace, "τελευτατελ"),
  63. "αελεεαααελ");
  64. }
  65. function test_strlen() {
  66. if(!is_object($driver = $this->_createDriver()))
  67. return;
  68. $this->assertEqual($driver->_strlen("τελευτατελ"), 10);
  69. $this->assertEqual($driver->_strlen("τ\nελευτα τελ "), 13);
  70. }
  71. function test_strpos() {
  72. if(!is_object($driver = $this->_createDriver()))
  73. return;
  74. $this->assertEqual($driver->_strpos("τελευτατελ", "τατ"), 5);
  75. $this->assertEqual($driver->_strpos("τελευτατελ", "ε"), 1);
  76. $this->assertEqual($driver->_strpos("τελευτατελ", "ε", 2), 3);
  77. }
  78. function test_strrpos() {
  79. if(!is_object($driver = $this->_createDriver()))
  80. return;
  81. $this->assertEqual($driver->_strrpos("τελευτατελ", "τατ"), 5);
  82. $this->assertEqual($driver->_strrpos("τελευτατελ", "ε"), 8);
  83. $this->assertEqual($driver->_strrpos("τελευτατελ", "ε", 3), 8);
  84. }
  85. function test_strtolower() {
  86. if(!is_object($driver = $this->_createDriver()))
  87. return;
  88. $this->assertEqual($driver->_strtolower("ТЕСТ"), "тест");
  89. $this->assertEqual($driver->_strtolower("тЕсТ"), "тест");
  90. }
  91. function test_strtoupper() {
  92. if(!is_object($driver = $this->_createDriver()))
  93. return;
  94. $this->assertEqual($driver->_strtoupper("тест"), "ТЕСТ");
  95. $this->assertEqual($driver->_strtoupper("тЕсТ"), "ТЕСТ");
  96. }
  97. function test_ucfirst() {
  98. if(!is_object($driver = $this->_createDriver()))
  99. return;
  100. $this->assertEqual($driver->_ucfirst("тест"), "Тест");
  101. }
  102. function test_ucfirst_Space() {
  103. if(!is_object($driver = $this->_createDriver()))
  104. return;
  105. $str = ' Iñtërnâtiônàlizætiøn';
  106. $ucfirst = ' Iñtërnâtiônàlizætiøn';
  107. $this->assertEqual($driver->_ucfirst($str),$ucfirst);
  108. }
  109. function test_ucfirst_Upper() {
  110. if(!is_object($driver = $this->_createDriver()))
  111. return;
  112. $str = 'Ñtërnâtiônàlizætiøn';
  113. $ucfirst = 'Ñtërnâtiônàlizætiøn';
  114. $this->assertEqual($driver->_ucfirst($str), $ucfirst);
  115. }
  116. function test_strcasecmp() {
  117. if(!is_object($driver = $this->_createDriver()))
  118. return;
  119. $this->assertEqual($driver->_strcasecmp("тест", "тест"), 0);
  120. $this->assertEqual($driver->_strcasecmp("тест", "ТесТ"), 0);
  121. $this->assertTrue($driver->_strcasecmp("тест", "ТЕСТЫ") < 0);
  122. $this->assertTrue($driver->_strcasecmp("тесты", "ТЕСТ") > 0);
  123. }
  124. function test_substr_count() {
  125. if(!is_object($driver = $this->_createDriver()))
  126. return;
  127. $str = "это...просто тест, не стоит воспринимать это...всерьез";
  128. $this->assertEqual($driver->_substr_count($str, "это..."), 2);
  129. }
  130. function test_str_split() {
  131. if(!is_object($driver = $this->_createDriver()))
  132. return;
  133. $str = 'Iñtërnâtiônàlizætiøn';
  134. $array = array(
  135. 'I','ñ','t','ë','r','n','â','t','i','ô','n','à','l','i',
  136. 'z','æ','t','i','ø','n',
  137. );
  138. $this->assertEqual($driver->_str_split($str), $array);
  139. }
  140. function test_str_split_Newline() {
  141. if(!is_object($driver = $this->_createDriver()))
  142. return;
  143. $str = "Iñtërn\nâtiônàl\nizætiøn\n";
  144. $array = array(
  145. 'I','ñ','t','ë','r','n',"\n",'â','t','i','ô','n','à','l',"\n",'i',
  146. 'z','æ','t','i','ø','n',"\n",
  147. );
  148. $this->assertEqual($driver->_str_split($str), $array);
  149. }
  150. function test_preg_match() {
  151. if(!is_object($driver = $this->_createDriver()))
  152. return;
  153. $this->assertTrue($driver->_preg_match("/^(.)/", "тест", $matches));
  154. $this->assertEqual($matches[1], "т");
  155. }
  156. function test_preg_match_all() {
  157. if(!is_object($driver = $this->_createDriver()))
  158. return;
  159. $this->assertTrue($driver->_preg_match_all("/(.)/", "тест", $matches));
  160. $this->assertEqual($matches[1][0], "т");
  161. $this->assertEqual($matches[1][1], "е");
  162. $this->assertEqual($matches[1][2], "с");
  163. $this->assertEqual($matches[1][3], "т");
  164. }
  165. function test_preg_replace() {
  166. if(!is_object($driver = $this->_createDriver()))
  167. return;
  168. $this->assertEqual($driver->_preg_replace("/кошк./", "собаки", "кошки"), "собаки");
  169. }
  170. function test_preg_replace_callback() {
  171. if(!is_object($driver = $this->_createDriver()))
  172. return;
  173. $this->assertEqual($driver->_preg_replace_callback("/(кошк)(.)/",
  174. create_function('$m','return $m[1]."i";'),
  175. "кошки"), "кошкi");
  176. }
  177. function test_preg_split() {
  178. if(!is_object($driver = $this->_createDriver()))
  179. return;
  180. $pieces = $driver->_preg_split("/д./", "кошки да собаки");
  181. $this->assertEqual($pieces[0], "кошки ");
  182. $this->assertEqual($pieces[1], " собаки");
  183. }
  184. }
  185. ?>