PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/limb-php-framework/limb-app-buildman
PHP | 178 lines | 126 code | 42 blank | 10 comment | 1 complexity | 80a2db1f30b38c56d45a944caa348eee 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: lmbSingleByteStringsDriverTest.class.php 4998 2007-02-08 15:36:32Z pachanga $
  10. * @package i18n
  11. */
  12. lmb_require('limb/i18n/src/charset/lmbSingleByteStringsDriver.class.php');
  13. class lmbSingleByteStringsDriverTest extends UnitTestCase
  14. {
  15. function test_substr() {
  16. $driver = new lmbSingleByteStringsDriver();
  17. $this->assertEqual($driver->_substr("just a test", 1), "ust a test");
  18. $this->assertEqual($driver->_substr("hello", 0, 400), "hello");
  19. $this->assertEqual($driver->_substr("foobar", 1, 4), "ooba");
  20. $this->assertEqual($driver->_substr("foo", -1), "o");
  21. $this->assertEqual($driver->_substr("foo", 0, -1), "fo");
  22. $this->assertEqual($driver->_substr("foo", 1, -1), "o");
  23. }
  24. function test_rtrim() {
  25. $driver = new lmbSingleByteStringsDriver();
  26. $this->assertEqual($driver->_rtrim("foo\n\n\t"), "foo");
  27. $this->assertEqual($driver->_rtrim("bar?++.*?", ".*?+"), "bar");
  28. }
  29. function test_ltrim() {
  30. $driver = new lmbSingleByteStringsDriver();
  31. $this->assertEqual($driver->_ltrim("\n\n\tfoo"), "foo");
  32. $this->assertEqual($driver->_ltrim("?+.*+?baz", "?.*+"), "baz");
  33. }
  34. function test_trim() {
  35. $driver = new lmbSingleByteStringsDriver();
  36. $this->assertEqual($driver->_trim(" \n\t\0 foo\0\n\n\t"), "foo");
  37. $this->assertEqual($driver->_trim("pbazp", "p"), "baz");
  38. $this->assertEqual($driver->_trim("?*++?bar?+.+?", "?.+*"), "bar");
  39. }
  40. function test_str_replace() {
  41. $driver = new lmbSingleByteStringsDriver();
  42. $this->assertEqual($driver->_str_replace("aaa", "", "fooaaabar"),
  43. "foobar");
  44. $this->assertEqual($driver->_str_replace("a", "b", "foobaz"),
  45. "foobbz");
  46. $search = array("v", "x");
  47. $this->assertEqual($driver->_str_replace($search, "d", "vxdddxv"),
  48. "ddddddd");
  49. $replace = array("a", "w");
  50. $this->assertEqual($driver->_str_replace($search, $replace, "vfooxbar"),
  51. "afoowbar");
  52. }
  53. function test_strlen() {
  54. $driver = new lmbSingleByteStringsDriver();
  55. $this->assertEqual($driver->_strlen("foo"), 3);
  56. $this->assertEqual($driver->_strlen("\nfoo bar "), 9);
  57. }
  58. function test_strpos() {
  59. $driver = new lmbSingleByteStringsDriver();
  60. $this->assertEqual($driver->_strpos("foo", "f"), 0);
  61. $this->assertEqual($driver->_strpos("foo", "o"), 1);
  62. $this->assertEqual($driver->_strpos("foo", "o", 2), 2);
  63. }
  64. function test_strrpos() {
  65. $driver = new lmbSingleByteStringsDriver();
  66. $this->assertEqual($driver->_strrpos("foo", "o"), 2);
  67. $this->assertEqual($driver->_strrpos("foo", "o", 2), 2);
  68. }
  69. function test_strtolower() {
  70. $driver = new lmbSingleByteStringsDriver();
  71. $this->assertEqual($driver->_strtolower("TEST"), "test");
  72. $this->assertEqual($driver->_strtolower("tEsT"), "test");
  73. }
  74. function test_strtoupper() {
  75. $driver = new lmbSingleByteStringsDriver();
  76. $this->assertEqual($driver->_strtoupper("test"), "TEST");
  77. $this->assertEqual($driver->_strtoupper("tEsT"), "TEST");
  78. }
  79. function test_ucfirst() {
  80. $driver = new lmbSingleByteStringsDriver();
  81. $this->assertEqual($driver->_ucfirst("test"), "Test");
  82. }
  83. function test_strcasecmp() {
  84. $driver = new lmbSingleByteStringsDriver();
  85. $this->assertEqual($driver->_strcasecmp("test", "test"), 0);
  86. $this->assertEqual($driver->_strcasecmp("test", "TesT"), 0);
  87. $this->assertTrue($driver->_strcasecmp("test", "TESTS") < 0);
  88. $this->assertTrue($driver->_strcasecmp("tests", "TEST") > 0);
  89. }
  90. function test_substr_count() {
  91. $driver = new lmbSingleByteStringsDriver();
  92. $str = "This is a test";
  93. $this->assertEqual($driver->_substr_count($str, "is"), 2);
  94. }
  95. function test_str_split() {
  96. if(phpversion() < 5)
  97. return;
  98. $driver = new lmbSingleByteStringsDriver();
  99. $str = 'Internationalization';
  100. $array = array(
  101. 'I','n','t','e','r','n','a','t','i','o','n','a','l','i',
  102. 'z','a','t','i','o','n',
  103. );
  104. $this->assertEqual($driver->_str_split($str), $array);
  105. }
  106. function test_preg_match() {
  107. $driver = new lmbSingleByteStringsDriver();
  108. $this->assertTrue($driver->_preg_match("/^(.)/", "test", $matches));
  109. $this->assertEqual($matches[1], "t");
  110. }
  111. function test_preg_match_all() {
  112. $driver = new lmbSingleByteStringsDriver();
  113. $this->assertTrue($driver->_preg_match_all("/(.)/", "test", $matches));
  114. $this->assertEqual($matches[1][0], "t");
  115. $this->assertEqual($matches[1][1], "e");
  116. $this->assertEqual($matches[1][2], "s");
  117. $this->assertEqual($matches[1][3], "t");
  118. }
  119. function test_preg_replace() {
  120. $driver = new lmbSingleByteStringsDriver();
  121. $this->assertEqual($driver->_preg_replace("/cat./", "dogs", "cats"), "dogs");
  122. }
  123. function test_preg_replace_callback() {
  124. $driver = new lmbSingleByteStringsDriver();
  125. $this->assertEqual($driver->_preg_replace_callback("/(cat)(.)/",
  126. create_function('$m','return "dog".$m[2];'),
  127. "cats"), "dogs");
  128. }
  129. function test_preg_split() {
  130. $driver = new lmbSingleByteStringsDriver();
  131. $pieces = $driver->_preg_split("/an./", "foo and bar");
  132. $this->assertEqual($pieces[0], "foo ");
  133. $this->assertEqual($pieces[1], " bar");
  134. }
  135. }
  136. ?>