Merge "mediawiki.language: Implement Language::listToText in JS"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 3 Sep 2014 09:36:53 +0000 (09:36 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 3 Sep 2014 09:36:53 +0000 (09:36 +0000)
1  2 
resources/Resources.php
tests/qunit/suites/resources/mediawiki/mediawiki.language.test.js

diff --combined resources/Resources.php
@@@ -920,10 -920,6 +920,10 @@@ return array
                'scripts' => 'resources/src/mediawiki/mediawiki.notify.js',
                'targets' => array( 'desktop', 'mobile' ),
        ),
 +      'mediawiki.pager.tablePager' => array(
 +              'styles' => 'resources/src/mediawiki/mediawiki.pager.tablePager.less',
 +              'position' => 'top',
 +      ),
        'mediawiki.searchSuggest' => array(
                'scripts' => 'resources/src/mediawiki/mediawiki.searchSuggest.js',
                'styles' => 'resources/src/mediawiki/mediawiki.searchSuggest.css',
                                'mediawiki.cldr',
                        ),
                'targets' => array( 'desktop', 'mobile' ),
+               'messages' => array(
+                       'and',
+                       'comma-separator',
+                       'word-separator'
+               ),
        ),
  
        'mediawiki.cldr' => array(
        /* MediaWiki Legacy */
  
        'mediawiki.legacy.ajax' => array(
 -              'scripts' => 'common/ajax.js',
 -              'remoteBasePath' => $GLOBALS['wgStylePath'],
 -              'localBasePath' => $GLOBALS['wgStyleDirectory'],
 +              'scripts' => 'resources/src/mediawiki.legacy/ajax.js',
                'dependencies' => array(
                        'mediawiki.util',
                        'mediawiki.legacy.wikibits',
                ),
 -              'position' => 'top', // Temporary hack for legacy support
 +              'position' => 'top',
        ),
        'mediawiki.legacy.commonPrint' => array(
 -              'styles' => array( 'common/commonPrint.css' => array( 'media' => 'print' ) ),
 -              'remoteBasePath' => $GLOBALS['wgStylePath'],
 -              'localBasePath' => $GLOBALS['wgStyleDirectory'],
 +              'styles' => array( 'resources/src/mediawiki.legacy/commonPrint.css' => array( 'media' => 'print' ) ),
        ),
        'mediawiki.legacy.protect' => array(
 -              'scripts' => 'common/protect.js',
 -              'remoteBasePath' => $GLOBALS['wgStylePath'],
 -              'localBasePath' => $GLOBALS['wgStyleDirectory'],
 +              'scripts' => 'resources/src/mediawiki.legacy/protect.js',
                'dependencies' => array(
                        'jquery.byteLimit',
                ),
        ),
        'mediawiki.legacy.shared' => array(
                // Used in the web installer. Test it after modifying this definition!
 -              'styles' => array( 'common/shared.css' => array( 'media' => 'screen' ) ),
 -              'remoteBasePath' => $GLOBALS['wgStylePath'],
 -              'localBasePath' => $GLOBALS['wgStyleDirectory'],
 +              'styles' => array( 'resources/src/mediawiki.legacy/shared.css' => array( 'media' => 'screen' ) ),
        ),
        'mediawiki.legacy.oldshared' => array(
 -              'styles' => array( 'common/oldshared.css' => array( 'media' => 'screen' ) ),
 -              'remoteBasePath' => $GLOBALS['wgStylePath'],
 -              'localBasePath' => $GLOBALS['wgStyleDirectory'],
 +              'styles' => array( 'resources/src/mediawiki.legacy/oldshared.css' => array( 'media' => 'screen' ) ),
        ),
        'mediawiki.legacy.upload' => array(
 -              'scripts' => 'common/upload.js',
 -              'remoteBasePath' => $GLOBALS['wgStylePath'],
 -              'localBasePath' => $GLOBALS['wgStyleDirectory'],
 +              'scripts' => 'resources/src/mediawiki.legacy/upload.js',
                'dependencies' => array(
                        'jquery.spinner',
                        'mediawiki.api',
                ),
        ),
        'mediawiki.legacy.wikibits' => array(
 -              'scripts' => 'common/wikibits.js',
 -              'remoteBasePath' => $GLOBALS['wgStylePath'],
 -              'localBasePath' => $GLOBALS['wgStyleDirectory'],
 +              'scripts' => 'resources/src/mediawiki.legacy/wikibits.js',
                'dependencies' => array(
                        'mediawiki.util',
                ),
                assert.equal( mw.language.getData( 'en', 'invalidkey' ), undefined, 'Getter setter test for mw.language with invalid key' );
        } );
  
 +      QUnit.test( 'mw.language.commafy test', 9, function ( assert ) {
 +              // Number grouping patterns are as per http://cldr.unicode.org/translation/number-patterns
 +              assert.equal( mw.language.commafy( 1234.567, '###0.#####' ), '1234.567', 'Pattern with no digit grouping separator defined' );
 +              assert.equal( mw.language.commafy( 123456789.567, '###0.#####' ), '123456789.567', 'Pattern with no digit grouping seperator defined, bigger decimal part' );
 +              assert.equal( mw.language.commafy( 0.567, '###0.#####' ), '0.567', 'Decimal part 0' );
 +              assert.equal( mw.language.commafy( '.567', '###0.#####' ), '0.567', 'Decimal part missing. replace with zero' );
 +              assert.equal( mw.language.commafy( 1234, '##,#0.#####' ), '12,34', 'Pattern with no fractional part' );
 +              assert.equal( mw.language.commafy( -1234.567, '###0.#####' ), '-1234.567', 'Negative number' );
 +              assert.equal( mw.language.commafy( -1234.567, '#,###.00' ), '-1,234.56', 'Fractional part bigger than pattern.' );
 +              assert.equal( mw.language.commafy( 123456789.567, '###,##0.00' ), '123,456,789.56', 'Decimal part as group of 3' );
 +              assert.equal( mw.language.commafy( 123456789.567, '###,###,#0.00' ), '1,234,567,89.56', 'Decimal part as group of 3 and last one 2' );
 +      } );
 +
        function grammarTest( langCode, test ) {
                // The test works only if the content language is opt.language
                // because it requires [lang].js to be loaded.
                        grammarTest( langCode, test );
                }
        } );
+       QUnit.test( 'List to text test', 4, function ( assert ) {
+               assert.equal( mw.language.listToText( [] ), '', 'Blank list' );
+               assert.equal( mw.language.listToText( ['a'] ), 'a', 'Single item' );
+               assert.equal( mw.language.listToText( ['a', 'b'] ), 'a and b', 'Two items' );
+               assert.equal( mw.language.listToText( ['a', 'b', 'c'] ), 'a, b and c', 'More than two items' );
+       } );
  }( mediaWiki, jQuery ) );