X-Git-Url: https://projects.mako.cc/source/scuttle/blobdiff_plain/bce919af7b49bbd06223f79b8c37a53a3d263ff0..c7f63c8b9b12efd7b3c10b9f80cda06eaf32068f:/includes/utf8/tests/cases/utf8_position.test.php diff --git a/includes/utf8/tests/cases/utf8_position.test.php b/includes/utf8/tests/cases/utf8_position.test.php new file mode 100644 index 0000000..ef99551 --- /dev/null +++ b/includes/utf8/tests/cases/utf8_position.test.php @@ -0,0 +1,136 @@ +assertIdentical(utf8_byte_position($str, 3), 3); + $this->assertIdentical(utf8_byte_position($str, 3, 4), array(3,4)); + $this->assertIdentical(utf8_byte_position($str, -1), 0); + $this->assertIdentical(utf8_byte_position($str, 8), 7); + } + + function test_multibyte_char_to_byte() { + $str = 'Iñtërnâtiônàlizætiøn'; + $this->assertIdentical(utf8_byte_position($str, 3), 4); + $this->assertIdentical(utf8_byte_position($str, 3, 5), array(4,7)); + $this->assertIdentical(utf8_byte_position($str, -1), 0); + $this->assertIdentical(utf8_byte_position($str, 28), 27); + } + + // tests for utf8_locate_current_chr & utf8_locate_next_chr + function test_singlebyte(){ + $tests = array(); + + // single byte, should return current index + $tests[] = array('aaживπά우리をあöä',0,0); + $tests[] = array('aaживπά우리をあöä',1,1); + + foreach($tests as $test){ + $this->assertIdentical(utf8_locate_current_chr($test[0],$test[1]),$test[2]); + } + + $tests = array(); + $tests[] = array('aaживπά우리をあöä',1,1); + + foreach($tests as $test){ + $this->assertIdentical(utf8_locate_next_chr($test[0],$test[1]),$test[2]); + } + + } + + function test_twobyte(){ + // two byte, should move to boundary, expect even number + $tests = array(); + $tests[] = array('aaживπά우리をあöä',2,2); + $tests[] = array('aaживπά우리をあöä',3,2); + $tests[] = array('aaживπά우리をあöä',4,4); + + foreach($tests as $test){ + $this->assertIdentical(utf8_locate_current_chr($test[0],$test[1]),$test[2]); + } + + $tests = array(); + $tests[] = array('aaживπά우리をあöä',2,2); + $tests[] = array('aaживπά우리をあöä',3,4); + $tests[] = array('aaживπά우리をあöä',4,4); + + foreach($tests as $test){ + $this->assertIdentical(utf8_locate_next_chr($test[0],$test[1]),$test[2]); + } + } + + function test_threebyte(){ + // three byte, should move to boundary 10 or 13 + $tests = array(); + $tests[] = array('aaживπά우리をあöä',10,10); + $tests[] = array('aaживπά우리をあöä',11,10); + $tests[] = array('aaживπά우리をあöä',12,10); + $tests[] = array('aaживπά우리をあöä',13,13); + + foreach($tests as $test){ + $this->assertIdentical(utf8_locate_current_chr($test[0],$test[1]),$test[2]); + } + + $tests = array(); + $tests[] = array('aaживπά우리をあöä',10,10); + $tests[] = array('aaживπά우리をあöä',11,13); + $tests[] = array('aaживπά우리をあöä',12,13); + $tests[] = array('aaживπά우리をあöä',13,13); + + foreach($tests as $test){ + $this->assertIdentical(utf8_locate_next_chr($test[0],$test[1]),$test[2]); + } + } + + function test_bounds(){ + // bounds checking + $tests = array(); + $tests[] = array('aaживπά우리をあöä',-2,0); + $tests[] = array('aaживπά우리をあöä',128,29); + + foreach($tests as $test){ + $this->assertIdentical(utf8_locate_current_chr($test[0],$test[1]),$test[2]); + } + + $tests[] = array('aaживπά우리をあöä',-2,0); + $tests[] = array('aaживπά우리をあöä',128,29); + + foreach($tests as $test){ + $this->assertIdentical(utf8_locate_next_chr($test[0],$test[1]),$test[2]); + } + } + + +} + +//-------------------------------------------------------------------- +/** +* @package utf8 +* @subpackage Tests +*/ +if (!defined('TEST_RUNNING')) { + define('TEST_RUNNING', true); + $test = &new test_utf8_position(); + $reporter = & getTestReporter(); + $test->run($reporter); +}