2010-12-04 13:59:06 -05:00
|
|
|
/**
|
|
|
|
* Tests util.propParse
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Mike Gerwitz
|
|
|
|
*
|
|
|
|
* This file is part of ease.js.
|
|
|
|
*
|
|
|
|
* ease.js is free software: you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU Lesser 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 Lesser General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @author Mike Gerwitz
|
|
|
|
* @package test
|
|
|
|
*/
|
|
|
|
|
|
|
|
require( './common' );
|
|
|
|
|
2010-12-04 14:03:26 -05:00
|
|
|
var assert = require( 'assert' ),
|
|
|
|
util = require( '../lib/util' );
|
2010-12-04 13:59:06 -05:00
|
|
|
|
|
|
|
var data = {
|
|
|
|
// scalars (properties)
|
2010-12-04 14:05:56 -05:00
|
|
|
propStr: 'string',
|
|
|
|
propBool: true,
|
|
|
|
propInt: 1,
|
2010-12-04 13:59:06 -05:00
|
|
|
propFloat: 1.23,
|
|
|
|
|
|
|
|
// array (property)
|
|
|
|
propArray: [],
|
|
|
|
|
|
|
|
// object (property)
|
|
|
|
propObj: {},
|
|
|
|
|
2010-12-05 20:50:13 -05:00
|
|
|
// getter/setter
|
|
|
|
get someFoo() {},
|
|
|
|
set someFoo() {},
|
|
|
|
|
2010-12-04 13:59:06 -05:00
|
|
|
// concrete method
|
|
|
|
method: function() {},
|
2010-12-04 14:03:26 -05:00
|
|
|
|
|
|
|
// abstract method
|
|
|
|
abstractMethod: util.createAbstractMethod(),
|
2010-12-04 13:59:06 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-12-04 14:03:26 -05:00
|
|
|
var props = {},
|
|
|
|
methods = {},
|
2010-12-05 20:50:13 -05:00
|
|
|
amethods = {},
|
|
|
|
getters = {},
|
|
|
|
setters = {};
|
2010-12-04 13:59:06 -05:00
|
|
|
|
2010-12-04 14:03:26 -05:00
|
|
|
util.propParse( data, {
|
2010-12-04 13:59:06 -05:00
|
|
|
property: function( name, value )
|
|
|
|
{
|
|
|
|
props[ name ] = value;
|
|
|
|
},
|
|
|
|
|
|
|
|
// concrete method
|
|
|
|
method: function( name, method )
|
|
|
|
{
|
|
|
|
methods[ name ] = method;
|
|
|
|
},
|
2010-12-04 14:03:26 -05:00
|
|
|
|
|
|
|
abstractMethod: function( name, def )
|
|
|
|
{
|
|
|
|
amethods[ name ] = def;
|
2010-12-05 20:50:13 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getter: function( name, func )
|
|
|
|
{
|
|
|
|
getters[ name ] = func;
|
|
|
|
},
|
|
|
|
|
|
|
|
setter: function( name, func )
|
|
|
|
{
|
|
|
|
setters[ name ] = func;
|
|
|
|
},
|
2010-12-04 13:59:06 -05:00
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
// ensure properties were properly recognized
|
|
|
|
[ 'propStr', 'propBool', 'propInt', 'propFloat', 'propArray', 'propObj' ]
|
|
|
|
.forEach( function( item )
|
|
|
|
{
|
|
|
|
assert.equal(
|
|
|
|
props[ item ],
|
|
|
|
data[ item ],
|
|
|
|
"Property parser properly detects class properties"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
methods.method,
|
|
|
|
data.method,
|
2010-12-04 14:03:26 -05:00
|
|
|
"Property parser properly detects concrete methods"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
amethods.abstractMethod,
|
|
|
|
data.abstractMethod,
|
|
|
|
"Property parser properly detects abstract methods"
|
2010-12-04 13:59:06 -05:00
|
|
|
);
|
|
|
|
|
2010-12-05 20:50:13 -05:00
|
|
|
assert.equal(
|
|
|
|
getters.someFoo,
|
|
|
|
data.__lookupGetter__( 'someFoo' ),
|
|
|
|
"Property parser properly detects getters"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
setters.someFoo,
|
|
|
|
data.__lookupSetter__( 'someFoo' ),
|
|
|
|
"Property parser properly detects setters"
|
|
|
|
);
|
|
|
|
|