Tagged 0.7.5
[scuttle] / includes / utf8 / tests / cases / utf8_trim.test.php
1 <?php
2 /**
3 * @version $Id: utf8_trim.test.php,v 1.2 2006/02/25 14:52:18 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 require_once UTF8 . '/trim.php';
16
17 //--------------------------------------------------------------------
18 /**
19 * @package utf8
20 * @subpackage Tests
21 */
22 class test_utf8_ltrim extends UnitTestCase {
23
24     function test_utf8_ltrim() {
25         $this->UnitTestCase('test_utf8_ltrim()');
26     }
27     
28     function testTrim() {
29         $str = 'ñtërnâtiônàlizætiøn';
30         $trimmed = 'tërnâtiônàlizætiøn';
31         $this->assertEqual(utf8_ltrim($str,'ñ'),$trimmed);
32     }
33     
34     function testNoTrim() {
35         $str = ' Iñtërnâtiônàlizætiøn';
36         $trimmed = ' Iñtërnâtiônàlizætiøn';
37         $this->assertEqual(utf8_ltrim($str,'ñ'),$trimmed);
38     }
39     
40     function testEmptyString() {
41         $str = '';
42         $trimmed = '';
43         $this->assertEqual(utf8_ltrim($str),$trimmed);
44     }
45     
46     function testForwardSlash() {
47         $str = '/Iñtërnâtiônàlizætiøn';
48         $trimmed = 'Iñtërnâtiônàlizætiøn';
49         $this->assertEqual(utf8_ltrim($str,'/'),$trimmed);
50     }
51     
52     function testNegateCharClass() {
53         $str = 'Iñtërnâtiônàlizætiøn';
54         $trimmed = 'Iñtërnâtiônàlizætiøn';
55         $this->assertEqual(utf8_ltrim($str,'^s'),$trimmed);
56     }
57     
58     function testLinefeed() {
59         $str = "ñ\nñtërnâtiônàlizætiøn";
60         $trimmed = "\nñtërnâtiônàlizætiøn";
61         $this->assertEqual(utf8_ltrim($str,'ñ'),$trimmed);
62     }
63     
64     function testLinefeedMask() {
65         $str = "ñ\nñtërnâtiônàlizætiøn";
66         $trimmed = "tërnâtiônàlizætiøn";
67         $this->assertEqual(utf8_ltrim($str,"ñ\n"),$trimmed);
68     }
69     
70 }
71
72 //--------------------------------------------------------------------
73 /**
74 * @package utf8
75 * @subpackage Tests
76 */
77 class test_utf8_rtrim extends UnitTestCase {
78
79     function test_utf8_rtrim() {
80         $this->UnitTestCase('test_utf8_rtrim()');
81     }
82     
83     function testTrim() {
84         $str = 'Iñtërnâtiônàlizætiø';
85         $trimmed = 'Iñtërnâtiônàlizæti';
86         $this->assertEqual(utf8_rtrim($str,'ø'),$trimmed);
87     }
88     
89     function testNoTrim() {
90         $str = 'Iñtërnâtiônàlizætiøn ';
91         $trimmed = 'Iñtërnâtiônàlizætiøn ';
92         $this->assertEqual(utf8_rtrim($str,'ø'),$trimmed);
93     }
94     
95     function testEmptyString() {
96         $str = '';
97         $trimmed = '';
98         $this->assertEqual(utf8_rtrim($str),$trimmed);
99     }
100     
101     function testLinefeed() {
102         $str = "Iñtërnâtiônàlizætiø\nø";
103         $trimmed = "Iñtërnâtiônàlizætiø\n";
104         $this->assertEqual(utf8_rtrim($str,'ø'),$trimmed);
105     }
106     
107     function testLinefeedMask() {
108         $str = "Iñtërnâtiônàlizætiø\nø";
109         $trimmed = "Iñtërnâtiônàlizæti";
110         $this->assertEqual(utf8_rtrim($str,"ø\n"),$trimmed);
111     }
112     
113 }
114
115 //--------------------------------------------------------------------
116 /**
117 * @package utf8
118 * @subpackage Tests
119 */
120 class test_utf8_trim extends UnitTestCase {
121
122     function test_utf8_trim() {
123         $this->UnitTestCase('test_utf8_trim()');
124     }
125     
126     function testTrim() {
127         $str = 'ñtërnâtiônàlizætiø';
128         $trimmed = 'tërnâtiônàlizæti';
129         $this->assertEqual(utf8_trim($str,'ñø'),$trimmed);
130     }
131     
132     function testNoTrim() {
133         $str = ' Iñtërnâtiônàlizætiøn ';
134         $trimmed = ' Iñtërnâtiônàlizætiøn ';
135         $this->assertEqual(utf8_trim($str,'ñø'),$trimmed);
136     }
137     
138     function testEmptyString() {
139         $str = '';
140         $trimmed = '';
141         $this->assertEqual(utf8_trim($str),$trimmed);
142     }
143 }
144
145 //--------------------------------------------------------------------
146 /**
147 * @package utf8
148 * @subpackage Tests
149 */
150 if (!defined('TEST_RUNNING')) {
151     define('TEST_RUNNING', true);
152     $test = & new GroupTest('utf8_trim tests');
153     $test->addTestCase(new test_utf8_ltrim());
154     $test->addTestCase(new test_utf8_rtrim());
155     $test->addTestCase(new test_utf8_trim());
156     $reporter = & getTestReporter();
157     $test->run($reporter);
158 }

Benjamin Mako Hill || Want to submit a patch?