]> projects.mako.cc - scuttle/blob - includes/utf8/tests/cases/utf8_substr.test.php
updated readme with information on a series of bugs I know exist
[scuttle] / includes / utf8 / tests / cases / utf8_substr.test.php
1 <?php
2 /**
3 * @version $Id: utf8_substr.test.php,v 1.5 2006/09/30 22:51:00 harryf 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
16 //--------------------------------------------------------------------
17 /**
18 * @package utf8
19 * @subpackage Tests
20 */
21 class test_utf8_substr extends UnitTestCase {
22
23     function test_utf8_substr() {
24         $this->UnitTestCase('utf8_substr()');
25     }
26     
27     function testUtf8() {
28         $str = 'Iñtërnâtiônàlizætiøn';
29         $this->assertEqual(utf8_substr($str,0,2),'Iñ');
30     }
31     
32     function testUtf8Two() {
33         $str = 'Iñtërnâtiônàlizætiøn';
34         $this->assertEqual(utf8_substr($str,2,2),'të');
35     }
36     
37     function testUtf8Zero() {
38         $str = 'Iñtërnâtiônàlizætiøn';
39         $this->assertEqual(utf8_substr($str,0),'Iñtërnâtiônàlizætiøn');
40     }
41     
42     function testUtf8ZeroZero() {
43         $str = 'Iñtërnâtiônàlizætiøn';
44         $this->assertEqual(utf8_substr($str,0,0),'');
45     }
46     
47     function testStartGreatThanLength() {
48         $str = 'Iñt';
49         $this->assertFalse(utf8_substr($str,4));
50     }
51     
52     function testCompareStartGreatThanLength() {
53         $str = 'abc';
54         $this->assertEqual(utf8_substr($str,4),substr($str,4));
55     }
56     
57     function testLengthBeyondString() {
58         $str = 'Iñt';
59         $this->assertEqual(utf8_substr($str,1,5),'ñt');
60     }
61     
62     function testCompareLengthBeyondString() {
63         $str = 'abc';
64         $this->assertEqual(utf8_substr($str,1,5),substr($str,1,5));
65     }
66     
67     function testStartNegative() {
68         $str = 'Iñtërnâtiônàlizætiøn';
69         $this->assertEqual(utf8_substr($str,-4), 'tiøn');
70     }
71     
72     function testLengthNegative() {
73         $str = 'Iñtërnâtiônàlizætiøn';
74         $this->assertEqual(utf8_substr($str,10,-2), 'nàlizæti');
75     }
76     
77     function testStartLengthNegative() {
78         $str = 'Iñtërnâtiônàlizætiøn';
79         $this->assertEqual(utf8_substr($str,-4,-2), 'ti');
80     }
81     
82     function testLinefeed() {
83         $str = "Iñ\ntërnâtiônàlizætiøn";
84         $this->assertEqual(utf8_substr($str,1,5),"ñ\ntër");
85     }
86     
87     function testLongLength() {
88         $str = 'Iñtërnâtiônàlizætiøn';
89         $this->assertEqual(utf8_substr($str,0,15536),'Iñtërnâtiônàlizætiøn');
90     }
91     
92 }
93
94 //--------------------------------------------------------------------
95 /**
96 * @package utf8
97 * @subpackage Tests
98 */
99 if (!defined('TEST_RUNNING')) {
100     define('TEST_RUNNING', true);
101     $test = & new test_utf8_substr();
102     $reporter = & getTestReporter();
103     $test->run($reporter);
104 }

Benjamin Mako Hill || Want to submit a patch?