JavaScript-V8x-TestMoreish

 view release on metacpan or  search on metacpan

lib/JavaScript/V8x/TestMoreish/JS.pm  view on Meta::CPAN

        return this.test.like( got, match ) ?  { name: name } :
            this._gotExpectedFailure( got, match, name, "Value does not match regular expression" );
    };
	
    _TM._fail = function( name ) {
        return { name: name, error: "Failure" };
    };

//    _formatMessage : function (customMessage /*:String*/, defaultMessage /*:String*/) /*:String*/ {

//        var message = customMessage;
//        if (YAHOO.lang.isString(customMessage) && customMessage.length > 0){
//            return YAHOO.lang.substitute(customMessage, { message: defaultMessage });
//        } else {
//            return defaultMessage;
//        }        
//    },

//    getMessage : function () /*:String*/ {
//        return this.message + "\nExpected: " + this.expected + " (" + (typeof this.expected) + ")"  +
//            "\nActual:" + this.actual + " (" + (typeof this.actual) + ")";
//    }

    var _installTest = function( test ) {
		return function() {
            var tester = this['_' + test];
            var result = tester.apply( this, arguments );
            this._ok( result.error ? 0 : 1, result.name );
            if ( result.error ) {
                this._diag( result.error );
            }
            return result.error ? 0 : 1;
        };
    }

    // Public API

    _TM.diag = function() { this._diag.apply( this, arguments ) };

    var _test = [
        'areEqual',
        'areNotEqual',
        'areSame',
        'areNotSame',

        'isTrue',
        'isFalse',

        'isBoolean',
        'isFunction',
        'isNumber',
        'isObject',
        'isString',

        'like',

        'fail',
//        'isTypeOf',
//        'isArray',
//        'isInstanceOf',
//        'isNaN',
//        'isNotNaN',
//        'isNull',
//        'isNotNull',
//        'isUndefined',
//        'isNotUndefined'
    ];

    for (var ii = 0; ii < _test.length; ii++) {
        var name = _test[ii];
        _TM[name] = _installTest( name );
    }

})();

//    //-------------------------------------------------------------------------
//    // Boolean Assertion Methods
//    //-------------------------------------------------------------------------    
//    
//    /**
//     * Asserts that a value is false. This uses the triple equals sign
//     * so no type cohersion may occur.
//     * @param {Object} actual The actual value to test.
//     * @param {String} message (Optional) The message to display if the assertion fails.
//     * @method isFalse
//     * @static
//     */
//    isFalse : function (actual /*:Boolean*/, message /*:String*/) {
//        if (false !== actual) {
//            throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be false."), false, actual);
//        }
//    },
//    
//    /**
//     * Asserts that a value is true. This uses the triple equals sign
//     * so no type cohersion may occur.
//     * @param {Object} actual The actual value to test.
//     * @param {String} message (Optional) The message to display if the assertion fails.
//     * @method isTrue
//     * @static
//     */
//    isTrue : function (actual /*:Boolean*/, message /*:String*/) /*:Void*/ {
//        if (true !== actual) {
//            throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be true."), true, actual);
//        }

//    },
//    
//    //-------------------------------------------------------------------------
//    // Special Value Assertion Methods
//    //-------------------------------------------------------------------------    
//    
//    /**
//     * Asserts that a value is not a number.
//     * @param {Object} actual The value to test.
//     * @param {String} message (Optional) The message to display if the assertion fails.
//     * @method isNaN
//     * @static
//     */
//    isNaN : function (actual /*:Object*/, message /*:String*/) /*:Void*/{
//        if (!isNaN(actual)){
//            throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be NaN."), NaN, actual);
//        }    
//    },
//    
//    /**
//     * Asserts that a value is not the special NaN value.
//     * @param {Object} actual The value to test.
//     * @param {String} message (Optional) The message to display if the assertion fails.
//     * @method isNotNaN
//     * @static
//     */
//    isNotNaN : function (actual /*:Object*/, message /*:String*/) /*:Void*/{
//        if (isNaN(actual)){
//            throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Values should not be NaN."), NaN);
//        }    
//    },
//    
//    /**
//     * Asserts that a value is not null. This uses the triple equals sign
//     * so no type cohersion may occur.
//     * @param {Object} actual The actual value to test.
//     * @param {String} message (Optional) The message to display if the assertion fails.
//     * @method isNotNull
//     * @static
//     */
//    isNotNull : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
//        if (YAHOO.lang.isNull(actual)) {
//            throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Values should not be null."), null);
//        }
//    },

//    /**
//     * Asserts that a value is not undefined. This uses the triple equals sign
//     * so no type cohersion may occur.
//     * @param {Object} actual The actual value to test.
//     * @param {String} message (Optional) The message to display if the assertion fails.
//     * @method isNotUndefined
//     * @static
//     */
//    isNotUndefined : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
//        if (YAHOO.lang.isUndefined(actual)) {
//            throw new YAHOO.util.UnexpectedValue(this._formatMessage(message, "Value should not be undefined."), undefined);
//        }
//    },

//    /**
//     * Asserts that a value is null. This uses the triple equals sign
//     * so no type cohersion may occur.
//     * @param {Object} actual The actual value to test.
//     * @param {String} message (Optional) The message to display if the assertion fails.
//     * @method isNull
//     * @static
//     */
//    isNull : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
//        if (!YAHOO.lang.isNull(actual)) {
//            throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be null."), null, actual);
//        }
//    },
//        
//    /**
//     * Asserts that a value is undefined. This uses the triple equals sign
//     * so no type cohersion may occur.
//     * @param {Object} actual The actual value to test.
//     * @param {String} message (Optional) The message to display if the assertion fails.
//     * @method isUndefined
//     * @static
//     */
//    isUndefined : function (actual /*:Object*/, message /*:String*/) /*:Void*/ {
//        if (!YAHOO.lang.isUndefined(actual)) {
//            throw new YAHOO.util.ComparisonFailure(this._formatMessage(message, "Value should be undefined."), undefined, actual);
//        }
//    },    
//    
//    //--------------------------------------------------------------------------



( run in 0.956 second using v1.01-cache-2.11-cpan-99c4e6809bf )