From ba1c3044de06bb190536b94fcaa69bda0bbf053e Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 19 Jan 2014 12:03:20 -0500 Subject: [PATCH] Moved test-prop_parser-parse-keywords into suite as PropParserKeywordsTest --- test/PropParserKeywordsTest.js | 144 ++++++++++++++++++++++++ test/test-prop_parser-parse-keywords.js | 90 --------------- 2 files changed, 144 insertions(+), 90 deletions(-) create mode 100644 test/PropParserKeywordsTest.js delete mode 100644 test/test-prop_parser-parse-keywords.js diff --git a/test/PropParserKeywordsTest.js b/test/PropParserKeywordsTest.js new file mode 100644 index 0000000..8178f9d --- /dev/null +++ b/test/PropParserKeywordsTest.js @@ -0,0 +1,144 @@ +/** + * Tests property keyword parser + * + * Copyright (C) 2010, 2011, 2013 Mike Gerwitz + * + * This file is part of GNU ease.js. + * + * ease.js 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 . + */ + +require( 'common' ).testCase( +{ + caseSetUp: function() + { + this.Sut = this.require( 'prop_parser' ); + }, + + + setUp: function() + { + // pre-parsed test data + this.ptest = this.Sut.parseKeywords( + 'virtual static abstract foo' + ); + }, + + + /** + * The intended name of the field is the last word in the string; + * everything else is a keyword. + */ + 'Retrieves field name void of keywords': function() + { + this.assertEqual( this.ptest.name, 'foo' ); + }, + + + /** + * Complements above test. + */ + 'Retrieves all keywords': function() + { + var keywords = this.ptest.keywords; + + // reserved words are quoted for environments that do not follow + // ECMAScript's requirement of treating anything after a `.' as a + // field + this.assertOk( keywords['virtual'] ); + this.assertOk( keywords['static'] ); + this.assertOk( keywords['abstract'] ); + }, + + + /** + * This is more of a sanity check than anything---it really should never + * happen unless someone has been drinking heavily. + */ + 'Does not include keywords not explicitly provided': function() + { + var keywords = this.ptest.keywords; + + delete keywords['virtual']; + delete keywords['static']; + delete keywords['abstract']; + + // there should be no other keywords + for ( var k in keywords ) + { + this.assertFail( "Someone has been drinking: " + k ); + } + + // if we've gotten to this point, then we're good + this.assertOk( true ); + }, + + + /** + * Sounds like a good April Fool's joke. + */ + 'Accepts all valid keywords': function() + { + var parse = this.Sut.parseKeywords; + + this.assertDoesNotThrow( function() + { + // Odd seeing these all together, isn't it? Note that this is + // not at all valid, but the prop parser doesn't care what + // appears together. + parse( + 'public protected private ' + + 'virtual abstract override ' + + 'static const proxy ' + + 'var' + ); + }, Error ); + }, + + + /** + * In an effort to prevent unnecessary bugs, notify the user when they + * use a keyword that is not recognized; this may be a typo, + * misunderstanding of the API, or differences between versions of + * ease.js. + */ + 'Does not accept unknown keywords': function() + { + var parse = this.Sut.parseKeywords; + + var oddword = 'foobunny', + oddname = 'moobunny'; + + try + { + // remember, the last part of the string is the var name and is + // not considered to be a keyword + parse( oddword + ' ' + oddname ); + } + catch ( e ) + { + this.assertOk( e.message.search( oddword ) !== -1, + "Error message contains unrecognized keyword" + ); + + this.assertOk( e.message.search( oddname ) !== -1, + "Error message contains name" + ); + + return; + } + + this.assertFail( "Should not permit unknown keywords" ); + }, +} ); diff --git a/test/test-prop_parser-parse-keywords.js b/test/test-prop_parser-parse-keywords.js deleted file mode 100644 index 81cd8a2..0000000 --- a/test/test-prop_parser-parse-keywords.js +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Tests property keyword parser - * - * Copyright (C) 2010, 2011, 2013 Mike Gerwitz - * - * This file is part of GNU ease.js. - * - * ease.js 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 . - */ - -var common = require( './common' ), - assert = require( 'assert' ), - parse = common.require( 'prop_parser' ).parseKeywords, - - data = parse( 'virtual static abstract foo' ), - keywords = data.keywords -; - - -( function testProperlyRetrievesName() -{ - assert.equal( - data.name, - 'foo', - "Property keyword parser properly retrieves name" - ); -} )(); - - -( function testProperlyRetrievesAllKeywords() -{ - assert.ok( - ( ( keywords['virtual'] === true ) - && ( keywords['static'] === true ) - && ( keywords['abstract'] === true ) - ), - "Property keyword parser properly retrieves all keywords" - ); -} )(); - - -/** - * In an effort to prevent unnecessary bugs, notify the user when they use a - * keyword that is not recognized. - */ -( function testOnlyPermitsKnownKeywords() -{ - assert.doesNotThrow( function() - { - // Odd seeing these all together, isn't it? Note that this is not at all - // valid, but the prop parser doesn't care what appears together. - parse( 'public protected private static virtual abstract const var' ); - }, Error, "Known keywords are permitted by the parser" ); - - var oddword = 'foobunny', - oddname = 'moobunny'; - - try - { - // remember, the last part of the string is the var name and is not - // considered to be a keyword - parse( oddword + ' ' + oddname ); - } - catch ( e ) - { - assert.ok( e.message.search( oddword ) !== -1, - "Error message contains unrecognized keyword" - ); - - assert.ok( e.message.search( oddname ) !== -1, - "Error message contains name" - ); - - return; - } - - assert.fail( "Should not permit unknown keywords" ); -} )(); -