5fae06556019405d909c10c469bb2b46b9acab96
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.mwExtension.test.js
1 ( function ( $ ) {
2 QUnit.module( 'jquery.mwExtension', QUnit.newMwEnvironment() );
3
4 QUnit.test( 'String functions', 7, function ( assert ) {
5 assert.equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
6 assert.equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
7 assert.equal( $.ucFirst( 'foo' ), 'Foo', 'ucFirst' );
8
9 assert.equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
10 '<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
11 assert.equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
12 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
13 assert.equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
14 'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
15 assert.equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
16 } );
17
18 QUnit.test( 'Is functions', 15, function ( assert ) {
19 assert.strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
20 'isDomElement: #qunit-header Node' );
21 assert.strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
22 'isDomElement: #random-name (null)' );
23 assert.strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
24 'isDomElement: getElementsByTagName Array' );
25 assert.strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
26 'isDomElement: getElementsByTagName(..)[0] Node' );
27 assert.strictEqual( $.isDomElement( $( 'div' ) ), false,
28 'isDomElement: jQuery object' );
29 assert.strictEqual( $.isDomElement( $( 'div' ).get( 0 ) ), true,
30 'isDomElement: jQuery object > Get node' );
31 assert.strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
32 'isDomElement: createElement' );
33 assert.strictEqual( $.isDomElement( { foo: 1 } ), false,
34 'isDomElement: Object' );
35
36 assert.strictEqual( $.isEmpty( 'string' ), false, 'isEmpty: "string"' );
37 assert.strictEqual( $.isEmpty( '0' ), true, 'isEmpty: "0"' );
38 assert.strictEqual( $.isEmpty( '' ), true, 'isEmpty: ""' );
39 assert.strictEqual( $.isEmpty( 1 ), false, 'isEmpty: 1' );
40 assert.strictEqual( $.isEmpty( [] ), true, 'isEmpty: []' );
41 assert.strictEqual( $.isEmpty( {} ), true, 'isEmpty: {}' );
42
43 // Documented behaviour
44 assert.strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmpty: { length: 0 }' );
45 } );
46
47 QUnit.test( 'Comparison functions', 5, function ( assert ) {
48 assert.ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, 'a', [], [2, 'b'] ] ),
49 'compareArray: Two deep arrays that are excactly the same' );
50 assert.ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
51
52 assert.ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
53 assert.ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
54 assert.ok( !$.compareObject( { bar: true }, { baz: false } ),
55 'compareObject: Two different objects (false)' );
56 } );
57 }( jQuery ) );