3 * @version $Id: utf8_ascii.test.php,v 1.9 2006/10/17 08:53:37 harryf Exp $
8 //--------------------------------------------------------------------
14 require_once(dirname(__FILE__).'/../config.php');
15 require_once UTF8 . '/utils/ascii.php';
17 //--------------------------------------------------------------------
22 class test_utf8_is_ascii extends UnitTestCase {
24 function test_utf8_is_ascii() {
25 $this->UnitTestCase('test_utf8_is_ascii()');
30 $this->assertFalse(utf8_is_ascii($str));
33 function testAscii() {
35 $this->assertTrue(utf8_is_ascii($str));
38 function testInvalidChar() {
40 $this->assertFalse(utf8_is_ascii($str));
43 function testEmptyStr() {
45 $this->assertTrue(utf8_is_ascii($str));
50 //--------------------------------------------------------------------
55 class test_utf8_strip_non_ascii extends UnitTestCase {
57 function test_utf8_strip_non_ascii() {
58 $this->UnitTestCase('test_utf8_strip_non_ascii()');
63 $this->assertEqual(utf8_strip_non_ascii($str),'testig');
66 function testAscii() {
68 $this->assertEqual(utf8_strip_non_ascii($str),'testing');
71 function testInvalidChar() {
73 $this->assertEqual(utf8_strip_non_ascii($str),'testing');
76 function testEmptyStr() {
78 $this->assertEqual(utf8_strip_non_ascii($str),'');
82 //--------------------------------------------------------------------
87 class test_utf8_strip_non_ascii_ctrl extends UnitTestCase{
89 function test_utf8_strip_non_ascii_ctrl() {
90 $this->UnitTestCase('test_utf8_strip_non_ascii_ctrl');
93 function testNulAndNon7Bit() {
95 $this->assertEqual(utf8_strip_non_ascii_ctrl($str),'ac');
100 //--------------------------------------------------------------------
105 class test_utf8_strip_ascii_ctrl extends UnitTestCase{
107 function test_utf8_strip_ascii_ctrl() {
108 $this->UnitTestCase('test_utf8_strip_ascii_ctrl');
112 $str = "a\x00b\x00c";
113 $this->assertEqual(utf8_strip_ascii_ctrl($str),'abc');
118 //--------------------------------------------------------------------
123 class test_utf8_accents_to_ascii extends UnitTestCase{
125 function test_utf8_accents_to_ascii() {
126 $this->UnitTestCase('test_utf8_accents_to_ascii');
129 function testEmptyStr() {
130 $this->assertEqual(utf8_accents_to_ascii(''),'');
133 function testLowercase() {
135 $this->assertEqual(utf8_accents_to_ascii($str,-1),'o');
138 function testUppercase() {
140 $this->assertEqual(utf8_accents_to_ascii($str,1),'O');
143 function testBoth() {
145 $this->assertEqual(utf8_accents_to_ascii($str,0),'oO');
150 //--------------------------------------------------------------------
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);