[DEV] better generation for brace in 'else', 'if', 'function' and add test for 'for'
This commit is contained in:
parent
a7775acfa9
commit
61cc132991
@ -110,7 +110,7 @@ estyle::BraceProperty::BraceProperty() :
|
|||||||
single(false) {
|
single(false) {
|
||||||
|
|
||||||
}
|
}
|
||||||
estyle::BraceProperty::BraceProperty(class estyle::Generator* _generator, const etk::String& _typeName):
|
estyle::BraceProperty::BraceProperty(class estyle::Generator* _generator, const etk::String& _typeName, bool _allowSingle):
|
||||||
inNewLineBefore(_generator, "brace-" + _typeName + "-in-new-line-before", false, "Set a new line before the input brace"),
|
inNewLineBefore(_generator, "brace-" + _typeName + "-in-new-line-before", false, "Set a new line before the input brace"),
|
||||||
inNewLineAfter(_generator, "brace-" + _typeName + "-in-new-line-after", false, "Set a new line after the input brace"),
|
inNewLineAfter(_generator, "brace-" + _typeName + "-in-new-line-after", false, "Set a new line after the input brace"),
|
||||||
inSpaceBefore(_generator, "brace-" + _typeName + "-in-space-before", false, "Set a space before the input brace (if not already present)"),
|
inSpaceBefore(_generator, "brace-" + _typeName + "-in-space-before", false, "Set a space before the input brace (if not already present)"),
|
||||||
@ -119,7 +119,9 @@ 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"),
|
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)"),
|
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)"),
|
outSpaceAfter(_generator, "brace-" + _typeName + "-out-space-after", false, "Set a space after the input brace (if not already present)"),
|
||||||
single(_generator, "brace-" + _typeName + "-single", false, "remove or add brace if only 1 action is present.") {
|
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)) )) {
|
||||||
|
|
||||||
}
|
}
|
||||||
estyle::BraceProperty::BraceProperty(estyle::BraceProperty&& _obj) :
|
estyle::BraceProperty::BraceProperty(estyle::BraceProperty&& _obj) :
|
||||||
@ -167,14 +169,16 @@ estyle::Generator::Generator():
|
|||||||
setPropertyDoxygenMultiLine(propertyDoxygenMultipleLine);
|
setPropertyDoxygenMultiLine(propertyDoxygenMultipleLine);
|
||||||
propertyBrace.set("if", etk::move(estyle::BraceProperty(this, "if")));
|
propertyBrace.set("if", etk::move(estyle::BraceProperty(this, "if")));
|
||||||
propertyBrace.set("else", etk::move(estyle::BraceProperty(this, "else")));
|
propertyBrace.set("else", etk::move(estyle::BraceProperty(this, "else")));
|
||||||
|
propertyBrace.set("function", etk::move(estyle::BraceProperty(this, "function", false)));
|
||||||
|
|
||||||
propertyBrace.set("for", etk::move(estyle::BraceProperty(this, "for")));
|
propertyBrace.set("for", etk::move(estyle::BraceProperty(this, "for")));
|
||||||
propertyBrace.set("while", etk::move(estyle::BraceProperty(this, "while")));
|
propertyBrace.set("while", etk::move(estyle::BraceProperty(this, "while")));
|
||||||
propertyBrace.set("do", etk::move(estyle::BraceProperty(this, "do")));
|
propertyBrace.set("do", etk::move(estyle::BraceProperty(this, "do")));
|
||||||
propertyBrace.set("switch", etk::move(estyle::BraceProperty(this, "switch")));
|
propertyBrace.set("switch", etk::move(estyle::BraceProperty(this, "switch", false)));
|
||||||
propertyBrace.set("namespace", etk::move(estyle::BraceProperty(this, "namespace")));
|
propertyBrace.set("namespace", etk::move(estyle::BraceProperty(this, "namespace", false)));
|
||||||
propertyBrace.set("class", etk::move(estyle::BraceProperty(this, "class")));
|
propertyBrace.set("class", etk::move(estyle::BraceProperty(this, "class", false)));
|
||||||
propertyBrace.set("struct", etk::move(estyle::BraceProperty(this, "struct")));
|
propertyBrace.set("struct", etk::move(estyle::BraceProperty(this, "struct", false)));
|
||||||
propertyBrace.set("block", etk::move(estyle::BraceProperty(this, "block")));
|
propertyBrace.set("block", etk::move(estyle::BraceProperty(this, "block", false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
estyle::Generator::~Generator() {
|
estyle::Generator::~Generator() {
|
||||||
@ -567,6 +571,94 @@ int32_t estyle::Generator::process(int32_t _startId,
|
|||||||
int32_t sectionEnd = endOfAction(iii+1);
|
int32_t sectionEnd = endOfAction(iii+1);
|
||||||
subGenerationStop = sectionEnd+1;
|
subGenerationStop = sectionEnd+1;
|
||||||
}
|
}
|
||||||
|
iii = generateBrace(subGenerationStart, subGenerationStop, needBrace, true);
|
||||||
|
if (haveBrace == true) {
|
||||||
|
iii--;
|
||||||
|
} else {
|
||||||
|
iii -= 2;
|
||||||
|
}
|
||||||
|
typePop();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (elem == estyle::lexer::RESERVED_ELSE) {
|
||||||
|
addNewLineIfSemiColon();
|
||||||
|
typePush("else");
|
||||||
|
addSpace();
|
||||||
|
m_output += "else";
|
||||||
|
// special case ==> nothing special to do for the else element...
|
||||||
|
if (nextIs(iii+1, estyle::lexer::RESERVED_IF) == true) {
|
||||||
|
typePop();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bool needBrace = false;
|
||||||
|
bool haveBrace = false;
|
||||||
|
int32_t subGenerationStart = iii+1;
|
||||||
|
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);
|
||||||
|
if (countAction != 1) {
|
||||||
|
needBrace = true;
|
||||||
|
}
|
||||||
|
subGenerationStart = iii+2;
|
||||||
|
subGenerationStop = endOfSection(iii+1);
|
||||||
|
} else {
|
||||||
|
// only 1 instruction:
|
||||||
|
int32_t sectionEnd = endOfAction(iii+1);
|
||||||
|
subGenerationStop = sectionEnd+1;
|
||||||
|
}
|
||||||
|
iii = generateBrace(subGenerationStart, subGenerationStop, needBrace, true);
|
||||||
|
if (haveBrace == true) {
|
||||||
|
iii--;
|
||||||
|
} else {
|
||||||
|
iii -= 2;
|
||||||
|
}
|
||||||
|
typePop();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( elem == estyle::lexer::ELEMENT_FUNCTION
|
||||||
|
|| elem == estyle::lexer::ELEMENT_FUNCTION_DECLARATION) {
|
||||||
|
addNewLineIfSemiColon();
|
||||||
|
typePush("function");
|
||||||
|
//addSpace();
|
||||||
|
m_output += m_lexer.getData(iii);
|
||||||
|
m_output += " ";
|
||||||
|
//offsetPush(m_lexer.getData(iii).size() + 2);
|
||||||
|
offsetPushAuto();
|
||||||
|
for (int64_t jjj=iii+1; jjj<m_lexer.size(); ++jjj) {
|
||||||
|
enum estyle::lexer::tocken elem = m_lexer.getTocken(jjj);
|
||||||
|
if (elem == estyle::lexer::RESERVED_NEW_LINE) {
|
||||||
|
// OK ==> normal case ...
|
||||||
|
} else if (elem == estyle::lexer::PARENTHESE_IN) {
|
||||||
|
// find condition section ...
|
||||||
|
iii = generateFunction(jjj);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
ESTYLE_ERROR("Get '" << m_lexer.getData(iii) << "' (function) without '(' element");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
offsetPop();
|
||||||
|
if (elem == estyle::lexer::ELEMENT_FUNCTION_DECLARATION) {
|
||||||
|
// nothing more to do ... end of declaration
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int32_t subGenerationStart = iii+1;
|
||||||
|
int32_t subGenerationStop = iii+1;
|
||||||
|
subGenerationStart = iii+2;
|
||||||
|
subGenerationStop = endOfSection(iii+1);
|
||||||
|
iii = generateBrace(subGenerationStart, subGenerationStop, true);
|
||||||
|
//iii--;
|
||||||
|
typePop();
|
||||||
|
}
|
||||||
|
// default other case:
|
||||||
|
//addSpace();
|
||||||
|
m_output += m_lexer.getData(iii);
|
||||||
|
}
|
||||||
|
return _stopId+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int64_t estyle::Generator::generateBrace(int64_t _start, int64_t _stop, bool _needBrace, bool _checkElse) {
|
||||||
/*
|
/*
|
||||||
ESTYLE_ERROR(" single " << propertyBrace[m_type].single.get());
|
ESTYLE_ERROR(" single " << propertyBrace[m_type].single.get());
|
||||||
ESTYLE_ERROR(" inNewLineBefore " << propertyBrace[m_type].inNewLineBefore.get());
|
ESTYLE_ERROR(" inNewLineBefore " << propertyBrace[m_type].inNewLineBefore.get());
|
||||||
@ -578,12 +670,12 @@ int32_t estyle::Generator::process(int32_t _startId,
|
|||||||
ESTYLE_ERROR(" outSpaceAfter " << propertyBrace[m_type].outSpaceAfter.get());
|
ESTYLE_ERROR(" outSpaceAfter " << propertyBrace[m_type].outSpaceAfter.get());
|
||||||
ESTYLE_ERROR(" outNewLineAfter " << propertyBrace[m_type].outNewLineAfter.get());
|
ESTYLE_ERROR(" outNewLineAfter " << propertyBrace[m_type].outNewLineAfter.get());
|
||||||
*/
|
*/
|
||||||
if (needBrace == false) {
|
if (_needBrace == false) {
|
||||||
if (propertyBrace[m_type].single.get() == false) {
|
if (propertyBrace[m_type].single.get() == false) {
|
||||||
needBrace = true;
|
_needBrace = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (needBrace == true) {
|
if (_needBrace == true) {
|
||||||
if (propertyBrace[m_type].inNewLineBefore.get() == true) {
|
if (propertyBrace[m_type].inNewLineBefore.get() == true) {
|
||||||
addNewLine();
|
addNewLine();
|
||||||
// add indentation
|
// add indentation
|
||||||
@ -603,17 +695,18 @@ int32_t estyle::Generator::process(int32_t _startId,
|
|||||||
addNewLine();
|
addNewLine();
|
||||||
}
|
}
|
||||||
indentationPush();
|
indentationPush();
|
||||||
|
// TODO: maybe check the last element
|
||||||
|
int64_t out = process(_start, _stop);
|
||||||
|
|
||||||
iii = process(subGenerationStart, subGenerationStop);
|
|
||||||
indentationPop();
|
indentationPop();
|
||||||
if (needBrace == true) {
|
if (_needBrace == true) {
|
||||||
if (propertyBrace[m_type].outNewLineBefore.get() == true) {
|
if (propertyBrace[m_type].outNewLineBefore.get() == true) {
|
||||||
addNewLine();
|
addNewLine();
|
||||||
// add indentation
|
// add indentation
|
||||||
addSpace();
|
addSpace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (needBrace == true) {
|
if (_needBrace == true) {
|
||||||
if (propertyBrace[m_type].outSpaceBefore.get() == true) {
|
if (propertyBrace[m_type].outSpaceBefore.get() == true) {
|
||||||
// add 1 space if needed
|
// add 1 space if needed
|
||||||
addSpace();
|
addSpace();
|
||||||
@ -624,80 +717,22 @@ int32_t estyle::Generator::process(int32_t _startId,
|
|||||||
addSpace();
|
addSpace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (haveBrace == true) {
|
|
||||||
iii--;
|
|
||||||
} else {
|
|
||||||
iii-=2;
|
|
||||||
}
|
|
||||||
// special case for a else after a condition ...
|
// special case for a else after a condition ...
|
||||||
if (nextIs(iii+1, estyle::lexer::RESERVED_ELSE) == false) {
|
if (_checkElse == true) {
|
||||||
|
if (nextIs(_stop, estyle::lexer::RESERVED_ELSE) == false) {
|
||||||
if (propertyBrace[m_type].outNewLineAfter.get() == true) {
|
if (propertyBrace[m_type].outNewLineAfter.get() == true) {
|
||||||
addNewLine();
|
addNewLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
typePop();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (elem == estyle::lexer::RESERVED_ELSE) {
|
|
||||||
addNewLineIfSemiColon();
|
|
||||||
typePush("else");
|
|
||||||
if (nextIs(iii+1, estyle::lexer::BRACE_IN) == true) {
|
|
||||||
int32_t countAction = countCurrent(iii+1, estyle::lexer::tocken::SEMICOLON);
|
|
||||||
// TODO ...
|
|
||||||
addSpace();
|
|
||||||
m_output += "else";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (nextIs(iii+1, estyle::lexer::RESERVED_IF) == true) {
|
|
||||||
addSpace();
|
|
||||||
m_output += "else";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
addNewLine();
|
|
||||||
addSpace();
|
|
||||||
m_output += "{";
|
|
||||||
indentationPush();
|
|
||||||
addNewLine();
|
|
||||||
|
|
||||||
int32_t sectionEnd = endOfAction(iii+1);
|
|
||||||
iii = process(iii+1, sectionEnd+1);
|
|
||||||
|
|
||||||
addNewLine();
|
|
||||||
indentationPop();
|
|
||||||
addSpace();
|
|
||||||
m_output += "}";
|
|
||||||
addNewLine();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( elem == estyle::lexer::ELEMENT_FUNCTION
|
|
||||||
|| elem == estyle::lexer::ELEMENT_FUNCTION_DECLARATION) {
|
|
||||||
addNewLineIfSemiColon();
|
|
||||||
//addSpace();
|
|
||||||
m_output += m_lexer.getData(iii);
|
|
||||||
m_output += " ";
|
|
||||||
//offsetPush(m_lexer.getData(iii).size() + 2);
|
|
||||||
offsetPushAuto();
|
|
||||||
for (int64_t jjj=iii+1; jjj<m_lexer.size(); ++jjj) {
|
|
||||||
enum estyle::lexer::tocken elem = m_lexer.getTocken(jjj);
|
|
||||||
if (elem == estyle::lexer::RESERVED_NEW_LINE) {
|
|
||||||
// OK ==> normal case ...
|
|
||||||
} else if (elem == estyle::lexer::PARENTHESE_IN) {
|
|
||||||
// find condition section ...
|
|
||||||
iii = generateFunction(jjj);
|
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
ESTYLE_ERROR("Get '" << m_lexer.getData(iii) << "' (function) without '(' element");
|
if (propertyBrace[m_type].outNewLineAfter.get() == true) {
|
||||||
|
addNewLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
offsetPop();
|
return out;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// default other case:
|
|
||||||
//addSpace();
|
|
||||||
m_output += m_lexer.getData(iii);
|
|
||||||
}
|
|
||||||
return _stopId+1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// go ackward and find if previous is the corect type (remove) \n and empty space ==> not comment they need to add it (wrong place but not may job ...
|
// go ackward and find if previous is the corect type (remove) \n and empty space ==> not comment they need to add it (wrong place but not may job ...
|
||||||
bool estyle::Generator::previousIs(int64_t _pos, enum estyle::lexer::tocken _previousType) {
|
bool estyle::Generator::previousIs(int64_t _pos, enum estyle::lexer::tocken _previousType) {
|
||||||
for (int32_t iii=_pos-1; iii>0; --iii) {
|
for (int32_t iii=_pos-1; iii>0; --iii) {
|
||||||
|
@ -17,7 +17,7 @@ namespace estyle {
|
|||||||
class BraceProperty {
|
class BraceProperty {
|
||||||
public:
|
public:
|
||||||
BraceProperty();
|
BraceProperty();
|
||||||
BraceProperty(estyle::Generator* _generator, const etk::String& _typeName);
|
BraceProperty(estyle::Generator* _generator, const etk::String& _typeName, bool _allowSingle=true);
|
||||||
eproperty::Value<bool> inNewLineBefore;
|
eproperty::Value<bool> inNewLineBefore;
|
||||||
eproperty::Value<bool> inNewLineAfter;
|
eproperty::Value<bool> inNewLineAfter;
|
||||||
eproperty::Value<bool> inSpaceBefore;
|
eproperty::Value<bool> inSpaceBefore;
|
||||||
@ -102,6 +102,7 @@ namespace estyle {
|
|||||||
int32_t countCurrentLevelCondition(int64_t _pos);
|
int32_t countCurrentLevelCondition(int64_t _pos);
|
||||||
int32_t countCurrentParameters(int64_t _pos);
|
int32_t countCurrentParameters(int64_t _pos);
|
||||||
int32_t countCurrentAction(int64_t _pos);
|
int32_t countCurrentAction(int64_t _pos);
|
||||||
|
int64_t generateBrace(int64_t _start, int64_t _stop, bool _needBrace, bool _checkElse = false);
|
||||||
int64_t generateCondition(int64_t _pos);
|
int64_t generateCondition(int64_t _pos);
|
||||||
int64_t generateFunction(int64_t _pos);
|
int64_t generateFunction(int64_t _pos);
|
||||||
bool previousIs(int64_t _pos, enum estyle::lexer::tocken _previousType);
|
bool previousIs(int64_t _pos, enum estyle::lexer::tocken _previousType);
|
||||||
|
@ -22,6 +22,9 @@ def configure(target, my_module):
|
|||||||
my_module.add_src_file([
|
my_module.add_src_file([
|
||||||
'test/main.cpp',
|
'test/main.cpp',
|
||||||
'test/testIf.cpp',
|
'test/testIf.cpp',
|
||||||
|
'test/testElse.cpp',
|
||||||
|
'test/testFunction.cpp',
|
||||||
|
'test/testFor.cpp',
|
||||||
])
|
])
|
||||||
my_module.add_path("test")
|
my_module.add_path("test")
|
||||||
my_module.copy_path('data/*','test')
|
my_module.copy_path('data/*','test')
|
||||||
|
309
test/testElse.cpp
Normal file
309
test/testElse.cpp
Normal file
@ -0,0 +1,309 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2017, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL-2 (see license file)
|
||||||
|
*/
|
||||||
|
#include <estyle/estyle.hpp>
|
||||||
|
#include <estyle/Generator.hpp>
|
||||||
|
#include <etk/etk.hpp>
|
||||||
|
#include <etk/os/FSNode.hpp>
|
||||||
|
#include <test-debug/debug.hpp>
|
||||||
|
#include <etest/etest.hpp>
|
||||||
|
|
||||||
|
static etk::String sourceElse1Action = "action_A;if(true){action_K:}else{action_B;}action_D;";
|
||||||
|
static etk::String sourceElse1ActionNoBrace = "action_A;if(true){action_K:}else action_B;action_D;";
|
||||||
|
static etk::String sourceElse2Action = "action_A;if(true){action_K:}else{action_B;action_C;}action_D;";
|
||||||
|
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
//interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
//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{action_B;}action_D;";
|
||||||
|
etk::String output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
//interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
//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{action_B;\n}action_D;";
|
||||||
|
etk::String output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
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{action_B;\n}action_D;";
|
||||||
|
etk::String output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
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{ action_B;\n} action_D;";
|
||||||
|
etk::String output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
//interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
//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 output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
//interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
//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 output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
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 output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
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 output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
//interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
//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{ action_B;\n} action_D;";
|
||||||
|
etk::String output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
//interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
//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 output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
//interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
//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 output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
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 output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
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 {action_B; }action_D;";
|
||||||
|
etk::String output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
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 { action_B; } action_D;";
|
||||||
|
etk::String output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
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 output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceElse, 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");
|
||||||
|
//interface.properties.set("brace-else-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-else-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-else-out-new-line-after", "true");
|
||||||
|
//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{ action_B;} action_D;";
|
||||||
|
etk::String output = interface.process(sourceElse1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
output = interface.process(sourceElse1ActionNoBrace);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
346
test/testFor.cpp
346
test/testFor.cpp
@ -3,79 +3,307 @@
|
|||||||
* @copyright 2017, Edouard DUPIN, all right reserved
|
* @copyright 2017, Edouard DUPIN, all right reserved
|
||||||
* @license MPL-2 (see license file)
|
* @license MPL-2 (see license file)
|
||||||
*/
|
*/
|
||||||
|
#include <estyle/estyle.hpp>
|
||||||
|
#include <estyle/Generator.hpp>
|
||||||
|
#include <etk/etk.hpp>
|
||||||
|
#include <etk/os/FSNode.hpp>
|
||||||
#include <test-debug/debug.hpp>
|
#include <test-debug/debug.hpp>
|
||||||
#include <etest/etest.hpp>
|
#include <etest/etest.hpp>
|
||||||
#include "testInterface.hpp"
|
|
||||||
|
static etk::String sourceFor1Action = "action_A;for(;;){action_B;}action_D;";
|
||||||
|
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) {
|
||||||
// FOR
|
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");
|
||||||
TEST(testFor, simple) {
|
//interface.properties.set("brace-for-in-space-after", "true");
|
||||||
testInterface system;
|
//interface.properties.set("brace-for-out-new-line-before", "true");
|
||||||
bool ret = system.execute("variable result = 0; variable i; for (i=1;i<10;i++) result = result + i;");
|
//interface.properties.set("brace-for-out-new-line-after", "true");
|
||||||
EXPECT_EQ(ret, true);
|
//interface.properties.set("brace-for-out-space-before", "true");
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
//interface.properties.set("brace-for-out-space-after", "true");
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
//interface.properties.set("brace-for-single", "true");
|
||||||
EXPECT_EQ(system.getInteger32("result"), 45);
|
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, internal_init) {
|
TEST(testBraceFor, brace_for_1000) {
|
||||||
testInterface system;
|
estyle::Generator interface;
|
||||||
bool ret = system.execute("variable result = 0; for (variable i=1;i<10;i++) result = result + i;");
|
interface.properties.set("brace-for-in-new-line-before", "true");
|
||||||
EXPECT_EQ(ret, true);
|
//interface.properties.set("brace-for-in-new-line-after", "true");
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
//interface.properties.set("brace-for-in-space-before", "true");
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
//interface.properties.set("brace-for-in-space-after", "true");
|
||||||
EXPECT_EQ(system.getInteger32("result"), 45);
|
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", "true");
|
||||||
|
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(testFor, decrement) {
|
TEST(testBraceFor, brace_for_1010) {
|
||||||
testInterface system;
|
estyle::Generator interface;
|
||||||
bool ret = system.execute("variable result = 0; for (variable i=10;i>1;i--) result = result + i;");
|
interface.properties.set("brace-for-in-new-line-before", "true");
|
||||||
EXPECT_EQ(ret, true);
|
//interface.properties.set("brace-for-in-new-line-after", "true");
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
interface.properties.set("brace-for-in-space-before", "true");
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
//interface.properties.set("brace-for-in-space-after", "true");
|
||||||
EXPECT_EQ(system.getInteger32("result"), 54);
|
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", "true");
|
||||||
|
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) {
|
||||||
|
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", "true");
|
||||||
|
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) {
|
||||||
|
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", "true");
|
||||||
|
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) {
|
||||||
|
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", "true");
|
||||||
|
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) {
|
||||||
|
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", "true");
|
||||||
|
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) {
|
||||||
|
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", "true");
|
||||||
|
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) {
|
||||||
|
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", "true");
|
||||||
|
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_0100) {
|
||||||
// while
|
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", "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(testWhile, simple) {
|
TEST(testBraceFor, brace_for_0101) {
|
||||||
testInterface system;
|
estyle::Generator interface;
|
||||||
bool ret = system.execute("variable result = 0; variable i=1; while (i<10) { result = result + i; i++;}");
|
//interface.properties.set("brace-for-in-new-line-before", "true");
|
||||||
EXPECT_EQ(ret, true);
|
interface.properties.set("brace-for-in-new-line-after", "true");
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
//interface.properties.set("brace-for-in-space-before", "true");
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
interface.properties.set("brace-for-in-space-after", "true");
|
||||||
EXPECT_EQ(system.getInteger32("result"), 45);
|
//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", "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(testBraceFor, 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");
|
||||||
|
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", "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(testBraceFor, 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");
|
||||||
|
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", "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(testBraceFor, 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");
|
||||||
|
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", "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(testBraceFor, 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");
|
||||||
|
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", "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(testBraceFor, 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");
|
||||||
|
//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", "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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////
|
|
||||||
// do .. while
|
|
||||||
//////////////////////////////////////
|
|
||||||
|
|
||||||
TEST(testDoWhile, simple) {
|
|
||||||
testInterface system;
|
|
||||||
bool ret = system.execute("variable result = 0; variable i=1; do { result = result + i; i++;} while (i<10);");
|
|
||||||
EXPECT_EQ(ret, true);
|
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
|
||||||
EXPECT_EQ(system.getInteger32("result"), 45);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TEST(testDoWhile, first) {
|
|
||||||
testInterface system;
|
|
||||||
bool ret = system.execute("variable result = 0; variable i=1; do { result = result + i; i++;} while (i<0);");
|
|
||||||
EXPECT_EQ(ret, true);
|
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
|
||||||
EXPECT_EQ(system.getInteger32("result"), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -3,54 +3,258 @@
|
|||||||
* @copyright 2017, Edouard DUPIN, all right reserved
|
* @copyright 2017, Edouard DUPIN, all right reserved
|
||||||
* @license MPL-2 (see license file)
|
* @license MPL-2 (see license file)
|
||||||
*/
|
*/
|
||||||
|
#include <estyle/estyle.hpp>
|
||||||
|
#include <estyle/Generator.hpp>
|
||||||
|
#include <etk/etk.hpp>
|
||||||
|
#include <etk/os/FSNode.hpp>
|
||||||
#include <test-debug/debug.hpp>
|
#include <test-debug/debug.hpp>
|
||||||
#include <etest/etest.hpp>
|
#include <etest/etest.hpp>
|
||||||
#include "testInterface.hpp"
|
|
||||||
|
static etk::String sourceIf1Action = "action_A;print_console(){action_B;}action_D;";
|
||||||
|
static etk::String sourceIf2Action = "action_A;print_console(){action_B;action_C;}action_D;";
|
||||||
|
|
||||||
|
|
||||||
TEST(testFunction, simple) {
|
TEST(testBraceFunction, brace_function_0000) {
|
||||||
testInterface system;
|
estyle::Generator interface;
|
||||||
bool ret = system.execute("function add(a,b) { return a+b; }; variable result = add(222,33);");
|
//interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
EXPECT_EQ(ret, true);
|
//interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
//interface.properties.set("brace-function-in-space-before", "true");
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
//interface.properties.set("brace-function-in-space-after", "true");
|
||||||
EXPECT_EQ(system.getInteger32("result"), 255);
|
//interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
//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 ( ){action_B;}action_D;";
|
||||||
|
etk::String output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(testFunction, function_in_object) {
|
TEST(testBraceFunction, brace_function_1000) {
|
||||||
testInterface system;
|
estyle::Generator interface;
|
||||||
bool ret = system.execute("variable myObject= {};myObject.add = function(a,b) { return a+b; }; variable result = myObject.add(222,33);");
|
interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
EXPECT_EQ(ret, true);
|
//interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
//interface.properties.set("brace-function-in-space-before", "true");
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
//interface.properties.set("brace-function-in-space-after", "true");
|
||||||
EXPECT_EQ(system.getInteger32("result"), 255);
|
interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
//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{action_B;\n}action_D;";
|
||||||
|
etk::String output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_1010) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
//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{action_B;\n}action_D;";
|
||||||
|
etk::String output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_1011) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
//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{ action_B;\n} action_D;";
|
||||||
|
etk::String output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_1100) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
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 output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_1101) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
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 output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_1110) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
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 output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_1111) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
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 output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_1001) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
//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{ action_B;\n} action_D;";
|
||||||
|
etk::String output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(testFunction, function_in_object_in_json) {
|
TEST(testBraceFunction, brace_function_0100) {
|
||||||
testInterface system;
|
estyle::Generator interface;
|
||||||
bool ret = system.execute("variable myObject= { add : function(a,b) { return a+b; } }; variable result = myObject.add(222,33);");
|
//interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
EXPECT_EQ(ret, true);
|
interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
//interface.properties.set("brace-function-in-space-before", "true");
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
//interface.properties.set("brace-function-in-space-after", "true");
|
||||||
EXPECT_EQ(system.getInteger32("result"), 255);
|
//interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
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 output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_0101) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
//interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
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 output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_0110) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
//interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
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 output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_0010) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
//interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
//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 ( ) {action_B; }action_D;";
|
||||||
|
etk::String output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_0011) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
//interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
//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 ( ) { action_B; } action_D;";
|
||||||
|
etk::String output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_0111) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
//interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
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 output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(testBraceFunction, brace_function_0001) {
|
||||||
|
estyle::Generator interface;
|
||||||
|
//interface.properties.set("brace-function-in-new-line-before", "true");
|
||||||
|
//interface.properties.set("brace-function-in-new-line-after", "true");
|
||||||
|
//interface.properties.set("brace-function-in-space-before", "true");
|
||||||
|
interface.properties.set("brace-function-in-space-after", "true");
|
||||||
|
//interface.properties.set("brace-function-out-new-line-before", "true");
|
||||||
|
//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 ( ){ action_B;} action_D;";
|
||||||
|
etk::String output = interface.process(sourceIf1Action);
|
||||||
|
EXPECT_EQ(output, outputRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(testFunction, multiple_call) {
|
|
||||||
testInterface system;
|
|
||||||
bool ret = system.execute("function first(a) { return a+200; };function second(a) { return first(a)+50; }; variable result = second(5);");
|
|
||||||
EXPECT_EQ(ret, true);
|
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
|
||||||
EXPECT_EQ(system.getInteger32("result"), 255);
|
|
||||||
}
|
|
||||||
TEST(testFunction, recursion) {
|
|
||||||
testInterface system;
|
|
||||||
bool ret = system.execute("function recursive(a) { if (a>1) { return a + recursive(a-1); } return 1; }; variable result = recursive(10);");
|
|
||||||
EXPECT_EQ(ret, true);
|
|
||||||
EXPECT_EQ(system.exist("result"), true);
|
|
||||||
EXPECT_EQ(system.isInteger32("result"), true);
|
|
||||||
EXPECT_EQ(system.getInteger32("result"), 10+9+8+7+6+5+4+3+2+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
#include <test-debug/debug.hpp>
|
#include <test-debug/debug.hpp>
|
||||||
#include <etest/etest.hpp>
|
#include <etest/etest.hpp>
|
||||||
|
|
||||||
etk::String sourceIf1Action = "action_A;if(true){action_B;}action_D;";
|
static etk::String sourceIf1Action = "action_A;if(true){action_B;}action_D;";
|
||||||
etk::String sourceIf1ActionNoBrace = "action_A;if(true)action_B;action_D;";
|
static etk::String sourceIf1ActionNoBrace = "action_A;if(true)action_B;action_D;";
|
||||||
etk::String sourceIf2Action = "action_A;if(true){action_B;action_C;}action_D;";
|
static etk::String sourceIf2Action = "action_A;if(true){action_B;action_C;}action_D;";
|
||||||
|
|
||||||
|
|
||||||
TEST(testBraceIf, brace_if_0000) {
|
TEST(testBraceIf, brace_if_0000) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user