]> projects.mako.cc - scuttle/blob - includes/utf8/tests/cases/utf8_ascii.test.php
remove duplicate shared-tag in xml - the android apps dont like this
[scuttle] / includes / utf8 / tests / cases / utf8_ascii.test.php
1 <?php
2 /**
3 * @version $Id: utf8_ascii.test.php,v 1.9 2006/10/17 08:53:37 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 . '/utils/ascii.php';
16
17 //--------------------------------------------------------------------
18 /**
19 * @package utf8
20 * @subpackage Tests
21 */
22 class test_utf8_is_ascii extends UnitTestCase {
23
24     function test_utf8_is_ascii() {
25         $this->UnitTestCase('test_utf8_is_ascii()');
26     }
27     
28     function testUtf8() {
29         $str = 'testiñg';
30         $this->assertFalse(utf8_is_ascii($str));
31     }
32     
33     function testAscii() {
34         $str = 'testing';
35         $this->assertTrue(utf8_is_ascii($str));
36     }
37     
38     function testInvalidChar() {
39         $str = "tes\xe9ting";
40         $this->assertFalse(utf8_is_ascii($str));
41     }
42     
43     function testEmptyStr() {
44         $str = '';
45         $this->assertTrue(utf8_is_ascii($str));
46     }
47     
48 }
49
50 //--------------------------------------------------------------------
51 /**
52 * @package utf8
53 * @subpackage Tests
54 */
55 class test_utf8_strip_non_ascii extends UnitTestCase {
56
57     function test_utf8_strip_non_ascii() {
58         $this->UnitTestCase('test_utf8_strip_non_ascii()');
59     }
60     
61     function testUtf8() {
62         $str = 'testiñg';
63         $this->assertEqual(utf8_strip_non_ascii($str),'testig');
64     }
65     
66     function testAscii() {
67         $str = 'testing';
68         $this->assertEqual(utf8_strip_non_ascii($str),'testing');
69     }
70     
71     function testInvalidChar() {
72         $str = "tes\xe9ting";
73         $this->assertEqual(utf8_strip_non_ascii($str),'testing');
74     }
75     
76     function testEmptyStr() {
77         $str = '';
78         $this->assertEqual(utf8_strip_non_ascii($str),'');
79     }
80 }
81
82 //--------------------------------------------------------------------
83 /**
84 * @package utf8
85 * @subpackage Tests
86 */
87 class test_utf8_strip_non_ascii_ctrl extends UnitTestCase{
88
89     function test_utf8_strip_non_ascii_ctrl() {
90         $this->UnitTestCase('test_utf8_strip_non_ascii_ctrl');
91     }
92     
93     function testNulAndNon7Bit() {
94         $str = "a\x00ñ\x00c";
95         $this->assertEqual(utf8_strip_non_ascii_ctrl($str),'ac');
96     }
97
98 }
99
100 //--------------------------------------------------------------------
101 /**
102 * @package utf8
103 * @subpackage Tests
104 */
105 class test_utf8_strip_ascii_ctrl extends UnitTestCase{
106
107     function test_utf8_strip_ascii_ctrl() {
108         $this->UnitTestCase('test_utf8_strip_ascii_ctrl');
109     }
110     
111     function testNul() {
112         $str = "a\x00b\x00c";
113         $this->assertEqual(utf8_strip_ascii_ctrl($str),'abc');
114     }
115
116 }
117
118 //--------------------------------------------------------------------
119 /**
120 * @package utf8
121 * @subpackage Tests
122 */
123 class test_utf8_accents_to_ascii extends UnitTestCase{
124
125     function test_utf8_accents_to_ascii() {
126         $this->UnitTestCase('test_utf8_accents_to_ascii');
127     }
128     
129     function testEmptyStr() {
130         $this->assertEqual(utf8_accents_to_ascii(''),'');
131     }
132     
133     function testLowercase() {
134         $str = "ô";
135         $this->assertEqual(utf8_accents_to_ascii($str,-1),'o');
136     }
137     
138     function testUppercase() {
139         $str = "Ô";
140         $this->assertEqual(utf8_accents_to_ascii($str,1),'O');
141     }
142     
143     function testBoth() {
144         $str = "ôÔ";
145         $this->assertEqual(utf8_accents_to_ascii($str,0),'oO');
146     }
147
148 }
149
150 //--------------------------------------------------------------------
151 /**
152 * @package utf8
153 * @subpackage Tests
154 */
155 if (!defined('TEST_RUNNING')) {
156     define('TEST_RUNNING', true);
157     $test = &new GroupTest('utf8_ascii');
158     $test->addTestCase(new test_utf8_is_ascii());
159     $test->addTestCase(new test_utf8_strip_non_ascii());
160     $test->addTestCase(new test_utf8_strip_non_ascii_ctrl());
161     $test->addTestCase(new test_utf8_strip_ascii_ctrl());
162     $test->addTestCase(new test_utf8_accents_to_ascii());
163     $reporter = & getTestReporter();
164     $test->run($reporter);
165 }

Benjamin Mako Hill || Want to submit a patch?