From 7070e5525482be2e39abef0483da3a04b7a1a1d1 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Fri, 18 Mar 2011 23:55:56 -0400 Subject: [PATCH] Added test to ensure same visibility de-escalation rules apply to concrete implementations of Interface methods --- test/test-class-visibility.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/test/test-class-visibility.js b/test/test-class-visibility.js index cfc38e3..b8854d9 100644 --- a/test/test-class-visibility.js +++ b/test/test-class-visibility.js @@ -22,10 +22,11 @@ * @package test */ -var common = require( './common' ), - assert = require( 'assert' ), - Class = common.require( 'class' ), - propobj = common.require( 'propobj' ), +var common = require( './common' ), + assert = require( 'assert' ), + Class = common.require( 'class' ), + Interface = common.require( 'interface' ), + propobj = common.require( 'propobj' ), pub = 'foo', prot = 'bar', @@ -638,3 +639,21 @@ var common = require( './common' ), ); } )(); + +/** + * Concrete implementations of interfaces should have to follow the same + * visibility de-escalation rules as defined in the above tests (otherwise, that + * defeats the purpose of an interface). In other words, they must be public. + */ +( function testVisibilityDeescalationRulesApplyToInterfaces() +{ + assert.throws( function() + { + Class.implement( Interface( { 'abstract public foo': [] } ) ).extend( + { + // should throw an exception; visibility de-escalation + 'protected foo': function() {}, + } ); + }, Error, "Cannot de-escalate visibility for interface members" ); +} )(); +