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