Splitting records with string_view; test updates
The splitting of RawRecords into individual symbols uses string_view. Also updates tests since RawRecord now assumes that the record string it receives is complete and does *not* contain the terminating slash.
This commit is contained in:
@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(get_byNameNonExisting_throws) {
|
||||
BOOST_AUTO_TEST_CASE(StringsWithSpaceOK) {
|
||||
ParserStringItemPtr itemString(new ParserStringItem(std::string("STRINGITEM1")));
|
||||
ParserRecordPtr record1(new ParserRecord());
|
||||
RawRecord rawRecord( " ' VALUE ' /" );
|
||||
RawRecord rawRecord( " ' VALUE ' " );
|
||||
ParseContext parseContext;
|
||||
record1->addItem( itemString );
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE(Initialize_Default_String) {
|
||||
BOOST_AUTO_TEST_CASE(scan_PreMatureTerminator_defaultUsed) {
|
||||
ParserIntItem itemInt(std::string("ITEM2"), 123);
|
||||
|
||||
RawRecord rawRecord1( "/" );
|
||||
RawRecord rawRecord1( "" );
|
||||
const auto defaulted = itemInt.scan(rawRecord1);
|
||||
|
||||
BOOST_CHECK(defaulted.defaultApplied(0));
|
||||
@@ -315,7 +315,7 @@ BOOST_AUTO_TEST_CASE(Scan_All_CorrectIntSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemInt("ITEM", sizeType);
|
||||
|
||||
RawRecord rawRecord( "100 443 10*77 10*1 25/" );
|
||||
RawRecord rawRecord( "100 443 10*77 10*1 25" );
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(23U, deckIntItem.size());
|
||||
BOOST_CHECK_EQUAL(77, deckIntItem.get< int >(3));
|
||||
@@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(Scan_All_WithDefaults) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemInt("ITEM", sizeType);
|
||||
|
||||
RawRecord rawRecord( "100 10* 10*1 25/" );
|
||||
RawRecord rawRecord( "100 10* 10*1 25" );
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(22U, deckIntItem.size());
|
||||
BOOST_CHECK(!deckIntItem.defaultApplied(0));
|
||||
@@ -341,7 +341,7 @@ BOOST_AUTO_TEST_CASE(Scan_All_WithDefaults) {
|
||||
BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) {
|
||||
ParserIntItem itemInt(std::string("ITEM2"));
|
||||
|
||||
RawRecord rawRecord("100 44.3 'Heisann' /" );
|
||||
RawRecord rawRecord("100 44.3 'Heisann'" );
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(100, deckIntItem.get< int >(0));
|
||||
}
|
||||
@@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(Scan_SeveralInts_CorrectIntsSetInDeckItem) {
|
||||
ParserIntItem itemInt2(std::string("ITEM2"));
|
||||
ParserIntItem itemInt3(std::string("ITEM3"));
|
||||
|
||||
RawRecord rawRecord( "100 443 338932 222.33 'Heisann' /" );
|
||||
RawRecord rawRecord( "100 443 338932 222.33 'Heisann' " );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(100, deckIntItem1.get< int >(0));
|
||||
|
||||
@@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE(Scan_Multiplier_CorrectIntsSetInDeckItem) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemInt("ITEM2", sizeType);
|
||||
|
||||
RawRecord rawRecord( "3*4 /" );
|
||||
RawRecord rawRecord( "3*4 " );
|
||||
const auto deckIntItem = itemInt.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(0));
|
||||
BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(1));
|
||||
@@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(Scan_StarNoMultiplier_ExceptionThrown) {
|
||||
ParserItemSizeEnum sizeType = SINGLE;
|
||||
ParserIntItem itemInt("ITEM2", sizeType , 100);
|
||||
|
||||
RawRecord rawRecord( "*45 /" );
|
||||
RawRecord rawRecord( "*45 " );
|
||||
BOOST_CHECK_THROW(itemInt.scan(rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleItems_CorrectIntsSetInDeckItem) {
|
||||
ParserIntItem itemInt1(std::string("ITEM1"));
|
||||
ParserIntItem itemInt2(std::string("ITEM2"));
|
||||
|
||||
RawRecord rawRecord( "10 20 /" );
|
||||
RawRecord rawRecord( "10 20" );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
const auto deckIntItem2 = itemInt2.scan(rawRecord);
|
||||
|
||||
@@ -401,7 +401,7 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleDefault_CorrectIntsSetInDeckItem) {
|
||||
ParserIntItem itemInt1("ITEM1", 10);
|
||||
ParserIntItem itemInt2("ITEM2", 20);
|
||||
|
||||
RawRecord rawRecord( "* * /" );
|
||||
RawRecord rawRecord( "* * " );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
const auto deckIntItem2 = itemInt2.scan(rawRecord);
|
||||
|
||||
@@ -413,7 +413,7 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) {
|
||||
ParserIntItem itemInt1("ITEM1", 10);
|
||||
ParserIntItem itemInt2("ITEM2", 20);
|
||||
|
||||
RawRecord rawRecord( "2*30/" );
|
||||
RawRecord rawRecord( "2*30" );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
const auto deckIntItem2 = itemInt2.scan(rawRecord);
|
||||
|
||||
@@ -424,14 +424,14 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) {
|
||||
BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplier_Throw) {
|
||||
ParserIntItem itemInt1("ITEM1" , 10);
|
||||
|
||||
RawRecord rawRecord( "2.10*30/" );
|
||||
RawRecord rawRecord( "2.10*30" );
|
||||
BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplierChar_Throw) {
|
||||
ParserIntItem itemInt1("ITEM1", 10);
|
||||
|
||||
RawRecord rawRecord( "210X30/" );
|
||||
RawRecord rawRecord( "210X30" );
|
||||
BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument);
|
||||
}
|
||||
|
||||
@@ -439,7 +439,7 @@ BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault_CorrectIntsSetInDeckItem
|
||||
ParserIntItem itemInt1("ITEM1", 10);
|
||||
ParserIntItem itemInt2("ITEM2", 20);
|
||||
|
||||
RawRecord rawRecord( "2*/" );
|
||||
RawRecord rawRecord( "2*" );
|
||||
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
||||
const auto deckIntItem2 = itemInt2.scan(rawRecord);
|
||||
|
||||
@@ -501,24 +501,24 @@ BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefaultInvalid_thro
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_defaultvalue_defaultset) {
|
||||
ParserStringItem itemString(std::string("ITEM1") , "DEFAULT");
|
||||
RawRecord rawRecord( "'1*'/" );
|
||||
RawRecord rawRecord( "'1*'" );
|
||||
BOOST_CHECK_EQUAL("1*", itemString.scan( rawRecord ).get< std::string >(0) );
|
||||
|
||||
RawRecord rawRecord1( "13*/" );
|
||||
RawRecord rawRecord1( "13*" );
|
||||
BOOST_CHECK_EQUAL("DEFAULT" , itemString.scan( rawRecord1 ).get< std::string >(0) );
|
||||
|
||||
RawRecord rawRecord2( "*/" );
|
||||
RawRecord rawRecord2( "*" );
|
||||
BOOST_CHECK_EQUAL("DEFAULT", itemString.scan( rawRecord2 ).get< std::string >(0) );
|
||||
|
||||
ParserStringItem itemStringDefaultChanged("ITEM2", "SPECIAL");
|
||||
RawRecord rawRecord3( "*/" );
|
||||
RawRecord rawRecord3( "*" );
|
||||
BOOST_CHECK_EQUAL("SPECIAL", itemStringDefaultChanged.scan( rawRecord3 ).get< std::string >(0) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserStringItem itemString("ITEMWITHMANY", sizeType);
|
||||
RawRecord rawRecord( "'WELL1' FISK BANAN 3*X OPPLEGG_FOR_DATAANALYSE 'Foo$*!% BAR' /" );
|
||||
RawRecord rawRecord( "'WELL1' FISK BANAN 3*X OPPLEGG_FOR_DATAANALYSE 'Foo$*!% BAR' " );
|
||||
const auto deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(8U, deckItem.size());
|
||||
|
||||
@@ -535,7 +535,7 @@ BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) {
|
||||
BOOST_AUTO_TEST_CASE(scan_all_withdefaults) {
|
||||
ParserItemSizeEnum sizeType = ALL;
|
||||
ParserIntItem itemString("ITEMWITHMANY", sizeType);
|
||||
RawRecord rawRecord( "10*1 10* 10*2 /" );
|
||||
RawRecord rawRecord( "10*1 10* 10*2 " );
|
||||
const auto deckItem = itemString.scan(rawRecord);
|
||||
|
||||
BOOST_CHECK_EQUAL(30U, deckItem.size());
|
||||
@@ -558,7 +558,7 @@ BOOST_AUTO_TEST_CASE(scan_all_withdefaults) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scan_single_dataCorrect) {
|
||||
ParserStringItem itemString(std::string("ITEM1"));
|
||||
RawRecord rawRecord( "'WELL1' 'WELL2' /" );
|
||||
RawRecord rawRecord( "'WELL1' 'WELL2'" );
|
||||
const auto deckItem = itemString.scan(rawRecord);
|
||||
BOOST_CHECK_EQUAL(1U, deckItem.size());
|
||||
BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0));
|
||||
@@ -576,7 +576,7 @@ BOOST_AUTO_TEST_CASE(scan_singleWithMixedRecord_dataCorrect) {
|
||||
|
||||
/******************String and int**********************/
|
||||
BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) {
|
||||
RawRecord rawRecord( "'WELL1' 2 2 2*3 /" );
|
||||
RawRecord rawRecord( "'WELL1' 2 2 2*3" );
|
||||
|
||||
ParserItemSizeEnum sizeTypeItemBoxed = ALL;
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) {
|
||||
parserRecord->addItem(itemK);
|
||||
|
||||
ParseContext parseContext;
|
||||
RawRecord rawRecord( "3 3 /" );
|
||||
RawRecord rawRecord( "3 3 " );
|
||||
// no default specified for the third item, record can be parsed just fine but trying
|
||||
// to access the data will raise an exception...
|
||||
BOOST_CHECK_NO_THROW(parserRecord->parse(parseContext , rawRecord));
|
||||
|
||||
@@ -33,16 +33,15 @@ using namespace std;
|
||||
|
||||
namespace Opm {
|
||||
|
||||
static inline std::string::const_iterator first_nonspace (
|
||||
std::string::const_iterator begin,
|
||||
std::string::const_iterator end ) {
|
||||
template< typename Itr >
|
||||
static inline Itr first_nonspace( Itr begin, Itr end ) {
|
||||
return std::find_if_not( begin, end, RawConsts::is_separator );
|
||||
}
|
||||
|
||||
static std::deque< string_view > splitSingleRecordString( const string_view& record ) {
|
||||
static std::deque< string_view > splitSingleRecordString( const string_view& line ) {
|
||||
|
||||
std::deque< string_view > dst;
|
||||
string_view record( rec );
|
||||
string_view record( line );
|
||||
|
||||
for( auto current = first_nonspace( record.begin(), record.end() );
|
||||
current != record.end();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RawRecordGetRecordsCorrectElementsReturned) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 "));
|
||||
|
||||
BOOST_CHECK_EQUAL((unsigned) 4, record->size());
|
||||
|
||||
@@ -42,13 +42,11 @@ BOOST_AUTO_TEST_CASE(RawRecordIsCompleteRecordCompleteRecordReturnsTrue) {
|
||||
BOOST_AUTO_TEST_CASE(RawRecordIsCompleteRecordInCompleteRecordReturnsFalse) {
|
||||
bool isComplete = Opm::RawRecord::isTerminatedRecordString("'NODIR ' 'REVERS' 1 20 ");
|
||||
BOOST_CHECK_EQUAL(false, isComplete);
|
||||
isComplete = Opm::RawRecord::isTerminatedRecordString("'NODIR ' 'REVERS 1 20 /");
|
||||
BOOST_CHECK_EQUAL(false, isComplete);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Rawrecord_OperatorThis_OK) {
|
||||
Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 /");
|
||||
Opm::RawRecordPtr recordPtr(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
Opm::RawRecord record(" 'NODIR ' 'REVERS' 1 20 ");
|
||||
Opm::RawRecordPtr recordPtr(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 "));
|
||||
|
||||
BOOST_CHECK_EQUAL("'NODIR '", record.getItem(0));
|
||||
BOOST_CHECK_EQUAL("'REVERS'", record.getItem(1));
|
||||
@@ -61,7 +59,7 @@ BOOST_AUTO_TEST_CASE(Rawrecord_OperatorThis_OK) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Rawrecord_PushFront_OK) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 "));
|
||||
record->push_front("String2");
|
||||
record->push_front("String1");
|
||||
|
||||
@@ -71,7 +69,7 @@ BOOST_AUTO_TEST_CASE(Rawrecord_PushFront_OK) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Rawrecord_size_OK) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 /"));
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" 'NODIR ' 'REVERS' 1 20 "));
|
||||
|
||||
BOOST_CHECK_EQUAL(4U, record->size());
|
||||
record->push_front("String2");
|
||||
@@ -80,17 +78,17 @@ BOOST_AUTO_TEST_CASE(Rawrecord_size_OK) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Rawrecord_sizeEmpty_OK) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord("/"));
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(""));
|
||||
BOOST_CHECK_EQUAL(0U, record->size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Rawrecord_spaceOnlyEmpty_OK) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" /"));
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord(" "));
|
||||
BOOST_CHECK_EQUAL(0U, record->size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Rawrecord_noFileAndKeywordGiven_EmptyStringUsed) {
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord("32 33 /"));
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord("32 33 "));
|
||||
BOOST_CHECK_EQUAL("", record->getKeywordName());
|
||||
BOOST_CHECK_EQUAL("", record->getFileName());
|
||||
}
|
||||
@@ -98,7 +96,7 @@ BOOST_AUTO_TEST_CASE(Rawrecord_noFileAndKeywordGiven_EmptyStringUsed) {
|
||||
BOOST_AUTO_TEST_CASE(Rawrecord_FileAndKeywordGiven_CorrectStringsReturned) {
|
||||
const std::string fileName = "/this/is/it";
|
||||
const std::string keywordName = "KEYWD";
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord("32 33 /", fileName, keywordName));
|
||||
Opm::RawRecordPtr record(new Opm::RawRecord("32 33 ", fileName, keywordName));
|
||||
BOOST_CHECK_EQUAL(keywordName, record->getKeywordName());
|
||||
BOOST_CHECK_EQUAL(fileName, record->getFileName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user