3use Wikimedia\ScopedCallback;
14 if ( $this->normalizationDataProvider ) {
15 $this->normalizationDataProvider->destroy();
16 $this->normalizationDataProvider =
null;
22 return parent::getTestModules() + [
23 'UstringLibraryTests' => __DIR__ .
'/UstringLibraryTests.lua',
24 'UstringLibraryNormalizationTests' => __DIR__ .
'/UstringLibraryNormalizationTests.lua',
30 $this->assertTrue(
true );
32 $this->markTestSkipped( $err );
37 if ( !$this->normalizationDataProvider ) {
38 $this->normalizationDataProvider =
48 $this->luaTestName =
"UstringLibraryNormalization: $name";
51 $c2, $c2, $c2, $c4, $c4,
52 $c3, $c3, $c3, $c5, $c5,
53 $c4, $c4, $c4, $c4, $c4,
54 $c5, $c5, $c5, $c5, $c5,
56 foreach ( $expected as &$e ) {
57 $chars = array_values( unpack(
'N*', mb_convert_encoding( $e,
'UTF-32BE',
'UTF-8' ) ) );
58 foreach (
$chars as &$c ) {
59 $c = sprintf(
"%x", $c );
61 $e =
"$e\t" . implode(
"\t",
$chars );
63 $actual = $dataProvider->runNorm( $c1, $c2, $c3, $c4, $c5 );
64 $this->assertSame( $expected, $actual );
65 $this->luaTestName =
null;
73 foreach ( $ini as $key => $value ) {
74 $old = ini_set( $key, $value );
75 if ( $old ===
false ) {
76 $this->markTestSkipped(
"Failed to set ini setting $key = $value" );
78 $reset[] =
new ScopedCallback(
'ini_set', [ $key, $old ] );
81 $interpreter = $this->
getEngine()->getInterpreter();
82 $func = $interpreter->loadString(
'return mw.ustring.gsub( ... )',
'fortest' );
84 $interpreter->callFunction( $func, ...
$args );
85 $this->fail(
'Expected exception not thrown' );
87 $this->assertSame( $error, $e->getMessage() );
94 [
'pcre.backtrack_limit' => 10 ],
95 [
'zzzzzzzzzzzzzzzzzzzz',
'^(.-)[abc]*$',
'%1' ],
96 'Lua error: PCRE backtrack limit reached while matching pattern \'^(.-)[abc]*$\'.'
107 '1E0A 0323;1E0C 0307;0044 0323 0307;1E0C 0307;0044 0323 0307;',
112 if ( is_readable( __DIR__ .
'/NormalizationTest.txt' ) ) {
115 $message = wordwrap(
'Download the Unicode Normalization Test Suite from ' .
116 'http://unicode.org/Public/6.0.0/ucd/NormalizationTest.txt and save as ' .
117 __DIR__ .
'/NormalizationTest.txt to run normalization tests. Note that ' .
118 'running these tests takes quite some time.' );
123 parent::__construct(
$engine,
'UstringLibraryNormalizationTests' );
124 if ( self::available() ) {
125 $this->file = fopen( __DIR__ .
'/NormalizationTest.txt',
'r' );
132 fclose( $this->file );
148 $v = !feof( $this->file );
150 $v = $this->
key < count( self::$static );
160 $this->
current = [
null,
null,
null,
null,
null, null ];
161 while ( $this->
valid() ) {
163 $line = fgets( $this->file );
168 if ( preg_match(
'/^((?:[0-9A-F ]+;){5})/',
$line, $m ) ) {
169 $line = rtrim( $m[1],
';' );
171 foreach ( explode(
';',
$line ) as $field ) {
173 foreach ( explode(
' ', $field ) as $char ) {
174 $args[] = hexdec( $char );
177 $s = mb_convert_encoding(
$s,
'UTF-8',
'UTF-32BE' );
186 public function runNorm( $c1, $c2, $c3, $c4, $c5 ) {
187 return $this->engine->getInterpreter()->callFunction( $this->exports[
'run'],
188 $c1, $c2, $c3, $c4, $c5
This is the subclass for Lua library tests.
@covers Scribunto_LuaUstringLibrary
testUstringLibraryNormalizationTestsAvailable()
static providePCREErrors()
testPCREErrors( $ini, $args, $error)
@dataProvider providePCREErrors
provideUstringLibraryNormalizationTests()
$normalizationDataProvider
testUstringLibraryNormalizationTests( $name, $c1, $c2, $c3, $c4, $c5)
@dataProvider provideUstringLibraryNormalizationTests
runNorm( $c1, $c2, $c3, $c4, $c5)
static available(&$message=null)
if(PHP_SAPI !=='cli' &&PHP_SAPI !=='phpdbg' $chars)