https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114049
Revision: 114049
Author: nikola
Date: 2012-03-17 05:58:05 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
- Fix bug 35076
- More tests, test comments
Modified Paths:
--------------
branches/nikola/phase3/languages/LanguageConverter.php
branches/nikola/phase3/tests/phpunit/languages/LanguageSrTest.php
Modified: branches/nikola/phase3/languages/LanguageConverter.php
===================================================================
--- branches/nikola/phase3/languages/LanguageConverter.php 2012-03-17
05:54:24 UTC (rev 114048)
+++ branches/nikola/phase3/languages/LanguageConverter.php 2012-03-17
05:58:05 UTC (rev 114049)
@@ -576,7 +576,7 @@
*/
public function convertTo( $text, $variant ) {
global $wgDisableLangConversion;
- if ( $wgDisableLangConversion || $this->guessVariant( $text,
$variant ) ) {
+ if ( $wgDisableLangConversion ) {
return $text;
}
return $this->recursiveConvertTopLevel( $text, $variant );
@@ -595,18 +595,22 @@
$startPos = 0;
$out = '';
$length = strlen( $text );
+ $shouldConvert = !$this->guessVariant( $text, $variant );
+
while ( $startPos < $length ) {
$pos = strpos( $text, '-{', $startPos );
if ( $pos === false ) {
// No more markup, append final segment
- $out .= $this->autoConvert( substr( $text,
$startPos ), $variant );
+ $fragment = substr( $text, $startPos );
+ $out .= $shouldConvert? $this->autoConvert(
$fragment, $variant ): $fragment;
return $out;
}
// Markup found
// Append initial segment
- $out .= $this->autoConvert( substr( $text, $startPos,
$pos - $startPos ), $variant );
+ $fragment = substr( $text, $startPos, $pos - $startPos
);
+ $out .= $shouldConvert? $this->autoConvert( $fragment,
$variant ): $fragment;
// Advance position
$startPos = $pos;
Modified: branches/nikola/phase3/tests/phpunit/languages/LanguageSrTest.php
===================================================================
--- branches/nikola/phase3/tests/phpunit/languages/LanguageSrTest.php
2012-03-17 05:54:24 UTC (rev 114048)
+++ branches/nikola/phase3/tests/phpunit/languages/LanguageSrTest.php
2012-03-17 05:58:05 UTC (rev 114049)
@@ -65,18 +65,38 @@
* @author Nikola Smolenski
*/
function testConversionToCyrillic() {
+ //A simple convertion of Latin to Cyrillic
$this->assertEquals( 'абвг',
$this->convertToCyrillic( 'abvg' )
);
+ //Same as above, but assert that -{}-s must be removed and not
converted
+ $this->assertEquals( 'ljабnjвгdž',
+ $this->convertToCyrillic( '-{lj}-ab-{nj}-vg-{dž}-' )
+ );
+ //A simple convertion of Cyrillic to Cyrillic
$this->assertEquals( 'абвг',
$this->convertToCyrillic( 'абвг' )
);
+ //Same as above, but assert that -{}-s must be removed and not
converted
+ $this->assertEquals( 'ljабnjвгdž',
+ $this->convertToCyrillic( '-{lj}-аб-{nj}-вг-{dž}-' )
+ );
+ //This text has some Latin, but is recognized as Cyrillic, so
it should not be converted
$this->assertEquals( 'abvgшђжчћ',
$this->convertToCyrillic( 'abvgшђжчћ' )
);
+ //Same as above, but assert that -{}-s must be removed
+ $this->assertEquals( 'љabvgњшђжчћџ',
+ $this->convertToCyrillic( '-{љ}-abvg-{њ}-шђжчћ-{џ}-' )
+ );
+ //This text has some Cyrillic, but is recognized as Latin, so
it should be converted
$this->assertEquals( 'абвгшђжчћ',
$this->convertToCyrillic( 'абвгšđžčć' )
);
+ //Same as above, but assert that -{}-s must be removed and not
converted
+ $this->assertEquals( 'ljабвгnjшђжчћdž',
+ $this->convertToCyrillic( '-{lj}-абвг-{nj}-šđžčć-{dž}-'
)
+ );
// Roman numerals are not converted
$this->assertEquals( 'а I б II в III г IV шђжчћ',
$this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
@@ -84,15 +104,19 @@
}
function testConversionToLatin() {
+ //A simple convertion of Latin to Latin
$this->assertEquals( 'abcd',
$this->convertToLatin( 'abcd' )
);
+ //A simple convertion of Cyrillic to Latin
$this->assertEquals( 'abcd',
$this->convertToLatin( 'абцд' )
);
+ //This text has some Latin, but is recognized as Cyrillic, so
it should be converted
$this->assertEquals( 'abcdšđžčć',
$this->convertToLatin( 'abcdшђжчћ' )
);
+ //This text has some Cyrillic, but is recognized as Latin, so
it should not be converted
$this->assertEquals( 'абцдšđžčć',
$this->convertToLatin( 'абцдšđžčć' )
);
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs