[DEV] better brace generating

This commit is contained in:
Edouard DUPIN 2018-01-01 04:05:20 +01:00
parent 7dfafbefdd
commit f110a0ba66
6 changed files with 558 additions and 108 deletions

View File

@ -107,7 +107,12 @@ estyle::BraceProperty::BraceProperty() :
outNewLineAfter(false),
outSpaceBefore(false),
outSpaceAfter(false),
single(false) {
oneLineIfSingleMaxSize(-1),
single(false),
singleInNewLine(false),
singleInSpace(false),
singleOutNewLine(false),
singleOutSpace(false) {
}
estyle::BraceProperty::BraceProperty(class estyle::Generator* _generator, const etk::String& _typeName, bool _allowSingle):
@ -119,11 +124,27 @@ estyle::BraceProperty::BraceProperty(class estyle::Generator* _generator, const
outNewLineAfter(_generator, "brace-" + _typeName + "-out-new-line-after", false, "Set a new line after the input brace"),
outSpaceBefore(_generator, "brace-" + _typeName + "-out-space-before", false, "Set a space before the input brace (if not already present)"),
outSpaceAfter(_generator, "brace-" + _typeName + "-out-space-after", false, "Set a space after the input brace (if not already present)"),
oneLineIfSingleMaxSize((_allowSingle==true?
etk::move(eproperty::Value<int32_t>(_generator, "brace-" + _typeName + "-single-one-line-size-max", -1, "Set i a single line if the size if < XXX (-1 to disable)")):
etk::move(eproperty::Value<int32_t>(-1)) )),
single((_allowSingle==true?
etk::move(eproperty::Value<bool>(_generator, "brace-" + _typeName + "-single", false, "remove or add brace if only 1 action is present.")):
etk::move(eproperty::Value<bool>(false)) )),
singleInNewLine((_allowSingle==true?
etk::move(eproperty::Value<bool>(_generator, "brace-" + _typeName + "-single-in-new-line", false, "Set new line before action.")):
etk::move(eproperty::Value<bool>(false)) )),
singleInSpace((_allowSingle==true?
etk::move(eproperty::Value<bool>(_generator, "brace-" + _typeName + "-single-in-space", false, "Set Space before action.")):
etk::move(eproperty::Value<bool>(false)) )),
singleOutNewLine((_allowSingle==true?
etk::move(eproperty::Value<bool>(_generator, "brace-" + _typeName + "-single-out-new-line", false, "Set new line after action.")):
etk::move(eproperty::Value<bool>(false)) )),
singleOutSpace((_allowSingle==true?
etk::move(eproperty::Value<bool>(_generator, "brace-" + _typeName + "-single-out-space", false, "Set space after action.")):
etk::move(eproperty::Value<bool>(false)) )) {
}
estyle::BraceProperty::BraceProperty(estyle::BraceProperty&& _obj) :
inNewLineBefore(etk::move(_obj.inNewLineBefore)),
inNewLineAfter(etk::move(_obj.inNewLineAfter)),
@ -133,7 +154,12 @@ estyle::BraceProperty::BraceProperty(estyle::BraceProperty&& _obj) :
outNewLineAfter(etk::move(_obj.outNewLineAfter)),
outSpaceBefore(etk::move(_obj.outSpaceBefore)),
outSpaceAfter(etk::move(_obj.outSpaceAfter)),
single(etk::move(_obj.single)) {
oneLineIfSingleMaxSize(etk::move(_obj.oneLineIfSingleMaxSize)),
single(etk::move(_obj.single)),
singleInNewLine(etk::move(_obj.singleInNewLine)),
singleInSpace(etk::move(_obj.singleInSpace)),
singleOutNewLine(etk::move(_obj.singleOutNewLine)),
singleOutSpace(etk::move(_obj.singleOutSpace)) {
}
@ -146,7 +172,12 @@ estyle::BraceProperty& estyle::BraceProperty::operator=(BraceProperty&& _obj) {
outNewLineAfter = etk::move(_obj.outNewLineAfter);
outSpaceBefore = etk::move(_obj.outSpaceBefore);
outSpaceAfter = etk::move(_obj.outSpaceAfter);
oneLineIfSingleMaxSize = etk::move(_obj.oneLineIfSingleMaxSize);
single = etk::move(_obj.single);
singleInNewLine = etk::move(_obj.singleInNewLine);
singleInSpace = etk::move(_obj.singleInSpace);
singleOutNewLine = etk::move(_obj.singleOutNewLine);
singleOutSpace = etk::move(_obj.singleOutSpace);
return *this;
}
@ -165,7 +196,8 @@ estyle::Generator::Generator():
propertyIndentWithTabulation(this, "indent-with-tabs", true, "true: indent with tabs: '\\t', false indent win space:' '"),
propertyIndentSize(this, "indent-size", 4, "default 4 sapce in one tabulation indentation"),
propertyDoxygenOneLine(this, "doxygen-1-line-type", true, "true: single line doxygen comment is done with '//!', false '///'"),
propertyDoxygenMultipleLine(this, "doxygen-N-line-type", DOXYGEN_MULTI_LINE__NORMAL, "0: /** */ ...") {
propertyDoxygenMultipleLine(this, "doxygen-N-line-type", DOXYGEN_MULTI_LINE__NORMAL, "0: /** */ ..."),
propertyForConditionMultiLineBigSize(this, "for-condition-multi-line-big-size", 80, "If the condition inside for (...;...;...) if biger than XX char") {
setPropertyDoxygenMultiLine(propertyDoxygenMultipleLine);
propertyBrace.set("if", etk::move(estyle::BraceProperty(this, "if")));
propertyBrace.set("else", etk::move(estyle::BraceProperty(this, "else")));
@ -212,6 +244,11 @@ etk::String estyle::Generator::getDoxygenNLine(const etk::String& _data) {
void estyle::Generator::addNewLine() {
while ( ( m_output.back() == ' '
|| m_output.back() == '\t')
&& m_output.size()>0) {
m_output.popBack();
}
if (m_output.size() == 0) {
return;
}
@ -259,7 +296,14 @@ void estyle::Generator::addIndent() {
}
}
void estyle::Generator::addSpace() {
void estyle::Generator::addSpace(bool _force) {
if (_force == false) {
while ( ( m_output.back() == ' '
|| m_output.back() == '\t')
&& m_output.size()>0) {
m_output.popBack();
}
}
if (m_output.size() == 0) {
return;
}
@ -535,6 +579,7 @@ int32_t estyle::Generator::process(int32_t _startId,
m_output += "for ";
typePush("for");
offsetPush(4);
bool errorOccured = false;
// TODO : do this ==> not implemented
for (int64_t jjj=iii+1; jjj<m_lexer.size(); ++jjj) {
enum estyle::lexer::tocken elem = m_lexer.getTocken(jjj);
@ -542,12 +587,62 @@ int32_t estyle::Generator::process(int32_t _startId,
// OK ==> normal case ...
} else if (elem == estyle::lexer::PARENTHESE_IN) {
// find condition section ...
iii = generateCondition(jjj);
int64_t lastElementCondition = endOfSection(jjj);
// now we need to count the number of actions ... must be 3 inside (A;B;C)
int32_t nbAction = countCurrentAction(jjj, lastElementCondition);
if (nbAction != 2) {
ESTYLE_ERROR("Get not enought action in 'for' " << nbAction << " != 2 (action is ended with a ';' element");
typePop();
errorOccured = true;
break;
}
int32_t rawSize = countRawSize(jjj+1, lastElementCondition);
int64_t endSectionA = endOfAction(jjj);
int32_t nbElementSectionA = endSectionA - (jjj+1);
int64_t endSectionB = endOfAction(endSectionA);
int32_t nbElementSectionB = endSectionB - (endSectionA+1);
int32_t nbElementSectionC = lastElementCondition - (endSectionB+1);
if ( nbElementSectionA == 0
&& nbElementSectionB == 0
&& nbElementSectionC == 0) {
m_output += "(;;)";
} else {
m_output += "(";
// write section A
process(jjj+1, endSectionA);
m_output += ";";
ESTYLE_WARNING("big size: " << propertyForConditionMultiLineBigSize.get() << " <= " << rawSize);
if (propertyForConditionMultiLineBigSize.get() <= rawSize) {
addNewLine();
addIndent();
} else {
m_output += " ";
}
// write section B
process(endSectionA+1, endSectionB);
m_output += ";";
if (propertyForConditionMultiLineBigSize.get() <= rawSize) {
addNewLine();
addIndent();
} else {
m_output += " ";
}
// Write section C
process(endSectionB+1, lastElementCondition);
m_output += ")";
}
iii = lastElementCondition;
break;
} else {
ESTYLE_ERROR("Get 'for' without '(' element");
typePop();
errorOccured = true;
break;
}
}
if (errorOccured == true) {
continue;
}
offsetPop();
bool needBrace = false;
bool haveBrace = false;
@ -557,7 +652,8 @@ int32_t estyle::Generator::process(int32_t _startId,
if (nextIs(iii+1, estyle::lexer::BRACE_IN) == true) {
haveBrace = true;
// no need to add one ...
int32_t countAction = countCurrent(iii+1, estyle::lexer::tocken::SEMICOLON);
int32_t countAction = countCurrent(iii+1, m_lexer.size(), estyle::lexer::tocken::SEMICOLON);
ESTYLE_ERROR("nbAction = " << countAction);
if (countAction != 1) {
needBrace = true;
}
@ -577,7 +673,8 @@ int32_t estyle::Generator::process(int32_t _startId,
typePop();
continue;
}
if (elem == estyle::lexer::RESERVED_IF) {
if ( elem == estyle::lexer::RESERVED_IF
|| elem == estyle::lexer::RESERVED_WHILE) {
addNewLineIfSemiColon();
addSpace();
m_output += "if ";
@ -597,6 +694,8 @@ int32_t estyle::Generator::process(int32_t _startId,
break;
} else {
ESTYLE_ERROR("Get 'if' without '(' element");
typePop();
continue;
}
}
offsetPop();
@ -608,7 +707,7 @@ int32_t estyle::Generator::process(int32_t _startId,
if (nextIs(iii+1, estyle::lexer::BRACE_IN) == true) {
haveBrace = true;
// no need to add one ...
int32_t countAction = countCurrent(iii+1, estyle::lexer::tocken::SEMICOLON);
int32_t countAction = countCurrent(iii+1, m_lexer.size(), estyle::lexer::tocken::SEMICOLON);
if (countAction != 1) {
needBrace = true;
}
@ -619,7 +718,10 @@ int32_t estyle::Generator::process(int32_t _startId,
int32_t sectionEnd = endOfAction(iii+1);
subGenerationStop = sectionEnd+1;
}
iii = generateBrace(subGenerationStart, subGenerationStop, needBrace, true);
iii = generateBrace(subGenerationStart,
subGenerationStop,
needBrace,
elem == estyle::lexer::RESERVED_IF);
if (haveBrace == true) {
iii--;
} else {
@ -644,7 +746,7 @@ int32_t estyle::Generator::process(int32_t _startId,
int32_t subGenerationStop = iii+1;
if (nextIs(iii+1, estyle::lexer::BRACE_IN) == true) {
haveBrace = true;
int32_t countAction = countCurrent(iii+1, estyle::lexer::tocken::SEMICOLON);
int32_t countAction = countCurrent(iii+1, m_lexer.size(), estyle::lexer::tocken::SEMICOLON);
if (countAction != 1) {
needBrace = true;
}
@ -718,29 +820,49 @@ int64_t estyle::Generator::generateBrace(int64_t _start, int64_t _stop, bool _ne
ESTYLE_ERROR(" outSpaceAfter " << propertyBrace[m_type].outSpaceAfter.get());
ESTYLE_ERROR(" outNewLineAfter " << propertyBrace[m_type].outNewLineAfter.get());
*/
int32_t rawSize = countRawSize(_start, _stop);
bool removeNewLine = propertyBrace[m_type].oneLineIfSingleMaxSize.get() >= rawSize;
ESTYLE_ERROR("check: " << propertyBrace[m_type].oneLineIfSingleMaxSize.get() << " >= " << rawSize);
if (_needBrace == false) {
if (propertyBrace[m_type].single.get() == false) {
_needBrace = true;
}
}
if (_needBrace == true) {
if (propertyBrace[m_type].inNewLineBefore.get() == true) {
if ( propertyBrace[m_type].inNewLineBefore.get() == true
&& removeNewLine == false) {
addNewLine();
// add indentation
addSpace();
}
if (propertyBrace[m_type].inSpaceBefore.get() == true) {
} else if (propertyBrace[m_type].inSpaceBefore.get() == true) {
// add 1 space if needed
addSpace();
}
m_output += "{";
if (propertyBrace[m_type].inSpaceAfter.get() == true) {
if ( propertyBrace[m_type].inNewLineAfter.get() == true
&& removeNewLine == false) {
addNewLine();
} else if (propertyBrace[m_type].inSpaceAfter.get() == true) {
// add 1 space if needed
m_output += " ";
addSpace();
}
} else {
if ( propertyBrace[m_type].singleInNewLine.get() == true
&& removeNewLine == false) {
addNewLine();
} else if (propertyBrace[m_type].singleInSpace.get() == true) {
// add 1 space if needed
addSpace();
} else {
if ( m_output.size() != 0
&& ( m_output.back() != ' '
&& m_output.back() != ')'
&& m_output.back() != '>'
&& m_output.back() != ']'
&& m_output.back() != '\t')) {
addSpace();
}
}
}
if (propertyBrace[m_type].inNewLineAfter.get() == true) {
addNewLine();
}
indentationPush();
// TODO: maybe check the last element
@ -748,33 +870,49 @@ int64_t estyle::Generator::generateBrace(int64_t _start, int64_t _stop, bool _ne
indentationPop();
if (_needBrace == true) {
if (propertyBrace[m_type].outNewLineBefore.get() == true) {
if ( propertyBrace[m_type].outNewLineBefore.get() == true
&& removeNewLine == false) {
addNewLine();
// add indentation
addSpace();
}
}
if (_needBrace == true) {
if (propertyBrace[m_type].outSpaceBefore.get() == true) {
} else if (propertyBrace[m_type].outSpaceBefore.get() == true) {
// add 1 space if needed
addSpace();
}
m_output += "}";
if (propertyBrace[m_type].outSpaceAfter.get() == true) {
if ( propertyBrace[m_type].outSpaceAfter.get() == true
&& propertyBrace[m_type].outNewLineAfter.get() == false) {
// add 1 space if needed
addSpace();
}
}
// special case for a else after a condition ...
if (_checkElse == true) {
if (nextIs(_stop, estyle::lexer::RESERVED_ELSE) == false) {
// special case for a else after a condition ...
if (_checkElse == true) {
if (nextIs(_stop, estyle::lexer::RESERVED_ELSE) == false) {
if (propertyBrace[m_type].outNewLineAfter.get() == true) {
addNewLine();
}
}
} else {
if (propertyBrace[m_type].outNewLineAfter.get() == true) {
addNewLine();
}
}
} else {
if (propertyBrace[m_type].outNewLineAfter.get() == true) {
addNewLine();
if (propertyBrace[m_type].singleOutSpace.get() == true) {
// add 1 space if needed
addSpace();
}
// special case for a else after a condition ...
if (_checkElse == true) {
if (nextIs(_stop, estyle::lexer::RESERVED_ELSE) == false) {
if (propertyBrace[m_type].singleOutNewLine.get() == true) {
addNewLine();
}
}
} else {
if (propertyBrace[m_type].singleOutNewLine.get() == true) {
addNewLine();
}
}
}
return out;
@ -904,6 +1042,7 @@ int64_t estyle::Generator::endOfAction(int64_t _pos) {
int32_t estyle::Generator::countCurrent(int64_t _pos,
int64_t _posEnd,
enum estyle::lexer::tocken _type1,
enum estyle::lexer::tocken _type2,
enum estyle::lexer::tocken _type3,
@ -921,9 +1060,17 @@ int32_t estyle::Generator::countCurrent(int64_t _pos,
ESTYLE_ERROR("can not get end position of " << m_lexer.getTocken(_pos));
return _pos;
}
for (int64_t iii=_pos+1; iii < m_lexer.size(); ++iii) {
int64_t lastStart = _pos+1;
int64_t iii;
for (iii=_pos+1; iii < _posEnd; ++iii) {
elem = m_lexer.getTocken(iii);
if (elem == endTocken) {
/*
ESTYLE_ERROR("end tocke detected : " << iii << " > " << (lastStart+1) );
if (iii > lastStart+1) {
out++;
}
*/
return out;
}
if ( elem == estyle::lexer::PARENTHESE_IN
@ -936,24 +1083,40 @@ int32_t estyle::Generator::countCurrent(int64_t _pos,
|| _type3 == elem
|| _type4 == elem) {
out++;
ESTYLE_ERROR("detect type : " << iii);
lastStart = iii;
}
}
/*
if (iii == lastStart+1) {
out++;
}
*/
return out;
}
int32_t estyle::Generator::countCurrentLevelCondition(int64_t _pos) {
return countCurrent(_pos,
m_lexer.size(),
estyle::lexer::AND_AND,
estyle::lexer::OR_OR);
}
int32_t estyle::Generator::countCurrentParameters(int64_t _pos) {
return countCurrent(_pos,
m_lexer.size(),
estyle::lexer::COMA);
}
int32_t estyle::Generator::countCurrentAction(int64_t _pos) {
return countCurrent(_pos,
m_lexer.size(),
estyle::lexer::SEMICOLON);
}
int32_t estyle::Generator::countCurrentAction(int64_t _pos, int64_t _posEnd) {
return countCurrent(_pos,
_posEnd,
estyle::lexer::SEMICOLON);
}
@ -1031,3 +1194,24 @@ etk::String estyle::Generator::generateType(int64_t _pos) {
return out;
}
int32_t estyle::Generator::countRawSize(int64_t _pos, int64_t _posEnd) {
int32_t out = 0;
for (int64_t iii=_pos; iii<_posEnd; ++iii) {
enum estyle::lexer::tocken elem = m_lexer.getTocken(iii);
if (elem == estyle::lexer::ELEMENT_COMPLEX_TYPE) {
etk::Vector<estyle::LexerElement> listElement = m_lexer.getSubList(_pos);
for (size_t jjj=0; jjj<listElement.size(); ++jjj) {
enum estyle::lexer::tocken elem2 = listElement[jjj].getTocken();
if (elem2 == estyle::lexer::RESERVED_NEW_LINE) {
continue;
}
out += (listElement[jjj].getStop() - listElement[jjj].getStart());
}
} else {
//ESTYLE_WARNING("add Size : '" << m_lexer.getData(iii) << "' " << out << " +=" << m_lexer.getData(iii).size());
out += m_lexer.getData(iii).size();
}
}
return out;
}

View File

@ -26,7 +26,12 @@ namespace estyle {
eproperty::Value<bool> outNewLineAfter;
eproperty::Value<bool> outSpaceBefore;
eproperty::Value<bool> outSpaceAfter;
eproperty::Value<int32_t> oneLineIfSingleMaxSize;
eproperty::Value<bool> single;
eproperty::Value<bool> singleInNewLine;
eproperty::Value<bool> singleInSpace;
eproperty::Value<bool> singleOutNewLine;
eproperty::Value<bool> singleOutSpace;
BraceProperty(const BraceProperty& _obj) = delete;
BraceProperty(BraceProperty&& _obj);
~BraceProperty() = default;
@ -43,6 +48,8 @@ namespace estyle {
eproperty::Value<int8_t> propertyIndentSize;
eproperty::Value<bool> propertyDoxygenOneLine;
eproperty::List<int32_t> propertyDoxygenMultipleLine;
eproperty::Value<int32_t> propertyForConditionMultiLineBigSize;
// Brace section
// brace for "if"
etk::Map<etk::String, estyle::BraceProperty> propertyBrace;
@ -77,7 +84,7 @@ namespace estyle {
/**
* @brief Add space " " if no space or '\t' is set before and add the indentation if needed (last char is a "\n")
*/
void addSpace();
void addSpace(bool _force=false);
/**
* @brief Add Indentation "\t\t\t " if start of line
*/
@ -95,6 +102,7 @@ namespace estyle {
int64_t endOfSection(int64_t _pos);
int64_t endOfAction(int64_t _pos);
int32_t countCurrent(int64_t _pos,
int64_t _posEnd,
enum estyle::lexer::tocken _type1,
enum estyle::lexer::tocken _type2 = estyle::lexer::END_OF_FILE,
enum estyle::lexer::tocken _type3 = estyle::lexer::END_OF_FILE,
@ -102,6 +110,9 @@ namespace estyle {
int32_t countCurrentLevelCondition(int64_t _pos);
int32_t countCurrentParameters(int64_t _pos);
int32_t countCurrentAction(int64_t _pos);
int32_t countCurrentAction(int64_t _pos, int64_t _posEnd);
//! @brief count the number of char in the specified range
int32_t countRawSize(int64_t _pos, int64_t _posEnd);
int64_t generateBrace(int64_t _start, int64_t _stop, bool _needBrace, bool _checkElse = false);
int64_t generateCondition(int64_t _pos);
int64_t generateFunction(int64_t _pos);

View File

@ -15,7 +15,7 @@ static etk::String sourceElse1ActionNoBrace = "action_A;if(true){action_K:}else
static etk::String sourceElse2Action = "action_A;if(true){action_K:}else{action_B;action_C;}action_D;";
TEST(testBraceElse, brace_else_0000) {
TEST(testElse, brace_else_0000) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
@ -33,7 +33,7 @@ TEST(testBraceElse, brace_else_0000) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_1000) {
TEST(testElse, brace_else_1000) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
@ -51,7 +51,7 @@ TEST(testBraceElse, brace_else_1000) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_1010) {
TEST(testElse, brace_else_1010) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
@ -69,7 +69,7 @@ TEST(testBraceElse, brace_else_1010) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_1011) {
TEST(testElse, brace_else_1011) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
@ -87,7 +87,7 @@ TEST(testBraceElse, brace_else_1011) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_1100) {
TEST(testElse, brace_else_1100) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
@ -105,7 +105,7 @@ TEST(testBraceElse, brace_else_1100) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_1101) {
TEST(testElse, brace_else_1101) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
@ -116,14 +116,14 @@ TEST(testBraceElse, brace_else_1101) {
//interface.properties.set("brace-else-out-space-before", "true");
interface.properties.set("brace-else-out-space-after", "true");
//interface.properties.set("brace-else-single", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else\n{ \n\taction_B;\n} \naction_D;";
etk::String outputRef = "action_A;\nif (true ){action_K:} else\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_1110) {
TEST(testElse, brace_else_1110) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
@ -141,7 +141,7 @@ TEST(testBraceElse, brace_else_1110) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_1111) {
TEST(testElse, brace_else_1111) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
@ -152,14 +152,14 @@ TEST(testBraceElse, brace_else_1111) {
interface.properties.set("brace-else-out-space-before", "true");
interface.properties.set("brace-else-out-space-after", "true");
//interface.properties.set("brace-else-single", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else\n{ \n\taction_B;\n} \naction_D;";
etk::String outputRef = "action_A;\nif (true ){action_K:} else\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_1001) {
TEST(testElse, brace_else_1001) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
@ -178,7 +178,7 @@ TEST(testBraceElse, brace_else_1001) {
}
TEST(testBraceElse, brace_else_0100) {
TEST(testElse, brace_else_0100) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
@ -196,7 +196,7 @@ TEST(testBraceElse, brace_else_0100) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_0101) {
TEST(testElse, brace_else_0101) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
@ -207,14 +207,14 @@ TEST(testBraceElse, brace_else_0101) {
//interface.properties.set("brace-else-out-space-before", "true");
interface.properties.set("brace-else-out-space-after", "true");
//interface.properties.set("brace-else-single", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else{ \n\taction_B;} \naction_D;";
etk::String outputRef = "action_A;\nif (true ){action_K:} else{\n\taction_B;}\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_0110) {
TEST(testElse, brace_else_0110) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
@ -232,7 +232,7 @@ TEST(testBraceElse, brace_else_0110) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_0010) {
TEST(testElse, brace_else_0010) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
@ -250,7 +250,7 @@ TEST(testBraceElse, brace_else_0010) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_0011) {
TEST(testElse, brace_else_0011) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
@ -268,7 +268,7 @@ TEST(testBraceElse, brace_else_0011) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_0111) {
TEST(testElse, brace_else_0111) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
@ -279,14 +279,14 @@ TEST(testBraceElse, brace_else_0111) {
interface.properties.set("brace-else-out-space-before", "true");
interface.properties.set("brace-else-out-space-after", "true");
//interface.properties.set("brace-else-single", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else { \n\taction_B; } \naction_D;";
etk::String outputRef = "action_A;\nif (true ){action_K:} else {\n\taction_B; }\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceElse, brace_else_0001) {
TEST(testElse, brace_else_0001) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
@ -305,5 +305,67 @@ TEST(testBraceElse, brace_else_0001) {
}
TEST(testElse, brace_else_single_00) {
estyle::Generator interface;
//interface.properties.set("brace-else-single-one-line-size-max", "40");
interface.properties.set("brace-else-single", "true");
//interface.properties.set("brace-else-single-in-new-line", "true");
//interface.properties.set("brace-else-single-in-space", "true");
//interface.properties.set("brace-else-single-out-new-line", "true");
//interface.properties.set("brace-else-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else action_B;\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testElse, brace_else_single_10) {
estyle::Generator interface;
//interface.properties.set("brace-else-single-one-line-size-max", "40");
interface.properties.set("brace-else-single", "true");
interface.properties.set("brace-else-single-in-new-line", "true");
//interface.properties.set("brace-else-single-in-space", "true");
interface.properties.set("brace-else-single-out-new-line", "true");
//interface.properties.set("brace-else-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testElse, brace_else_single_01) {
estyle::Generator interface;
//interface.properties.set("brace-else-single-one-line-size-max", "40");
interface.properties.set("brace-else-single", "true");
//interface.properties.set("brace-else-single-in-new-line", "true");
interface.properties.set("brace-else-single-in-space", "true");
//interface.properties.set("brace-else-single-out-new-line", "true");
interface.properties.set("brace-else-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else action_B; action_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testElse, brace_else_single_11) {
estyle::Generator interface;
//interface.properties.set("brace-else-single-one-line-size-max", "40");
interface.properties.set("brace-else-single", "true");
interface.properties.set("brace-else-single-in-new-line", "true");
interface.properties.set("brace-else-single-in-space", "true");
interface.properties.set("brace-else-single-out-new-line", "true");
interface.properties.set("brace-else-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}

View File

@ -15,7 +15,7 @@ static etk::String sourceFor1ActionNoBrace = "action_A;for(;;)action_B;action_D;
static etk::String sourceFor2Action = "action_A;for(;;){action_B;action_C;}action_D;";
TEST(testBraceFor, brace_for_0000) {
TEST(testFor, brace_for_0000) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
@ -26,14 +26,14 @@ TEST(testBraceFor, brace_for_0000) {
//interface.properties.set("brace-for-out-space-before", "true");
//interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; ){action_B;}action_D;";
etk::String outputRef = "action_A;\nfor (;;){action_B;}action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_1000) {
TEST(testFor, brace_for_1000) {
estyle::Generator interface;
interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
@ -44,14 +44,14 @@ TEST(testBraceFor, brace_for_1000) {
//interface.properties.set("brace-for-out-space-before", "true");
//interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; )\n{action_B;\n}action_D;";
etk::String outputRef = "action_A;\nfor (;;)\n{action_B;\n}action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_1010) {
TEST(testFor, brace_for_1010) {
estyle::Generator interface;
interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
@ -62,14 +62,14 @@ TEST(testBraceFor, brace_for_1010) {
interface.properties.set("brace-for-out-space-before", "true");
//interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; )\n{action_B;\n}action_D;";
etk::String outputRef = "action_A;\nfor (;;)\n{action_B;\n}action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_1011) {
TEST(testFor, brace_for_1011) {
estyle::Generator interface;
interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
@ -80,14 +80,14 @@ TEST(testBraceFor, brace_for_1011) {
interface.properties.set("brace-for-out-space-before", "true");
interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; )\n{ action_B;\n} action_D;";
etk::String outputRef = "action_A;\nfor (;;)\n{ action_B;\n} action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_1100) {
TEST(testFor, brace_for_1100) {
estyle::Generator interface;
interface.properties.set("brace-for-in-new-line-before", "true");
interface.properties.set("brace-for-in-new-line-after", "true");
@ -98,14 +98,14 @@ TEST(testBraceFor, brace_for_1100) {
//interface.properties.set("brace-for-out-space-before", "true");
//interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; )\n{\n\taction_B;\n}\naction_D;";
etk::String outputRef = "action_A;\nfor (;;)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_1101) {
TEST(testFor, brace_for_1101) {
estyle::Generator interface;
interface.properties.set("brace-for-in-new-line-before", "true");
interface.properties.set("brace-for-in-new-line-after", "true");
@ -116,14 +116,14 @@ TEST(testBraceFor, brace_for_1101) {
//interface.properties.set("brace-for-out-space-before", "true");
interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; )\n{ \n\taction_B;\n} \naction_D;";
etk::String outputRef = "action_A;\nfor (;;)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_1110) {
TEST(testFor, brace_for_1110) {
estyle::Generator interface;
interface.properties.set("brace-for-in-new-line-before", "true");
interface.properties.set("brace-for-in-new-line-after", "true");
@ -134,14 +134,14 @@ TEST(testBraceFor, brace_for_1110) {
interface.properties.set("brace-for-out-space-before", "true");
//interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; )\n{\n\taction_B;\n}\naction_D;";
etk::String outputRef = "action_A;\nfor (;;)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_1111) {
TEST(testFor, brace_for_1111) {
estyle::Generator interface;
interface.properties.set("brace-for-in-new-line-before", "true");
interface.properties.set("brace-for-in-new-line-after", "true");
@ -152,14 +152,14 @@ TEST(testBraceFor, brace_for_1111) {
interface.properties.set("brace-for-out-space-before", "true");
interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; )\n{ \n\taction_B;\n} \naction_D;";
etk::String outputRef = "action_A;\nfor (;;)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_1001) {
TEST(testFor, brace_for_1001) {
estyle::Generator interface;
interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
@ -170,7 +170,7 @@ TEST(testBraceFor, brace_for_1001) {
//interface.properties.set("brace-for-out-space-before", "true");
interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; )\n{ action_B;\n} action_D;";
etk::String outputRef = "action_A;\nfor (;;)\n{ action_B;\n} action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
@ -178,7 +178,7 @@ TEST(testBraceFor, brace_for_1001) {
}
TEST(testBraceFor, brace_for_0100) {
TEST(testFor, brace_for_0100) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
interface.properties.set("brace-for-in-new-line-after", "true");
@ -189,14 +189,14 @@ TEST(testBraceFor, brace_for_0100) {
//interface.properties.set("brace-for-out-space-before", "true");
//interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; ){\n\taction_B;}\naction_D;";
etk::String outputRef = "action_A;\nfor (;;){\n\taction_B;}\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_0101) {
TEST(testFor, brace_for_0101) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
interface.properties.set("brace-for-in-new-line-after", "true");
@ -207,14 +207,14 @@ TEST(testBraceFor, brace_for_0101) {
//interface.properties.set("brace-for-out-space-before", "true");
interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; ){ \n\taction_B;} \naction_D;";
etk::String outputRef = "action_A;\nfor (;;){\n\taction_B;}\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_0110) {
TEST(testFor, brace_for_0110) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
interface.properties.set("brace-for-in-new-line-after", "true");
@ -225,14 +225,14 @@ TEST(testBraceFor, brace_for_0110) {
interface.properties.set("brace-for-out-space-before", "true");
//interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; ) {\n\taction_B; }\naction_D;";
etk::String outputRef = "action_A;\nfor (;;) {\n\taction_B; }\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_0010) {
TEST(testFor, brace_for_0010) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
@ -243,14 +243,14 @@ TEST(testBraceFor, brace_for_0010) {
interface.properties.set("brace-for-out-space-before", "true");
//interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; ) {action_B; }action_D;";
etk::String outputRef = "action_A;\nfor (;;) {action_B; }action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_0011) {
TEST(testFor, brace_for_0011) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
@ -261,14 +261,14 @@ TEST(testBraceFor, brace_for_0011) {
interface.properties.set("brace-for-out-space-before", "true");
interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; ) { action_B; } action_D;";
etk::String outputRef = "action_A;\nfor (;;) { action_B; } action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_0111) {
TEST(testFor, brace_for_0111) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
interface.properties.set("brace-for-in-new-line-after", "true");
@ -279,14 +279,14 @@ TEST(testBraceFor, brace_for_0111) {
interface.properties.set("brace-for-out-space-before", "true");
interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; ) { \n\taction_B; } \naction_D;";
etk::String outputRef = "action_A;\nfor (;;) {\n\taction_B; }\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceFor, brace_for_0001) {
TEST(testFor, brace_for_0001) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
@ -297,7 +297,7 @@ TEST(testBraceFor, brace_for_0001) {
//interface.properties.set("brace-for-out-space-before", "true");
interface.properties.set("brace-for-out-space-after", "true");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;\n; ){ action_B;} action_D;";
etk::String outputRef = "action_A;\nfor (;;){ action_B;} action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
@ -307,3 +307,137 @@ TEST(testBraceFor, brace_for_0001) {
TEST(testFor, brace_for_single_00) {
estyle::Generator interface;
//interface.properties.set("brace-for-single-one-line-size-max", "40");
interface.properties.set("brace-for-single", "true");
//interface.properties.set("brace-for-single-in-new-line", "true");
//interface.properties.set("brace-for-single-in-space", "true");
//interface.properties.set("brace-for-single-out-new-line", "true");
//interface.properties.set("brace-for-single-out-space", "true");
etk::String outputRef = "action_A;\nfor (;;)action_B;\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testFor, brace_for_single_10) {
estyle::Generator interface;
//interface.properties.set("brace-for-single-one-line-size-max", "40");
interface.properties.set("brace-for-single", "true");
interface.properties.set("brace-for-single-in-new-line", "true");
//interface.properties.set("brace-for-single-in-space", "true");
interface.properties.set("brace-for-single-out-new-line", "true");
//interface.properties.set("brace-for-single-out-space", "true");
etk::String outputRef = "action_A;\nfor (;;)\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testFor, brace_for_single_01) {
estyle::Generator interface;
//interface.properties.set("brace-for-single-one-line-size-max", "40");
interface.properties.set("brace-for-single", "true");
//interface.properties.set("brace-for-single-in-new-line", "true");
interface.properties.set("brace-for-single-in-space", "true");
//interface.properties.set("brace-for-single-out-new-line", "true");
interface.properties.set("brace-for-single-out-space", "true");
etk::String outputRef = "action_A;\nfor (;;) action_B; action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testFor, brace_for_single_11) {
estyle::Generator interface;
//interface.properties.set("brace-for-single-one-line-size-max", "40");
interface.properties.set("brace-for-single", "true");
interface.properties.set("brace-for-single-in-new-line", "true");
interface.properties.set("brace-for-single-in-space", "true");
interface.properties.set("brace-for-single-out-new-line", "true");
interface.properties.set("brace-for-single-out-space", "true");
etk::String outputRef = "action_A;\nfor (;;)\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testFor, brace_for_oneLine_0) {
estyle::Generator interface;
interface.properties.set("brace-for-in-new-line-before", "true");
interface.properties.set("brace-for-in-new-line-after", "true");
interface.properties.set("brace-for-in-space-before", "true");
interface.properties.set("brace-for-in-space-after", "true");
interface.properties.set("brace-for-out-new-line-before", "true");
interface.properties.set("brace-for-out-new-line-after", "true");
interface.properties.set("brace-for-out-space-before", "true");
//interface.properties.set("brace-for-out-space-after", "true");
interface.properties.set("brace-for-single-one-line-size-max", "40");
//interface.properties.set("brace-for-single", "true");
etk::String outputRef = "action_A;\nfor (;;) { action_B; }\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testFor, brace_for_oneLine_1) {
estyle::Generator interface;
interface.properties.set("brace-for-single-one-line-size-max", "40");
interface.properties.set("brace-for-single", "true");
interface.properties.set("brace-for-single-in-new-line", "true");
interface.properties.set("brace-for-single-in-space", "true");
interface.properties.set("brace-for-single-out-new-line", "true");
interface.properties.set("brace-for-single-out-space", "true");
etk::String outputRef = "action_A;\nfor (;;) action_B;\naction_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceFor1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testFor, condition_0) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
//interface.properties.set("brace-for-in-space-before", "true");
etk::String outputRef = "action_A;\nfor (;;){action_B;}action_D;";
etk::String output = interface.process(sourceFor1Action);
EXPECT_EQ(output, outputRef);
//output = interface.process(sourceFor1ActionNoBrace);
//EXPECT_EQ(output, outputRef);
}
TEST(testFor, condition_1) {
estyle::Generator interface;
//interface.properties.set("brace-for-in-new-line-before", "true");
//interface.properties.set("brace-for-in-new-line-after", "true");
//interface.properties.set("brace-for-in-space-before", "true");
etk::String outputRef = "action_A;\nfor (instanciation =4; condition<6; ++inclemantation){action_B;}action_D;";
etk::String base = "action_A;for(instanciation=4; condition<6; ++inclemantation){action_B;}action_D;";
etk::String output = interface.process(base);
EXPECT_EQ(output, outputRef);
interface.properties.set("for-condition-multi-line-big-size", "20");
output = interface.process(base);
outputRef = "action_A;\nfor (instanciation =4;\n condition<6;\n ++inclemantation){action_B;}action_D;";
EXPECT_EQ(output, outputRef);
}

View File

@ -99,7 +99,7 @@ TEST(testBraceFunction, brace_function_1101) {
interface.properties.set("brace-function-out-new-line-after", "true");
//interface.properties.set("brace-function-out-space-before", "true");
interface.properties.set("brace-function-out-space-after", "true");
etk::String outputRef = "action_A;\nprint_console ( )\n{ \n\taction_B;\n} \naction_D;";
etk::String outputRef = "action_A;\nprint_console ( )\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
}
@ -129,7 +129,7 @@ TEST(testBraceFunction, brace_function_1111) {
interface.properties.set("brace-function-out-new-line-after", "true");
interface.properties.set("brace-function-out-space-before", "true");
interface.properties.set("brace-function-out-space-after", "true");
etk::String outputRef = "action_A;\nprint_console ( )\n{ \n\taction_B;\n} \naction_D;";
etk::String outputRef = "action_A;\nprint_console ( )\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
}
@ -175,7 +175,7 @@ TEST(testBraceFunction, brace_function_0101) {
interface.properties.set("brace-function-out-new-line-after", "true");
//interface.properties.set("brace-function-out-space-before", "true");
interface.properties.set("brace-function-out-space-after", "true");
etk::String outputRef = "action_A;\nprint_console ( ){ \n\taction_B;} \naction_D;";
etk::String outputRef = "action_A;\nprint_console ( ){\n\taction_B;}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
}
@ -235,7 +235,7 @@ TEST(testBraceFunction, brace_function_0111) {
interface.properties.set("brace-function-out-new-line-after", "true");
interface.properties.set("brace-function-out-space-before", "true");
interface.properties.set("brace-function-out-space-after", "true");
etk::String outputRef = "action_A;\nprint_console ( ) { \n\taction_B; } \naction_D;";
etk::String outputRef = "action_A;\nprint_console ( ) {\n\taction_B; }\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
}

View File

@ -15,7 +15,7 @@ static etk::String sourceIf1ActionNoBrace = "action_A;if(true)action_B;action_D;
static etk::String sourceIf2Action = "action_A;if(true){action_B;action_C;}action_D;";
TEST(testBraceIf, brace_if_0000) {
TEST(testIf, brace_if_0000) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
@ -33,7 +33,7 @@ TEST(testBraceIf, brace_if_0000) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_1000) {
TEST(testIf, brace_if_1000) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
@ -51,7 +51,7 @@ TEST(testBraceIf, brace_if_1000) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_1010) {
TEST(testIf, brace_if_1010) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
@ -69,7 +69,7 @@ TEST(testBraceIf, brace_if_1010) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_1011) {
TEST(testIf, brace_if_1011) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
@ -87,7 +87,7 @@ TEST(testBraceIf, brace_if_1011) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_1100) {
TEST(testIf, brace_if_1100) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
@ -105,7 +105,7 @@ TEST(testBraceIf, brace_if_1100) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_1101) {
TEST(testIf, brace_if_1101) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
@ -116,14 +116,14 @@ TEST(testBraceIf, brace_if_1101) {
//interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outputRef = "action_A;\nif (true )\n{ \n\taction_B;\n} \naction_D;";
etk::String outputRef = "action_A;\nif (true )\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_1110) {
TEST(testIf, brace_if_1110) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
@ -141,7 +141,7 @@ TEST(testBraceIf, brace_if_1110) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_1111) {
TEST(testIf, brace_if_1111) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
@ -152,14 +152,14 @@ TEST(testBraceIf, brace_if_1111) {
interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outputRef = "action_A;\nif (true )\n{ \n\taction_B;\n} \naction_D;";
etk::String outputRef = "action_A;\nif (true )\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_1001) {
TEST(testIf, brace_if_1001) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
@ -178,7 +178,7 @@ TEST(testBraceIf, brace_if_1001) {
}
TEST(testBraceIf, brace_if_0100) {
TEST(testIf, brace_if_0100) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
@ -196,7 +196,7 @@ TEST(testBraceIf, brace_if_0100) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_0101) {
TEST(testIf, brace_if_0101) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
@ -207,14 +207,14 @@ TEST(testBraceIf, brace_if_0101) {
//interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outputRef = "action_A;\nif (true ){ \n\taction_B;} \naction_D;";
etk::String outputRef = "action_A;\nif (true ){\n\taction_B;}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_0110) {
TEST(testIf, brace_if_0110) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
@ -232,7 +232,7 @@ TEST(testBraceIf, brace_if_0110) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_0010) {
TEST(testIf, brace_if_0010) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
@ -250,7 +250,7 @@ TEST(testBraceIf, brace_if_0010) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_0011) {
TEST(testIf, brace_if_0011) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
@ -268,7 +268,7 @@ TEST(testBraceIf, brace_if_0011) {
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_0111) {
TEST(testIf, brace_if_0111) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
@ -279,14 +279,14 @@ TEST(testBraceIf, brace_if_0111) {
interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outputRef = "action_A;\nif (true ) { \n\taction_B; } \naction_D;";
etk::String outputRef = "action_A;\nif (true ) {\n\taction_B; }\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testBraceIf, brace_if_0001) {
TEST(testIf, brace_if_0001) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
@ -305,5 +305,64 @@ TEST(testBraceIf, brace_if_0001) {
}
TEST(testIf, brace_if_single_00) {
estyle::Generator interface;
//interface.properties.set("brace-if-single-one-line-size-max", "40");
interface.properties.set("brace-if-single", "true");
//interface.properties.set("brace-if-single-in-new-line", "true");
//interface.properties.set("brace-if-single-in-space", "true");
//interface.properties.set("brace-if-single-out-new-line", "true");
//interface.properties.set("brace-if-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true )action_B;\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testIf, brace_if_single_10) {
estyle::Generator interface;
//interface.properties.set("brace-if-single-one-line-size-max", "40");
interface.properties.set("brace-if-single", "true");
interface.properties.set("brace-if-single-in-new-line", "true");
//interface.properties.set("brace-if-single-in-space", "true");
interface.properties.set("brace-if-single-out-new-line", "true");
//interface.properties.set("brace-if-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true )\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testIf, brace_if_single_01) {
estyle::Generator interface;
//interface.properties.set("brace-if-single-one-line-size-max", "40");
interface.properties.set("brace-if-single", "true");
//interface.properties.set("brace-if-single-in-new-line", "true");
interface.properties.set("brace-if-single-in-space", "true");
//interface.properties.set("brace-if-single-out-new-line", "true");
interface.properties.set("brace-if-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true ) action_B; action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testIf, brace_if_single_11) {
estyle::Generator interface;
//interface.properties.set("brace-if-single-one-line-size-max", "40");
interface.properties.set("brace-if-single", "true");
interface.properties.set("brace-if-single-in-new-line", "true");
interface.properties.set("brace-if-single-in-space", "true");
interface.properties.set("brace-if-single-out-new-line", "true");
interface.properties.set("brace-if-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true )\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}