From 42b52bb692f616a19b6f46c0610bd3156567c57f Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 20 Apr 2014 02:40:36 -0400 Subject: [PATCH] Exposing keyword bit values and bitmasks Available through property parser interface --- lib/prop_parser.js | 5 ++++ test/PropParserKeywordsTest.js | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/lib/prop_parser.js b/lib/prop_parser.js index 036d282..6938328 100644 --- a/lib/prop_parser.js +++ b/lib/prop_parser.js @@ -50,6 +50,11 @@ var _kmasks = { }; +// expose magic values +exports.kvals = _keywords; +exports.kmasks = _kmasks; + + /** * Parses property keywords * diff --git a/test/PropParserKeywordsTest.js b/test/PropParserKeywordsTest.js index 913dab6..9816c39 100644 --- a/test/PropParserKeywordsTest.js +++ b/test/PropParserKeywordsTest.js @@ -203,4 +203,53 @@ require( 'common' ).testCase( {} ); }, + + + /** + * As the keyword bit values are magic values, they must be exposed if + * the bitfield is to be used. The bitmasks are useful for quick and + * convenient checks in other parts of the framework. + */ + 'Exposes keyword bit values and masks': function() + { + this.assertOk( this.Sut.kvals ); + this.assertOk( this.Sut.kmasks ); + }, + + + /** + * Access modifier checks are common; ensure that the bitmask can + * properly check them all and does not check for any other keywords. + */ + 'Access modifier bitmask catches all access modifiers': function() + { + var kvals = this.Sut.kvals; + + // this can be easily checked by ensuring that the inclusive logical + // or of all the access modifier bits are no different than the mask + this.assertEqual( + this.Sut.kmasks.amods + | kvals[ 'public' ] + | kvals[ 'protected' ] + | kvals[ 'private' ], + this.Sut.kmasks.amods + ); + }, + + + /** + * Likewise, a virtual bitmask is also useful since it can be denoted by + * multiple keywords (abstract is implicitly virtual). + */ + 'Virtual bitmask catches abstract and virtual keywords': function() + { + var kvals = this.Sut.kvals; + + this.assertEqual( + this.Sut.kmasks[ 'virtual' ] + | kvals[ 'abstract' ] + | kvals[ 'virtual' ], + this.Sut.kmasks[ 'virtual' ] + ); + }, } );