summaryrefslogtreecommitdiff
path: root/www/wiki/tests/qunit/suites/resources/mediawiki/mediawiki.RegExp.test.js
blob: 4e15cf011581f0fdc64b24ab3facfe4c79a58805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
( function ( mw ) {
	QUnit.module( 'mediawiki.RegExp' );

	QUnit.test( 'escape', function ( assert ) {
		var specials, normal;

		specials = [
			'\\',
			'{',
			'}',
			'(',
			')',
			'[',
			']',
			'|',
			'.',
			'?',
			'*',
			'+',
			'-',
			'^',
			'$'
		];

		normal = [
			'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
			'abcdefghijklmnopqrstuvwxyz',
			'0123456789'
		].join( '' );

		specials.forEach( function ( str ) {
			assert.propEqual( str.match( new RegExp( mw.RegExp.escape( str ) ) ), [ str ], 'Match ' + str );
		} );

		assert.equal( mw.RegExp.escape( normal ), normal, 'Alphanumerals are left alone' );
	} );

}( mediaWiki ) );