-
-
Notifications
You must be signed in to change notification settings - Fork 849
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
23,238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
// use no mbstring help here | ||
if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1); | ||
require_once DOKU_INC.'inc/utf8.php'; | ||
|
||
class utf8_correctidx_test extends PHPUnit_Framework_TestCase { | ||
|
||
|
||
function test_singlebyte(){ | ||
// we test multiple cases here - format: in, offset, length, out | ||
$tests = array(); | ||
|
||
// single byte, should return current index | ||
$tests[] = array('aaживπά우리をあöä',0,false,0); | ||
$tests[] = array('aaживπά우리をあöä',1,false,1); | ||
$tests[] = array('aaживπά우리をあöä',1,true,1); | ||
|
||
foreach($tests as $test){ | ||
$this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]); | ||
} | ||
} | ||
|
||
function test_twobyte(){ | ||
// we test multiple cases here - format: in, offset, length, out | ||
$tests = array(); | ||
|
||
// two byte, should move to boundary, expect even number | ||
$tests[] = array('aaживπά우리をあöä',2,false,2); | ||
$tests[] = array('aaживπά우리をあöä',3,false,2); | ||
$tests[] = array('aaживπά우리をあöä',4,false,4); | ||
|
||
$tests[] = array('aaживπά우리をあöä',2,true,2); | ||
$tests[] = array('aaживπά우리をあöä',3,true,4); | ||
$tests[] = array('aaживπά우리をあöä',4,true,4); | ||
|
||
foreach($tests as $test){ | ||
$this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]); | ||
} | ||
} | ||
|
||
function test_threebyte(){ | ||
// we test multiple cases here - format: in, offset, length, out | ||
$tests = array(); | ||
|
||
// three byte, should move to boundary 10 or 13 | ||
$tests[] = array('aaживπά우리をあöä',10,false,10); | ||
$tests[] = array('aaживπά우리をあöä',11,false,10); | ||
$tests[] = array('aaживπά우리をあöä',12,false,10); | ||
$tests[] = array('aaживπά우리をあöä',13,false,13); | ||
|
||
$tests[] = array('aaживπά우리をあöä',10,true,10); | ||
$tests[] = array('aaживπά우리をあöä',11,true,13); | ||
$tests[] = array('aaживπά우리をあöä',12,true,13); | ||
$tests[] = array('aaживπά우리をあöä',13,true,13); | ||
|
||
foreach($tests as $test){ | ||
$this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]); | ||
} | ||
} | ||
|
||
function test_bounds(){ | ||
// we test multiple cases here - format: in, offset, length, out | ||
$tests = array(); | ||
|
||
// bounds checking | ||
$tests[] = array('aaживπά우리をあöä',-2,false,0); | ||
$tests[] = array('aaживπά우리をあöä',128,false,29); | ||
|
||
$tests[] = array('aaживπά우리をあöä',-2,true,0); | ||
$tests[] = array('aaживπά우리をあöä',128,true,29); | ||
|
||
foreach($tests as $test){ | ||
$this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]); | ||
} | ||
} | ||
|
||
} | ||
//Setup VIM: ex: et ts=4 : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
require_once DOKU_INC.'inc/utf8.php'; | ||
|
||
// use no mbstring help here | ||
if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1); | ||
|
||
class utf8_html_test extends PHPUnit_Framework_TestCase { | ||
|
||
function test_from_1byte(){ | ||
$in = 'a'; | ||
$out = 'a'; | ||
$this->assertEquals(utf8_tohtml($in),$out); | ||
} | ||
|
||
function test_from_2byte(){ | ||
$in = "\xc3\xbc"; | ||
$out = 'ü'; | ||
$this->assertEquals(utf8_tohtml($in),$out); | ||
} | ||
|
||
function test_from_3byte(){ | ||
$in = "\xe2\x99\x8a"; | ||
$out = '♊'; | ||
$this->assertEquals(utf8_tohtml($in),$out); | ||
} | ||
|
||
function test_from_4byte(){ | ||
$in = "\xf4\x80\x80\x81"; | ||
$out = '􀀁'; | ||
$this->assertEquals(utf8_tohtml($in),$out); | ||
} | ||
|
||
function test_to_1byte(){ | ||
$out = 'a'; | ||
$in = 'a'; | ||
$this->assertEquals(utf8_unhtml($in),$out); | ||
} | ||
|
||
function test_to_2byte(){ | ||
$out = "\xc3\xbc"; | ||
$in = 'ü'; | ||
$this->assertEquals(utf8_unhtml($in),$out); | ||
} | ||
|
||
function test_to_3byte(){ | ||
$out = "\xe2\x99\x8a"; | ||
$in = '♊'; | ||
$this->assertEquals(utf8_unhtml($in),$out); | ||
} | ||
|
||
function test_to_4byte(){ | ||
$out = "\xf4\x80\x80\x81"; | ||
$in = '􀀁'; | ||
$this->assertEquals(utf8_unhtml($in),$out); | ||
} | ||
|
||
function test_without_entities(){ | ||
$out = '&#38;&#38;'; | ||
$in = '&#38;&amp;#38;'; | ||
$this->assertEquals(utf8_unhtml($in),$out); | ||
} | ||
|
||
function test_with_entities(){ | ||
$out = '&&#38;'; | ||
$in = '&#38;&amp;#38;'; | ||
$this->assertEquals(utf8_unhtml($in,HTML_ENTITIES),$out); | ||
} | ||
|
||
} | ||
|
||
//Setup VIM: ex: et ts=4 : |
Oops, something went wrong.