2018-02-16 12:19:37 -05:00
|
|
|
/**
|
|
|
|
* Test case
|
|
|
|
*
|
2022-05-03 14:14:29 -04:00
|
|
|
* Copyright (C) 2014-2022 Ryan Specialty Group, LLC.
|
2018-02-16 12:19:37 -05:00
|
|
|
*
|
|
|
|
* This file is part of TAME.
|
|
|
|
*
|
|
|
|
* TAME is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const { Class } = require( 'easejs' );
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Class( 'TestCase',
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test case data
|
|
|
|
*
|
|
|
|
* @type {Object} test case data
|
|
|
|
*/
|
|
|
|
'private _caseData': {},
|
|
|
|
|
|
|
|
get description()
|
|
|
|
{
|
|
|
|
return this._caseData.description || "";
|
|
|
|
},
|
|
|
|
|
2020-03-09 12:21:32 -04:00
|
|
|
get allow_failures()
|
|
|
|
{
|
|
|
|
return this._caseData.allow_failures || false;
|
|
|
|
},
|
|
|
|
|
2018-02-16 12:19:37 -05:00
|
|
|
get data()
|
|
|
|
{
|
|
|
|
return this._caseData.data || {};
|
|
|
|
},
|
|
|
|
|
|
|
|
get expect()
|
|
|
|
{
|
|
|
|
return this._caseData.expect || {};
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
constructor( case_data )
|
|
|
|
{
|
|
|
|
this._caseData = case_data;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'public mapEachValue'( callback )
|
|
|
|
{
|
|
|
|
const [ new_data, new_expect ] = [ this.data, this.expect ].map( src =>
|
|
|
|
{
|
|
|
|
const new_src = {};
|
|
|
|
|
|
|
|
Object.keys( src ).forEach(
|
|
|
|
key => new_src[ key ] = this._visitDeep(
|
|
|
|
src[ key ],
|
|
|
|
callback
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return new_src;
|
|
|
|
} );
|
|
|
|
|
|
|
|
return module.exports( {
|
2020-03-09 12:21:32 -04:00
|
|
|
description: this.description,
|
|
|
|
allow_failures: this.allow_failures,
|
|
|
|
data: new_data,
|
|
|
|
expect: new_expect,
|
2018-02-16 12:19:37 -05:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively resolve constants
|
|
|
|
*
|
|
|
|
* Only scalars and arrays are supported
|
|
|
|
*
|
|
|
|
* @param {number|Array} input scalar or array of inputs
|
|
|
|
* @param {Object} consts constant mapping
|
|
|
|
*
|
|
|
|
* @return {number|Array} resolved value(s)
|
|
|
|
*/
|
|
|
|
'private _visitDeep'( val, callback )
|
|
|
|
{
|
|
|
|
if ( Array.isArray( val ) )
|
|
|
|
{
|
|
|
|
return val.map(
|
|
|
|
x => this._visitDeep( x, callback )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return callback( val );
|
|
|
|
}
|
|
|
|
} );
|