Skip to content

Commit

Permalink
Merge branch 't/12309'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Sep 4, 2014
2 parents ac30879 + 0b338f4 commit b60bb80
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
26 changes: 26 additions & 0 deletions tests/_benderjs/ckeditor/static/extensions.js
Expand Up @@ -80,6 +80,32 @@
}
};

/**
* Assert that expected value is in range (between min and max).
*
* @param {Number} expected
* @param {Number} min
* @param {Number} max
* @param {String} [message]
*/
bender.assert.isNumberInRange = function( expected, min, max, message ) {
YTest.Assert._increment();

YTest.Assert.isNumber( expected, 'Expected value should be number type.' );
YTest.Assert.isNumber( min, 'Min value should be number type.' );
YTest.Assert.isNumber( max, 'Max value should be number type.' );

if ( min >= max ) {
throw new YUITest.AssertionError( 'Min value is greater or equal than max.' );
}

if ( expected < min || expected > max ) {
throw new YUITest.ComparisonFailure(
YUITest.Assert._formatMessage( message ),
expected
);
}
};

// add support test ignore
YUITest.Ignore = function() {};
Expand Down
7 changes: 4 additions & 3 deletions tests/core/dom/element/element.js
Expand Up @@ -526,10 +526,11 @@ bender.test( appendDomObjectTests(
Y.one( '#DocPositionTarget' ).setXY( [ 350, 450 ] );
var pos = CKEDITOR.document.getById( 'DocPositionTarget' ).getDocumentPosition(),
x = Math.round( pos.x ),
y = Math.round( pos.y );
y = Math.round( pos.y ),
accOffset = 1;

assert.areEqual( 350, x, 'Position coordinates:x relative to document doesn\'t match.' );
assert.areEqual( 450, y, 'Position coordinates:y relative to document doesn\'t match.' );
assert.isNumberInRange( x, 350 - accOffset, 350 + accOffset, 'Position coordinates:x(350) relative to document doesn\'t match ' + x + ' with offset ' + accOffset + '.' );
assert.isNumberInRange( y, 450 - accOffset, 450 + accOffset, 'Position coordinates:y(450) relative to document doesn\'t match ' + y + 'with offset ' + accOffset + '.' );
} );
} );

Expand Down
45 changes: 45 additions & 0 deletions tests/utils/assert/isnumberinrange.js
@@ -0,0 +1,45 @@
/* bender-tags: editor,unit,utils */

( function () {
'use strict';

var assert = bender.assert;

bender.test( {
'test invalid arguments': function() {
// Invalid arguments.
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( 100, 102, 101 );
}, 'min > max' );
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( 101, 101, 101 );
}, 'min == max' );
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( null, 99, 101 );
}, 'expected not a number' );
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( 100, '99', 101 );
}, 'min not a number' );
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( 100, 100 );
}, 'max not a number' );
},

'test number not in range': function() {
// Number is not in range.
assert.throwsError( YUITest.ComparisonFailure, function() {
assert.isNumberInRange( 100, 101, 102 );
}, 'lower < min' );
assert.throwsError( YUITest.ComparisonFailure, function() {
assert.isNumberInRange( 100, 98, 99 );
}, 'expected > max' );
},

'test passing and passed assertions number increasing': function() {
// Number is in range.
assert.isNumberInRange( 100, 99, 101, '99 <= 100 <= 101' );
assert.isNumberInRange( 100, 100, 101, '100 <= 100 <= 101' );
assert.isNumberInRange( 100, 98, 100, '98 <= 100 <= 100' );
}
} );
} )();

0 comments on commit b60bb80

Please sign in to comment.