| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/i18n/src/charset/lmbSingleByteCharsetDriver.class.php'); 10 11 class lmbSingleByteCharsetDriverTest extends UnitTestCase 12 { 13 function test_substr() { 14 $driver = new lmbSingleByteCharsetDriver(); 15 16 $this->assertEqual($driver->_substr("just a test", 1), "ust a test"); 17 $this->assertEqual($driver->_substr("hello", 0, 400), "hello"); 18 $this->assertEqual($driver->_substr("foobar", 1, 4), "ooba"); 19 $this->assertEqual($driver->_substr("foo", -1), "o"); 20 $this->assertEqual($driver->_substr("foo", 0, -1), "fo"); 21 $this->assertEqual($driver->_substr("foo", 1, -1), "o"); 22 } 23 24 function test_rtrim() { 25 $driver = new lmbSingleByteCharsetDriver(); 26 27 $this->assertEqual($driver->_rtrim("foo\n\n\t"), "foo"); 28 $this->assertEqual($driver->_rtrim("bar?++.*?", ".*?+"), "bar"); 29 } 30 31 function test_ltrim() { 32 $driver = new lmbSingleByteCharsetDriver(); 33 34 $this->assertEqual($driver->_ltrim("\n\n\tfoo"), "foo"); 35 $this->assertEqual($driver->_ltrim("?+.*+?baz", "?.*+"), "baz"); 36 } 37 38 function test_trim() { 39 $driver = new lmbSingleByteCharsetDriver(); 40 41 $this->assertEqual($driver->_trim(" \n\t\0 foo\0\n\n\t"), "foo"); 42 $this->assertEqual($driver->_trim("pbazp", "p"), "baz"); 43 $this->assertEqual($driver->_trim("?*++?bar?+.+?", "?.+*"), "bar"); 44 } 45 46 function test_str_replace() { 47 $driver = new lmbSingleByteCharsetDriver(); 48 49 $this->assertEqual($driver->_str_replace("aaa", "", "fooaaabar"), 50 "foobar"); 51 $this->assertEqual($driver->_str_replace("a", "b", "foobaz"), 52 "foobbz"); 53 $search = array("v", "x"); 54 $this->assertEqual($driver->_str_replace($search, "d", "vxdddxv"), 55 "ddddddd"); 56 $replace = array("a", "w"); 57 $this->assertEqual($driver->_str_replace($search, $replace, "vfooxbar"), 58 "afoowbar"); 59 } 60 61 function test_strlen() { 62 $driver = new lmbSingleByteCharsetDriver(); 63 64 $this->assertEqual($driver->_strlen("foo"), 3); 65 $this->assertEqual($driver->_strlen("\nfoo bar "), 9); 66 } 67 68 function test_strpos() { 69 $driver = new lmbSingleByteCharsetDriver(); 70 71 $this->assertEqual($driver->_strpos("foo", "f"), 0); 72 $this->assertEqual($driver->_strpos("foo", "o"), 1); 73 $this->assertEqual($driver->_strpos("foo", "o", 2), 2); 74 } 75 76 function test_strrpos() { 77 $driver = new lmbSingleByteCharsetDriver(); 78 79 $this->assertEqual($driver->_strrpos("foo", "o"), 2); 80 $this->assertEqual($driver->_strrpos("foo", "o", 2), 2); 81 } 82 83 function test_strtolower() { 84 $driver = new lmbSingleByteCharsetDriver(); 85 86 $this->assertEqual($driver->_strtolower("TEST"), "test"); 87 $this->assertEqual($driver->_strtolower("tEsT"), "test"); 88 } 89 90 function test_strtoupper() { 91 $driver = new lmbSingleByteCharsetDriver(); 92 93 $this->assertEqual($driver->_strtoupper("test"), "TEST"); 94 $this->assertEqual($driver->_strtoupper("tEsT"), "TEST"); 95 } 96 97 function test_ucfirst() { 98 $driver = new lmbSingleByteCharsetDriver(); 99 100 $this->assertEqual($driver->_ucfirst("test"), "Test"); 101 } 102 103 function test_strcasecmp() { 104 $driver = new lmbSingleByteCharsetDriver(); 105 106 $this->assertEqual($driver->_strcasecmp("test", "test"), 0); 107 $this->assertEqual($driver->_strcasecmp("test", "TesT"), 0); 108 $this->assertTrue($driver->_strcasecmp("test", "TESTS") < 0); 109 $this->assertTrue($driver->_strcasecmp("tests", "TEST") > 0); 110 } 111 112 function test_substr_count() { 113 $driver = new lmbSingleByteCharsetDriver(); 114 115 $str = "This is a test"; 116 117 $this->assertEqual($driver->_substr_count($str, "is"), 2); 118 } 119 120 function test_str_split() { 121 if(phpversion() < 5) 122 return; 123 124 $driver = new lmbSingleByteCharsetDriver(); 125 126 $str = 'Internationalization'; 127 $array = array( 128 'I','n','t','e','r','n','a','t','i','o','n','a','l','i', 129 'z','a','t','i','o','n', 130 ); 131 $this->assertEqual($driver->_str_split($str), $array); 132 } 133 134 function test_preg_match() { 135 $driver = new lmbSingleByteCharsetDriver(); 136 137 $this->assertTrue($driver->_preg_match("/^(.)/", "test", $matches)); 138 $this->assertEqual($matches[1], "t"); 139 } 140 141 function test_preg_match_all() { 142 $driver = new lmbSingleByteCharsetDriver(); 143 144 $this->assertTrue($driver->_preg_match_all("/(.)/", "test", $matches)); 145 146 $this->assertEqual($matches[1][0], "t"); 147 $this->assertEqual($matches[1][1], "e"); 148 $this->assertEqual($matches[1][2], "s"); 149 $this->assertEqual($matches[1][3], "t"); 150 } 151 152 function test_preg_replace() { 153 $driver = new lmbSingleByteCharsetDriver(); 154 155 $this->assertEqual($driver->_preg_replace("/cat./", "dogs", "cats"), "dogs"); 156 } 157 158 function test_preg_replace_callback() { 159 $driver = new lmbSingleByteCharsetDriver(); 160 161 $this->assertEqual($driver->_preg_replace_callback("/(cat)(.)/", 162 create_function('$m','return "dog".$m[2];'), 163 "cats"), "dogs"); 164 } 165 166 function test_preg_split() { 167 $driver = new lmbSingleByteCharsetDriver(); 168 169 $pieces = $driver->_preg_split("/an./", "foo and bar"); 170 $this->assertEqual($pieces[0], "foo "); 171 $this->assertEqual($pieces[1], " bar"); 172 } 173 } 174 175 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |