Merge pull request #59 from joakim-hove/wildcard-keywords

Wildcard keywords
This commit is contained in:
Kristian Flikka
2013-12-02 04:24:45 -08:00
15 changed files with 326 additions and 58 deletions

View File

@@ -14,6 +14,10 @@ add_executable(runParsePORO ParsePORO.cpp)
target_link_libraries(runParsePORO Parser ${Boost_LIBRARIES})
add_test(NAME runParsePORO WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runParsePORO)
add_executable(runParseTVDP ParseTVDP.cpp)
target_link_libraries(runParseTVDP Parser ${Boost_LIBRARIES})
add_test(NAME runParseTVDP WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runParseTVDP)
add_executable(runScheduleCreateFromDeck ScheduleCreateFromDeck.cpp)
target_link_libraries(runScheduleCreateFromDeck Parser ${Boost_LIBRARIES})
add_test(NAME runScheduleCreateFromDeck WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND runScheduleCreateFromDeck)

View File

@@ -50,8 +50,8 @@ ParserPtr createWWCTParser() {
BOOST_AUTO_TEST_CASE(parse_fileWithWWCTKeyword_deckReturned) {
boost::filesystem::path singleKeywordFile("testdata/integration_tests/wwct.data");
ParserPtr parser = createWWCTParser();
BOOST_CHECK( parser->hasKeyword("WWCT"));
BOOST_CHECK( parser->hasKeyword("SUMMARY"));
BOOST_CHECK( parser->canParseKeyword("WWCT"));
BOOST_CHECK( parser->canParseKeyword("SUMMARY"));
BOOST_CHECK_NO_THROW(DeckPtr deck = parser->parse(singleKeywordFile.string()));
}

View File

@@ -46,9 +46,9 @@ BOOST_AUTO_TEST_CASE( parse_ACTION_OK ) {
parser->addKeyword( DIMENS );
parser->addKeyword( THROW );
BOOST_REQUIRE( parser->hasKeyword( "DIMENS" ));
BOOST_REQUIRE( parser->hasKeyword( "WCONHIST" ));
BOOST_REQUIRE( parser->hasKeyword( "THROW" ));
BOOST_REQUIRE( parser->canParseKeyword( "DIMENS" ));
BOOST_REQUIRE( parser->canParseKeyword( "WCONHIST" ));
BOOST_REQUIRE( parser->canParseKeyword( "THROW" ));
BOOST_REQUIRE_THROW( parser->parse( actionFile2.string() , false) , std::invalid_argument );

View File

@@ -0,0 +1,47 @@
/*
Copyright 2013 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM 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.
OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_MODULE ParserTVPD
#include <vector>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
using namespace Opm;
BOOST_AUTO_TEST_CASE(ParseTVDP) {
ParserPtr parser(new Parser());
boost::filesystem::path poroFile("testdata/integration_tests/TVDP/TVDP1");
DeckPtr deck = parser->parse(poroFile.string());
BOOST_CHECK_EQUAL( false , deck->hasKeyword("TVDP*"));
BOOST_CHECK( deck->hasKeyword("TVDPA"));
BOOST_CHECK( deck->hasKeyword("TVDP1"));
BOOST_CHECK( deck->hasKeyword("TVDPXX"));
BOOST_CHECK( deck->hasKeyword("TVDPYY"));
}

View File

@@ -0,0 +1,46 @@
/*
Copyright 2013 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM 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.
OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_MODULE ParserTVPD
#include <vector>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
using namespace Opm;
BOOST_AUTO_TEST_CASE(AddDataKeywordFromJson_correctlyConfigured) {
ParserPtr parser(new Parser());
boost::filesystem::path poroFile("testdata/integration_tests/TVPD/TVPD1");
DeckPtr deck = parser->parse(poroFile.string());
BOOST_CHECK( deck->hasKeyword("TVDPA"));
BOOST_CHECK( deck->hasKeyword("TVDP1"));
BOOST_CHECK( deck->hasKeyword("TVDPXX"));
BOOST_CHECK( deck->hasKeyword("TVDPYY"));
}

View File

@@ -63,31 +63,82 @@ namespace Opm {
size_t Parser::size() const {
return m_parserKeywords.size();
}
void Parser::addKeyword(ParserKeywordConstPtr parserKeyword) {
if (hasKeyword(parserKeyword->getName()))
m_parserKeywords.erase(parserKeyword->getName());
m_parserKeywords.insert(std::make_pair(parserKeyword->getName(), parserKeyword));
const std::string& name = parserKeyword->getName();
dropKeyword( name );
m_parserKeywords.insert(std::make_pair(name, parserKeyword));
if (ParserKeyword::wildCardName(name))
m_wildCardKeywords.insert( std::make_pair(name , parserKeyword ));
}
ParserKeywordConstPtr Parser::matchingKeyword(const std::string& name) const {
std::map<std::string, ParserKeywordConstPtr>::const_iterator iter = m_wildCardKeywords.begin();
ParserKeywordConstPtr keyword;
while (true) {
if (iter == m_wildCardKeywords.end())
break;
if ((*iter).second->matches(name)) {
keyword = (*iter).second;
break;
}
++iter;
}
return keyword;
}
bool Parser::hasKeyword(const std::string& keyword) const {
return m_parserKeywords.find(keyword) != m_parserKeywords.end();
return (m_parserKeywords.find(keyword) != m_parserKeywords.end());
}
bool Parser::dropKeyword(const std::string& keyword) {
if (m_parserKeywords.erase( keyword ) == 1)
return true;
else
return false;
bool Parser::hasWildCardKeyword(const std::string& keyword) const {
return (m_wildCardKeywords.find(keyword) != m_parserKeywords.end());
}
bool Parser::canParseKeyword( const std::string& keyword) const {
if (hasKeyword(keyword))
return true;
else {
ParserKeywordConstPtr wildCardKeyword = matchingKeyword( keyword );
if (wildCardKeyword)
return true;
else
return false;
}
}
bool Parser::dropKeyword(const std::string& keyword) {
bool erase = (m_parserKeywords.erase( keyword ) == 1);
if (erase)
m_wildCardKeywords.erase( keyword );
return erase;
}
ParserKeywordConstPtr Parser::getKeyword(const std::string& keyword) const {
if (hasKeyword(keyword)) {
return m_parserKeywords.at(keyword);
} else {
ParserKeywordConstPtr wildCardKeyword = matchingKeyword( keyword );
if (wildCardKeyword)
return wildCardKeyword;
else
throw std::invalid_argument("Do not have parser keyword for parsing: " + keyword);
}
else
throw std::invalid_argument("Keyword: " + keyword + " does not exist");
}
@@ -117,9 +168,9 @@ namespace Opm {
} else {
if (verbose)
std::cout << rawKeyword->getKeywordName() << std::endl;
if (hasKeyword(rawKeyword->getKeywordName())) {
ParserKeywordConstPtr parserKeyword = m_parserKeywords.at(rawKeyword->getKeywordName());
if (canParseKeyword(rawKeyword->getKeywordName())) {
ParserKeywordConstPtr parserKeyword = getKeyword(rawKeyword->getKeywordName());
ParserKeywordActionEnum action = parserKeyword->getAction();
if (action == INTERNALIZE) {
DeckKeywordPtr deckKeyword = parserKeyword->parse(rawKeyword);
@@ -154,8 +205,8 @@ namespace Opm {
}
RawKeywordPtr Parser::createRawKeyword(const DeckConstPtr deck, const std::string& filename , size_t lineNR , const std::string& keywordString, bool strictParsing) const {
if (hasKeyword(keywordString)) {
ParserKeywordConstPtr parserKeyword = m_parserKeywords.find(keywordString)->second;
if (canParseKeyword(keywordString)) {
ParserKeywordConstPtr parserKeyword = getKeyword( keywordString );
ParserKeywordActionEnum action = parserKeyword->getAction();
if (action == THROW_EXCEPTION)
@@ -192,7 +243,7 @@ namespace Opm {
bool Parser::tryParseKeyword(const DeckConstPtr deck, const std::string& filename , size_t& lineNR , std::ifstream& inputstream, RawKeywordPtr& rawKeyword, bool strictParsing) const {
std::string line;
std::cout << "tryParse " << std::endl;
while (std::getline(inputstream, line)) {
std::string keywordString;
lineNR++;

View File

@@ -46,8 +46,8 @@ namespace Opm {
/// Method to add ParserKeyword instances, these holding type and size information about the keywords and their data.
void addKeyword(ParserKeywordConstPtr parserKeyword);
bool hasKeyword(const std::string& keyword) const;
bool dropKeyword(const std::string& keyword);
bool canParseKeyword( const std::string& keyword) const;
ParserKeywordConstPtr getKeyword(const std::string& keyword) const;
void loadKeywords(const Json::JsonObject& jsonKeywords);
@@ -57,6 +57,12 @@ namespace Opm {
size_t size() const;
private:
std::map<std::string, ParserKeywordConstPtr> m_parserKeywords;
std::map<std::string, ParserKeywordConstPtr> m_wildCardKeywords;
bool hasKeyword(const std::string& keyword) const;
bool hasWildCardKeyword(const std::string& keyword) const;
ParserKeywordConstPtr matchingKeyword(const std::string& keyword) const;
bool tryParseKeyword(const DeckConstPtr deck , const std::string& filename , size_t& lineNR , std::ifstream& inputstream , RawKeywordPtr& rawKeyword, bool strictParsing) const;
void parseFile(DeckPtr deck , const boost::filesystem::path& file, const boost::filesystem::path& rootPath, bool strictParsing) const;
RawKeywordPtr createRawKeyword(const DeckConstPtr deck , const std::string& filename , size_t lineNR , const std::string& keywordString, bool strictParsing) const;

View File

@@ -146,21 +146,48 @@ namespace Opm {
initSizeKeyword(sizeKeyword, sizeItem);
}
bool ParserKeyword::validName(const std::string& name) {
bool ParserKeyword::validNameStart(const std::string& name) {
if (name.length() > ParserConst::maxKeywordLength)
return false;
if (!isupper(name[0]))
return false;
return true;
}
for (unsigned int i = 1; i < name.length(); i++) {
bool ParserKeyword::wildCardName(const std::string& name) {
if (!validNameStart(name))
return false;
for (size_t i = 1; i < name.length(); i++) {
char c = name[i];
if (!(isupper(c) || isdigit(c)))
return false;
if (!(isupper(c) || isdigit(c))) {
if ((i == (name.length() - 1)) && (c == '*'))
return true;
else
return false;
}
}
return false;
}
bool ParserKeyword::validName(const std::string& name) {
if (!validNameStart(name))
return false;
for (size_t i = 1; i < name.length(); i++) {
char c = name[i];
if (!(isupper(c) || isdigit(c)))
return wildCardName(name);
}
return true;
}
void ParserKeyword::addItem(ParserItemConstPtr item) {
if (m_isDataKeyword)
throw std::invalid_argument("Keyword:" + getName() + " is already configured as data keyword - can not add more items.");
@@ -287,7 +314,7 @@ namespace Opm {
}
DeckKeywordPtr ParserKeyword::parse(RawKeywordConstPtr rawKeyword) const {
DeckKeywordPtr keyword(new DeckKeyword(getName()));
DeckKeywordPtr keyword(new DeckKeyword(rawKeyword->getKeywordName()));
for (size_t i = 0; i < rawKeyword->size(); i++) {
DeckRecordConstPtr deckRecord = m_record->parse(rawKeyword->getRecord(i));
keyword->addRecord(deckRecord);
@@ -318,6 +345,20 @@ namespace Opm {
return m_isDataKeyword;
}
bool ParserKeyword::matches(const std::string& keyword) const {
size_t cmpLength = m_name.find('*');
if (cmpLength == std::string::npos)
return (keyword == m_name);
else {
if (keyword.length() < cmpLength)
return false;
return (m_name.compare( 0 , cmpLength , keyword , 0 , cmpLength) == 0);
}
}
bool ParserKeyword::equal(const ParserKeyword& other) const {
if ((m_name == other.m_name) &&
(m_record->equal(*(other.m_record))) &&

View File

@@ -42,7 +42,9 @@ namespace Opm {
ParserKeyword(const Json::JsonObject& jsonConfig);
static bool validName(const std::string& name);
static bool wildCardName(const std::string& name);
bool matches(const std::string& keyword) const;
ParserRecordPtr getRecord() const;
const std::string& getName() const;
ParserKeywordActionEnum getAction() const;
@@ -71,6 +73,7 @@ namespace Opm {
bool m_isTableCollection;
ParserKeywordActionEnum m_action;
static bool validNameStart(const std::string& name);
void initData( const Json::JsonObject& jsonConfig );
void initSize( const Json::JsonObject& jsonConfig );
void initSizeKeyword( const std::string& sizeKeyword, const std::string& sizeItem);

View File

@@ -67,6 +67,16 @@ BOOST_AUTO_TEST_CASE(ParserKeyword_withOtherSize_SizeTypeOTHER) {
BOOST_AUTO_TEST_CASE(ParserKeyword_wildCardName) {
BOOST_CHECK_EQUAL( true , ParserKeyword::wildCardName("SUM*"));
BOOST_CHECK_EQUAL( false , ParserKeyword::wildCardName("SUM*X"));
BOOST_CHECK_EQUAL( false , ParserKeyword::wildCardName("sUM*"));
BOOST_CHECK_EQUAL( false , ParserKeyword::wildCardName("5UM*"));
BOOST_CHECK_EQUAL( true , ParserKeyword::wildCardName("U5M*"));
BOOST_CHECK_EQUAL( false , ParserKeyword::wildCardName("ABCDEFGH*"));
}
BOOST_AUTO_TEST_CASE(ParserKeyword_validName) {
BOOST_CHECK_EQUAL( true , ParserKeyword::validName("SUMMARY"));
BOOST_CHECK_EQUAL( false , ParserKeyword::validName("MixeCase"));
@@ -75,6 +85,19 @@ BOOST_AUTO_TEST_CASE(ParserKeyword_validName) {
BOOST_CHECK_EQUAL( false , ParserKeyword::validName("88STRING"));
BOOST_CHECK_EQUAL( false , ParserKeyword::validName("KEY.EXT"));
BOOST_CHECK_EQUAL( false , ParserKeyword::validName("STRING~"));
BOOST_CHECK_EQUAL( true , ParserKeyword::validName("TVDP*"));
BOOST_CHECK_EQUAL( false , ParserKeyword::validName("*"));
}
BOOST_AUTO_TEST_CASE(ParserKeywordMathces) {
ParserKeyword parserKeyword("TVDP*" , (size_t) 1);
BOOST_CHECK_EQUAL( true , parserKeyword.matches("TVDP"));
BOOST_CHECK_EQUAL( true , parserKeyword.matches("TVDPX"));
BOOST_CHECK_EQUAL( true , parserKeyword.matches("TVDPXY"));
BOOST_CHECK_EQUAL( false , parserKeyword.matches("TVD"));
BOOST_CHECK_EQUAL( false , parserKeyword.matches("ATVDP"));
}

View File

@@ -52,10 +52,10 @@ BOOST_AUTO_TEST_CASE(addKeyword_keyword_doesntfail) {
}
BOOST_AUTO_TEST_CASE(hasKeyword_hasKeyword_returnstrue) {
BOOST_AUTO_TEST_CASE(canParseKeyword_canParseKeyword_returnstrue) {
ParserPtr parser(new Parser());
parser->addKeyword(ParserKeywordConstPtr(new ParserKeyword("FJAS")));
BOOST_CHECK(parser->hasKeyword("FJAS"));
BOOST_CHECK(parser->canParseKeyword("FJAS"));
}
@@ -77,11 +77,11 @@ BOOST_AUTO_TEST_CASE(getKeyword_hasnotkeyword_throws) {
/************************ JSON config related tests **********************'*/
BOOST_AUTO_TEST_CASE(addKeywordJSON_hasKeyword_returnstrue) {
BOOST_AUTO_TEST_CASE(addKeywordJSON_canParseKeyword_returnstrue) {
ParserPtr parser(new Parser());
Json::JsonObject jsonConfig("{\"name\": \"BPR\", \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"FLOAT\"}]}");
parser->addKeyword(ParserKeywordConstPtr(new ParserKeyword( jsonConfig )));
BOOST_CHECK(parser->hasKeyword("BPR"));
BOOST_CHECK(parser->canParseKeyword("BPR"));
}
@@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(addKeywordJSON_size_isObject_allGood) {
ParserPtr parser(new Parser());
Json::JsonObject jsonConfig("{\"name\": \"EQUIXL\", \"size\" : {\"keyword\":\"EQLDIMS\" , \"item\" : \"NTEQUL\"}, \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"FLOAT\"}]}");
parser->addKeyword(ParserKeywordConstPtr(new ParserKeyword( jsonConfig )));
BOOST_CHECK(parser->hasKeyword("EQUIXL"));
BOOST_CHECK(parser->canParseKeyword("EQUIXL"));
}
@@ -103,12 +103,12 @@ BOOST_AUTO_TEST_CASE(loadKeywordsJSON_notArray_throw) {
BOOST_AUTO_TEST_CASE(loadKeywordsJSON_hasKeyword_returnstrue) {
BOOST_AUTO_TEST_CASE(loadKeywordsJSON_canParseKeyword_returnstrue) {
ParserPtr parser(new Parser());
Json::JsonObject jsonConfig( "[{\"name\" : \"BPR\" , \"size\" : 100, \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"FLOAT\"}]}]");
parser->loadKeywords( jsonConfig );
BOOST_CHECK(parser->hasKeyword("BPR"));
BOOST_CHECK(parser->canParseKeyword("BPR"));
}
@@ -124,9 +124,9 @@ BOOST_AUTO_TEST_CASE(loadKeywordsJSON_manyKeywords_returnstrue) {
Json::JsonObject jsonConfig( "[{\"name\" : \"BPR\" , \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"FLOAT\"}]}, {\"name\" : \"WWCT\", \"size\" : 0} , {\"name\" : \"EQUIL\" , \"size\" : 0}]");
parser->loadKeywords( jsonConfig );
BOOST_CHECK(parser->hasKeyword("BPR"));
BOOST_CHECK(parser->hasKeyword("WWCT"));
BOOST_CHECK(parser->hasKeyword("EQUIL"));
BOOST_CHECK(parser->canParseKeyword("BPR"));
BOOST_CHECK(parser->canParseKeyword("WWCT"));
BOOST_CHECK(parser->canParseKeyword("EQUIL"));
BOOST_CHECK_EQUAL( 3U , parser->size() );
}
@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(loadKeywordFromFile_validKeyword_returnsTrueHasKeyword) {
boost::filesystem::path configFile("testdata/json/BPR");
BOOST_CHECK_EQUAL( true , parser->loadKeywordFromFile( configFile ));
BOOST_CHECK_EQUAL( 1U , parser->size() );
BOOST_CHECK_EQUAL( true , parser->hasKeyword("BPR") );
BOOST_CHECK_EQUAL( true , parser->canParseKeyword("BPR") );
}
@@ -175,12 +175,12 @@ BOOST_AUTO_TEST_CASE(loadConfigFromDirectory_directoryDoesNotexist_throws) {
BOOST_AUTO_TEST_CASE(loadConfigFromDirectory_notRecursive_allNames) {
ParserPtr parser(new Parser(false));
BOOST_CHECK_EQUAL(false , parser->hasKeyword("BPR"));
BOOST_CHECK_EQUAL(false , parser->canParseKeyword("BPR"));
boost::filesystem::path configPath("testdata/config/directory1");
BOOST_CHECK_NO_THROW(parser->loadKeywordsFromDirectory( configPath, false , false));
BOOST_CHECK(parser->hasKeyword("WWCT"));
BOOST_CHECK_EQUAL(true , parser->hasKeyword("BPR"));
BOOST_CHECK_EQUAL(false , parser->hasKeyword("DIMENS"));
BOOST_CHECK(parser->canParseKeyword("WWCT"));
BOOST_CHECK_EQUAL(true , parser->canParseKeyword("BPR"));
BOOST_CHECK_EQUAL(false , parser->canParseKeyword("DIMENS"));
}
@@ -188,31 +188,31 @@ BOOST_AUTO_TEST_CASE(loadConfigFromDirectory_notRecursive_strictNames) {
ParserPtr parser(new Parser(false));
boost::filesystem::path configPath("testdata/config/directory1");
BOOST_CHECK_NO_THROW(parser->loadKeywordsFromDirectory( configPath, false , true ));
BOOST_CHECK(parser->hasKeyword("WWCT"));
BOOST_CHECK_EQUAL(false , parser->hasKeyword("BPR"));
BOOST_CHECK_EQUAL(false , parser->hasKeyword("DIMENS"));
BOOST_CHECK(parser->canParseKeyword("WWCT"));
BOOST_CHECK_EQUAL(false , parser->canParseKeyword("BPR"));
BOOST_CHECK_EQUAL(false , parser->canParseKeyword("DIMENS"));
}
BOOST_AUTO_TEST_CASE(loadConfigFromDirectory_Recursive_allNames) {
ParserPtr parser(new Parser(false));
BOOST_CHECK_EQUAL(false , parser->hasKeyword("BPR"));
BOOST_CHECK_EQUAL(false , parser->canParseKeyword("BPR"));
boost::filesystem::path configPath("testdata/config/directory1");
BOOST_CHECK_NO_THROW(parser->loadKeywordsFromDirectory( configPath, true, false));
BOOST_CHECK(parser->hasKeyword("WWCT"));
BOOST_CHECK_EQUAL(true , parser->hasKeyword("BPR"));
BOOST_CHECK_EQUAL(true , parser->hasKeyword("DIMENS"));
BOOST_CHECK(parser->canParseKeyword("WWCT"));
BOOST_CHECK_EQUAL(true , parser->canParseKeyword("BPR"));
BOOST_CHECK_EQUAL(true , parser->canParseKeyword("DIMENS"));
}
BOOST_AUTO_TEST_CASE(loadConfigFromDirectory_default) {
ParserPtr parser(new Parser(false));
BOOST_CHECK_EQUAL(false , parser->hasKeyword("BPR"));
BOOST_CHECK_EQUAL(false , parser->canParseKeyword("BPR"));
boost::filesystem::path configPath("testdata/config/directory1");
BOOST_CHECK_NO_THROW(parser->loadKeywordsFromDirectory( configPath ));
BOOST_CHECK(parser->hasKeyword("WWCT"));
BOOST_CHECK_EQUAL(false , parser->hasKeyword("BPR"));
BOOST_CHECK_EQUAL(true , parser->hasKeyword("DIMENS"));
BOOST_CHECK(parser->canParseKeyword("WWCT"));
BOOST_CHECK_EQUAL(false , parser->canParseKeyword("BPR"));
BOOST_CHECK_EQUAL(true , parser->canParseKeyword("DIMENS"));
}
@@ -221,6 +221,10 @@ BOOST_AUTO_TEST_CASE(DropKeyword) {
BOOST_CHECK_EQUAL(false , parser->dropKeyword("DoesNotHaveThis"));
BOOST_CHECK_EQUAL(true , parser->dropKeyword("BPR"));
BOOST_CHECK_EQUAL(false , parser->dropKeyword("BPR"));
BOOST_CHECK_EQUAL(true , parser->canParseKeyword("TVDPX"));
BOOST_CHECK_EQUAL(true , parser->dropKeyword("TVDP*"));
BOOST_CHECK_EQUAL(false , parser->canParseKeyword("TVDPX"));
}
@@ -237,6 +241,24 @@ BOOST_AUTO_TEST_CASE(ReplaceKeyword) {
}
BOOST_AUTO_TEST_CASE(WildCardTest) {
ParserPtr parser(new Parser());
BOOST_CHECK_EQUAL(true , parser->canParseKeyword("TVDP*"));
BOOST_CHECK_EQUAL(true , parser->canParseKeyword("TVDP"));
BOOST_CHECK_EQUAL(true , parser->canParseKeyword("TVDPXXX"));
BOOST_CHECK_EQUAL(false , parser->canParseKeyword("TVD"));
ParserKeywordConstPtr keyword1 = parser->getKeyword("TVDP*");
ParserKeywordConstPtr keyword2 = parser->getKeyword("TVDP");
ParserKeywordConstPtr keyword3 = parser->getKeyword("TVDPXXX");
BOOST_CHECK_EQUAL( keyword1 , keyword2 );
BOOST_CHECK_EQUAL( keyword1 , keyword3 );
}
/***************** Simple Int parsing ********************************/
ParserKeywordPtr setupParserKeywordInt(std::string name, int numberOfItems) {