2011-10-23 01:14:13 -04:00
|
|
|
/**
|
|
|
|
* Tests member builder validation rules
|
|
|
|
*
|
2013-12-20 01:11:26 -05:00
|
|
|
* Copyright (C) 2011, 2013 Mike Gerwitz
|
2011-10-23 01:14:13 -04:00
|
|
|
*
|
2013-12-22 09:37:21 -05:00
|
|
|
* This file is part of GNU ease.js.
|
2011-10-23 01:14:13 -04:00
|
|
|
*
|
|
|
|
* ease.js is free software: you can redistribute it and/or modify it under the
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* 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.
|
2011-10-23 01:14:13 -04:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2011-10-23 01:14:13 -04:00
|
|
|
*
|
Relicensed under the GPLv3+
This project was originally LGPLv+-licensed to encourage its use in a community
that is largely copyleft-phobic. After further reflection, that was a mistake,
as adoption is not the important factor here---software freedom is.
When submitting ease.js to the GNU project, it was asked if I would be willing
to relicense it under the GPLv3+; I agreed happily, because there is no reason
why we should provide proprietary software any sort of edge. Indeed, proprietary
JavaScript is a huge problem since it is automatically downloaded on the user's
PC generally without them even knowing, and is a current focus for the FSF. As
such, to remain firm in our stance against proprietary JavaScript, relicensing
made the most sense for GNU.
This is likely to upset current users of ease.js. I am not sure of their
number---I have only seen download counts periodically on npmjs.org---but I know
there are at least a small number. These users are free to continue using the
previous LGPL'd releases, but with the understanding that there will be no
further maintenance (not even bug fixes). If possible, users should use the
GPL-licensed versions and release their software as free software.
Here comes GNU ease.js.
2013-12-20 01:00:35 -05:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-10-23 01:14:13 -04:00
|
|
|
*
|
|
|
|
* @author Mike Gerwitz
|
|
|
|
*/
|
|
|
|
|
|
|
|
var shared = require( __dirname + '/inc-common' );
|
|
|
|
|
|
|
|
|
|
|
|
require( 'common' ).testCase(
|
|
|
|
{
|
|
|
|
caseSetUp: function()
|
|
|
|
{
|
2011-10-29 10:08:08 -04:00
|
|
|
var _self = this;
|
|
|
|
|
2011-12-06 18:26:28 -05:00
|
|
|
this.quickFailureTest = function()
|
|
|
|
{
|
|
|
|
shared.quickFailureTest.apply( _self, arguments );
|
|
|
|
};
|
2011-10-23 01:14:13 -04:00
|
|
|
|
|
|
|
this.quickKeywordPropTest = function( keywords, identifier, prev )
|
|
|
|
{
|
|
|
|
shared.quickKeywordTest.call( this,
|
|
|
|
'validateProperty', keywords, identifier, prev
|
|
|
|
);
|
|
|
|
};
|
2011-10-28 20:22:53 -04:00
|
|
|
|
2011-12-03 00:30:22 -05:00
|
|
|
this.quickVisChangeTest = function( start, override, failtest, failstr )
|
2011-10-28 20:22:53 -04:00
|
|
|
{
|
2011-10-29 10:08:08 -04:00
|
|
|
shared.quickVisChangeTest.call( _self, start, override, failtest,
|
|
|
|
function( name, startobj, overrideobj )
|
|
|
|
{
|
|
|
|
_self.sut.validateProperty(
|
|
|
|
name, 'bar', overrideobj,
|
|
|
|
{ member: 'foo' },
|
|
|
|
startobj
|
|
|
|
);
|
2011-12-03 00:30:22 -05:00
|
|
|
},
|
|
|
|
failstr
|
2011-10-29 10:08:08 -04:00
|
|
|
);
|
2011-10-28 20:22:53 -04:00
|
|
|
};
|
2011-10-23 01:14:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
setUp: function()
|
|
|
|
{
|
|
|
|
this.sut = this.require( 'MemberBuilderValidator' )();
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clearly, overriding a method with a property will have terrible
|
|
|
|
* polymorphic consequences on the resulting interface.
|
|
|
|
*/
|
|
|
|
'Cannot override method with property': function()
|
|
|
|
{
|
|
|
|
var name = 'foo',
|
|
|
|
_self = this;
|
|
|
|
|
|
|
|
this.quickFailureTest( name, 'property', function()
|
|
|
|
{
|
|
|
|
// attempt to override a method
|
|
|
|
_self.sut.validateProperty(
|
|
|
|
name, 'bar', {},
|
|
|
|
{ member: function() {} },
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The concept of an abstract property does not make sense, as properties
|
|
|
|
* simply represent placeholders for values. Whether or not they actually
|
|
|
|
* hold a value is irrelevant.
|
|
|
|
*/
|
|
|
|
'Cannot declare abstract property': function()
|
|
|
|
{
|
|
|
|
this.quickKeywordPropTest( [ 'abstract' ], 'abstract' );
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Properties, unlike methods, are virtual by default. If a property's value
|
|
|
|
* can be reassigned, why would a subclass not be able to reassign it? If
|
|
|
|
* one wishes to prevent a property's value from changing, they should use
|
|
|
|
* the visibility modifiers or declare the property as a constant.
|
|
|
|
*/
|
|
|
|
'Cannot declare virtual property': function()
|
|
|
|
{
|
|
|
|
this.quickKeywordPropTest( [ 'virtual' ], 'virtual' );
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declaring a constant as static would be redundant.
|
|
|
|
*/
|
|
|
|
'Cannot declare static const property': function()
|
|
|
|
{
|
|
|
|
this.quickKeywordPropTest( [ 'static', 'const' ], 'Static' );
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* While getters act as properties, it doesn't make sense to override
|
|
|
|
* getters/setters with properties because they are fundamentally different.
|
|
|
|
*/
|
|
|
|
'Cannot override getter/setter with property': function()
|
|
|
|
{
|
|
|
|
var name = 'foo',
|
|
|
|
_self = this;
|
|
|
|
|
|
|
|
// test getter
|
|
|
|
this.quickFailureTest( name, 'getter/setter', function()
|
|
|
|
{
|
|
|
|
_self.sut.validateProperty(
|
|
|
|
name, 'bar', {},
|
|
|
|
{ get: function() {} },
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
// test setter
|
|
|
|
this.quickFailureTest( name, 'getter/setter', function()
|
|
|
|
{
|
|
|
|
_self.sut.validateProperty(
|
|
|
|
name, 'bar', {},
|
|
|
|
{ set: function() {} },
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
},
|
2011-10-28 20:22:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* De-escalating the visibility of a property would alter the interface of a
|
|
|
|
* subtype, which would not be polymorphic.
|
|
|
|
*/
|
|
|
|
'Properties do not support visibility de-escalation': function()
|
|
|
|
{
|
|
|
|
this.quickVisChangeTest( 'public', 'protected', true );
|
|
|
|
this.quickVisChangeTest( 'protected', 'private', true );
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contrary to the above test, we have no such problem with visibility
|
|
|
|
* escalation.
|
|
|
|
*/
|
|
|
|
'Properties do support visibility escalation and equality': function()
|
|
|
|
{
|
|
|
|
var _self = this;
|
|
|
|
shared.visEscalationTest( function( cur )
|
|
|
|
{
|
|
|
|
_self.quickVisChangeTest( cur[ 0 ], cur[ 1 ], false );
|
|
|
|
} );
|
|
|
|
},
|
2011-12-03 00:30:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait - what? That doesn't make sense from an OOP perspective, now does
|
|
|
|
* it! Unfortunately, we're forced into this restriction in order to
|
|
|
|
* properly support fallback to pre-ES5 environments where the visibility
|
|
|
|
* object is a single layer, rather than three. With this impl, all members
|
|
|
|
* are public and private name conflicts would result in supertypes and
|
|
|
|
* subtypes altering eachothers' private members (see manual for more
|
|
|
|
* information).
|
|
|
|
*/
|
|
|
|
'Cannot redeclare private properties in subtypes': function()
|
|
|
|
{
|
|
|
|
var _self = this;
|
|
|
|
shared.privateNamingConflictTest( function( cur )
|
|
|
|
{
|
|
|
|
_self.quickVisChangeTest( cur[ 0 ], cur[ 1 ], true, 'conflict' );
|
|
|
|
} );
|
|
|
|
},
|
2011-10-23 01:14:13 -04:00
|
|
|
} );
|
|
|
|
|