私は PHP で 2 つの関数を書きましたstr_to_utf8()
(seems_utf8()
これらの関数は、他のコードから借用した部分で構成されています)。現在、私はそれらの単体テストを作成しており、適切な単体テストがあることを確認したいと考えています。私は現在、Facebookから持っているものを取りました:
public function test_str_to_utf8()
{
// Make sure ASCII characters are ignored
$this->assertEquals( "this\x01 is a \x7f test string", str_to_utf8( "this\x01 is a \x7f test string" ) );
// Make sure UTF8 characters are ignored
$this->assertEquals( "\xc3\x9c \xc3\xbc \xe6\x9d\xb1!", str_to_utf8( "\xc3\x9c \xc3\xbc \xe6\x9d\xb1!" ) );
// Test long strings
#str_to_utf8( str_repeat( 'x', 1024 * 1024 ) );
$this->assertEquals( TRUE, TRUE );
// Test some invalid UTF8 to see if it is properly fixed
$input = "\xc3 this has \xe6\x9d some invalid utf8 \xe6";
$expect = "\xEF\xBF\xBD this has \xEF\xBF\xBD\xEF\xBF\xBD some invalid utf8 \xEF\xBF\xBD";
$this->assertEquals( $expect, str_to_utf8( $input ) );
}
それらは有効なテストケースですか?