66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
#include <algorithm>
|
|
|
|
#include "TranslationUnitTest.hpp"
|
|
|
|
#include "string.hpp"
|
|
|
|
using namespace std;
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( TranslationUnitTest );
|
|
|
|
vector<string> splitFile(string filename){
|
|
ifstream fileStream(filename);
|
|
|
|
int currentLineNumber = 0;
|
|
string currentLine;
|
|
vector<string> lines;
|
|
while(getline(fileStream, currentLine)){
|
|
|
|
bool insideString = false;
|
|
|
|
int lineBegin = 0;
|
|
for(int i = 0; i<= currentLine.size(); i++){
|
|
if(i == currentLine.size() || (currentLine.at(i)== ':' && !insideString)){
|
|
string splittedLine = currentLine.substr(lineBegin, i - lineBegin);
|
|
splittedLine = Blang::string(splittedLine).trim();
|
|
if(!splittedLine.empty()) // Do not add if it's empty
|
|
lines.push_back(splittedLine);
|
|
lineBegin = i+1;
|
|
}else if(currentLine.at(i) == '\"'){
|
|
if(insideString){
|
|
insideString = false;
|
|
}else{
|
|
insideString = true;
|
|
}
|
|
}
|
|
}
|
|
currentLineNumber++;
|
|
}
|
|
|
|
fileStream.close();
|
|
return lines;
|
|
}
|
|
|
|
vector<string> loadFile(string filename){
|
|
ifstream fileStream(filename);
|
|
|
|
string currentLine;
|
|
vector<string> lines;
|
|
|
|
while(getline(fileStream, currentLine)){
|
|
lines.push_back(currentLine);
|
|
}
|
|
|
|
fileStream.close();
|
|
return lines;
|
|
}
|
|
|
|
void TranslationUnitTest::splitFileTest(){
|
|
vector<string> result = splitFile("splitTest1.bc");
|
|
vector<string> expected = loadFile("expectedTest1.bc");
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("Lines count mismatch",expected.size(), result.size());
|
|
|
|
for(int i = 0; i < expected.size(); i++)
|
|
CPPUNIT_ASSERT_EQUAL(expected[i], result[i]);
|
|
} |