Merge "output: Narrow Title type hint to LinkTarget"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.util.test.js
index 3679ed7..a05b50b 100644 (file)
        QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment( {
                setup: function () {
                        $.fn.updateTooltipAccessKeys.setTestMode( true );
+                       this.origConfig = mw.util.setOptionsForTest( {
+                               FragmentMode: [ 'legacy', 'html5' ],
+                               LoadScript: '/w/load.php'
+                       } );
                },
                teardown: function () {
                        $.fn.updateTooltipAccessKeys.setTestMode( false );
-                       mw.util.resetOptionsForTest();
+                       mw.util.setOptionsForTest( this.origConfig );
                },
                messages: {
                        // Used by accessKeyLabel in test for addPortletLink
                        assert.strictEqual( util.isIPv6Address( ipCase[ 1 ] ), ipCase[ 0 ], ipCase[ 2 ] );
                } );
        } );
+
+       QUnit.test( 'escapeRegExp', function ( assert ) {
+               var specials, normal;
+
+               specials = [
+                       '\\',
+                       '{',
+                       '}',
+                       '(',
+                       ')',
+                       '[',
+                       ']',
+                       '|',
+                       '.',
+                       '?',
+                       '*',
+                       '+',
+                       '-',
+                       '^',
+                       '$'
+               ];
+
+               normal = [
+                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
+                       'abcdefghijklmnopqrstuvwxyz',
+                       '0123456789'
+               ].join( '' );
+
+               specials.forEach( function ( str ) {
+                       assert.propEqual( str.match( new RegExp( mw.util.escapeRegExp( str ) ) ), [ str ], 'Match ' + str );
+               } );
+
+               assert.strictEqual( mw.util.escapeRegExp( normal ), normal, 'Alphanumerals are left alone' );
+       } );
+
+       QUnit.test( 'debounce', function ( assert ) {
+               var fn,
+                       q = [],
+                       done = assert.async();
+
+               fn = mw.util.debounce( 0, function ( data ) {
+                       q.push( data );
+               } );
+
+               fn( 1 );
+               fn( 2 );
+               fn( 3 );
+
+               setTimeout( function () {
+                       assert.deepEqual(
+                               q,
+                               [ 3 ],
+                               'Last one ran'
+                       );
+                       done();
+               } );
+       } );
 }() );