/
utf8_substr_replace.test.php
76 lines (65 loc) · 2.04 KB
/
utf8_substr_replace.test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* @version $Id: utf8_substr_replace.test.php,v 1.3 2006/10/17 09:22:14 harryf Exp $
* @package utf8
* @subpackage Tests
*/
//--------------------------------------------------------------------
/**
* Includes
* @package utf8
* @subpackage Tests
*/
require_once(dirname(__FILE__).'/../config.php');
require_once UTF8 . '/substr_replace.php';
//--------------------------------------------------------------------
/**
* @package utf8
* @subpackage Tests
*/
class test_utf8_native_substr_replace extends UnitTestCase {
function test_utf8_native_substr_replace() {
$this->UnitTestCase('utf8_str_split()');
}
function testReplaceStart() {
$str = 'Iñtërnâtiônàlizætiøn';
$replaced = 'IñtërnâtX';
$this->assertEqual(utf8_substr_replace($str,'X',8),$replaced);
}
function testEmptyString() {
$str = '';
$replaced = 'X';
$this->assertEqual(utf8_substr_replace($str,'X',8),$replaced);
}
function testNegative() {
$str = 'testing';
$replaced = substr_replace($str,'foo',-2,-2);
$this->assertEqual(utf8_substr_replace($str,'foo',-2,-2),$replaced);
}
function testZero() {
$str = 'testing';
$replaced = substr_replace($str,'foo',0,0);
$this->assertEqual(utf8_substr_replace($str,'foo',0,0),$replaced);
}
function testLinefeed() {
$str = "Iñ\ntërnâtiônàlizætiøn";
$replaced = "Iñ\ntërnâtX";
$this->assertEqual(utf8_substr_replace($str,'X',9),$replaced);
}
function testLinefeedReplace() {
$str = "Iñ\ntërnâtiônàlizætiøn";
$replaced = "Iñ\ntërnâtX\nY";
$this->assertEqual(utf8_substr_replace($str,"X\nY",9),$replaced);
}
}
//--------------------------------------------------------------------
/**
* @package utf8
* @subpackage Tests
*/
if (!defined('TEST_RUNNING')) {
define('TEST_RUNNING', true);
$test = &new test_utf8_native_substr_replace();
$reporter = & getTestReporter();
$test->run($reporter);
}