[DEV] better generation for brace in 'else', 'if', 'function' and add test for 'for'

This commit is contained in:
Edouard DUPIN 2017-12-28 15:35:20 +01:00
parent a7775acfa9
commit 61cc132991
7 changed files with 977 additions and 197 deletions

View File

@ -110,7 +110,7 @@ estyle::BraceProperty::BraceProperty() :
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"),
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)"),
@ -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"),
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)"),
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) :
@ -165,16 +167,18 @@ estyle::Generator::Generator():
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: /** */ ...") {
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("function", etk::move(estyle::BraceProperty(this, "function", false)));
propertyBrace.set("for", etk::move(estyle::BraceProperty(this, "for")));
propertyBrace.set("while", etk::move(estyle::BraceProperty(this, "while")));
propertyBrace.set("do", etk::move(estyle::BraceProperty(this, "do")));
propertyBrace.set("switch", etk::move(estyle::BraceProperty(this, "switch")));
propertyBrace.set("namespace", etk::move(estyle::BraceProperty(this, "namespace")));
propertyBrace.set("class", etk::move(estyle::BraceProperty(this, "class")));
propertyBrace.set("struct", etk::move(estyle::BraceProperty(this, "struct")));
propertyBrace.set("block", etk::move(estyle::BraceProperty(this, "block")));
propertyBrace.set("switch", etk::move(estyle::BraceProperty(this, "switch", false)));
propertyBrace.set("namespace", etk::move(estyle::BraceProperty(this, "namespace", false)));
propertyBrace.set("class", etk::move(estyle::BraceProperty(this, "class", false)));
propertyBrace.set("struct", etk::move(estyle::BraceProperty(this, "struct", false)));
propertyBrace.set("block", etk::move(estyle::BraceProperty(this, "block", false)));
}
estyle::Generator::~Generator() {
@ -567,73 +571,11 @@ int32_t estyle::Generator::process(int32_t _startId,
int32_t sectionEnd = endOfAction(iii+1);
subGenerationStop = sectionEnd+1;
}
/*
ESTYLE_ERROR(" single " << propertyBrace[m_type].single.get());
ESTYLE_ERROR(" inNewLineBefore " << propertyBrace[m_type].inNewLineBefore.get());
ESTYLE_ERROR(" inSpaceBefore " << propertyBrace[m_type].inSpaceBefore.get());
ESTYLE_ERROR(" inSpaceAfter " << propertyBrace[m_type].inSpaceAfter.get());
ESTYLE_ERROR(" inNewLineAfter " << propertyBrace[m_type].inNewLineAfter.get());
ESTYLE_ERROR(" outNewLineBefore " << propertyBrace[m_type].outNewLineBefore.get());
ESTYLE_ERROR(" outSpaceBefore " << propertyBrace[m_type].outSpaceBefore.get());
ESTYLE_ERROR(" outSpaceAfter " << propertyBrace[m_type].outSpaceAfter.get());
ESTYLE_ERROR(" outNewLineAfter " << propertyBrace[m_type].outNewLineAfter.get());
*/
if (needBrace == false) {
if (propertyBrace[m_type].single.get() == false) {
needBrace = true;
}
}
if (needBrace == true) {
if (propertyBrace[m_type].inNewLineBefore.get() == true) {
addNewLine();
// add indentation
addSpace();
}
if (propertyBrace[m_type].inSpaceBefore.get() == true) {
// add 1 space if needed
addSpace();
}
m_output += "{";
if (propertyBrace[m_type].inSpaceAfter.get() == true) {
// add 1 space if needed
m_output += " ";
}
}
if (propertyBrace[m_type].inNewLineAfter.get() == true) {
addNewLine();
}
indentationPush();
iii = process(subGenerationStart, subGenerationStop);
indentationPop();
if (needBrace == true) {
if (propertyBrace[m_type].outNewLineBefore.get() == true) {
addNewLine();
// add indentation
addSpace();
}
}
if (needBrace == true) {
if (propertyBrace[m_type].outSpaceBefore.get() == true) {
// add 1 space if needed
addSpace();
}
m_output += "}";
if (propertyBrace[m_type].outSpaceAfter.get() == true) {
// add 1 space if needed
addSpace();
}
}
iii = generateBrace(subGenerationStart, subGenerationStop, needBrace, true);
if (haveBrace == true) {
iii--;
} else {
iii-=2;
}
// special case for a else after a condition ...
if (nextIs(iii+1, estyle::lexer::RESERVED_ELSE) == false) {
if (propertyBrace[m_type].outNewLineAfter.get() == true) {
addNewLine();
}
iii -= 2;
}
typePop();
continue;
@ -641,37 +583,43 @@ int32_t estyle::Generator::process(int32_t _startId,
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;
}
addSpace();
m_output += "else";
// special case ==> nothing special to do for the else element...
if (nextIs(iii+1, estyle::lexer::RESERVED_IF) == true) {
addSpace();
m_output += "else";
typePop();
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();
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 += " ";
@ -690,7 +638,17 @@ int32_t estyle::Generator::process(int32_t _startId,
}
}
offsetPop();
continue;
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();
@ -698,6 +656,83 @@ int32_t estyle::Generator::process(int32_t _startId,
}
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(" inNewLineBefore " << propertyBrace[m_type].inNewLineBefore.get());
ESTYLE_ERROR(" inSpaceBefore " << propertyBrace[m_type].inSpaceBefore.get());
ESTYLE_ERROR(" inSpaceAfter " << propertyBrace[m_type].inSpaceAfter.get());
ESTYLE_ERROR(" inNewLineAfter " << propertyBrace[m_type].inNewLineAfter.get());
ESTYLE_ERROR(" outNewLineBefore " << propertyBrace[m_type].outNewLineBefore.get());
ESTYLE_ERROR(" outSpaceBefore " << propertyBrace[m_type].outSpaceBefore.get());
ESTYLE_ERROR(" outSpaceAfter " << propertyBrace[m_type].outSpaceAfter.get());
ESTYLE_ERROR(" outNewLineAfter " << propertyBrace[m_type].outNewLineAfter.get());
*/
if (_needBrace == false) {
if (propertyBrace[m_type].single.get() == false) {
_needBrace = true;
}
}
if (_needBrace == true) {
if (propertyBrace[m_type].inNewLineBefore.get() == true) {
addNewLine();
// add indentation
addSpace();
}
if (propertyBrace[m_type].inSpaceBefore.get() == true) {
// add 1 space if needed
addSpace();
}
m_output += "{";
if (propertyBrace[m_type].inSpaceAfter.get() == true) {
// add 1 space if needed
m_output += " ";
}
}
if (propertyBrace[m_type].inNewLineAfter.get() == true) {
addNewLine();
}
indentationPush();
// TODO: maybe check the last element
int64_t out = process(_start, _stop);
indentationPop();
if (_needBrace == true) {
if (propertyBrace[m_type].outNewLineBefore.get() == true) {
addNewLine();
// add indentation
addSpace();
}
}
if (_needBrace == true) {
if (propertyBrace[m_type].outSpaceBefore.get() == true) {
// add 1 space if needed
addSpace();
}
m_output += "}";
if (propertyBrace[m_type].outSpaceAfter.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].outNewLineAfter.get() == true) {
addNewLine();
}
}
} else {
if (propertyBrace[m_type].outNewLineAfter.get() == true) {
addNewLine();
}
}
return out;
}
// 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) {
for (int32_t iii=_pos-1; iii>0; --iii) {

View File

@ -17,7 +17,7 @@ namespace estyle {
class BraceProperty {
public:
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> inNewLineAfter;
eproperty::Value<bool> inSpaceBefore;
@ -102,6 +102,7 @@ namespace estyle {
int32_t countCurrentLevelCondition(int64_t _pos);
int32_t countCurrentParameters(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 generateFunction(int64_t _pos);
bool previousIs(int64_t _pos, enum estyle::lexer::tocken _previousType);

View File

@ -22,6 +22,9 @@ def configure(target, my_module):
my_module.add_src_file([
'test/main.cpp',
'test/testIf.cpp',
'test/testElse.cpp',
'test/testFunction.cpp',
'test/testFor.cpp',
])
my_module.add_path("test")
my_module.copy_path('data/*','test')

309
test/testElse.cpp Normal file
View 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);
}

View File

@ -3,79 +3,307 @@
* @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>
#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;";
//////////////////////////////////////
// FOR
//////////////////////////////////////
TEST(testFor, simple) {
testInterface system;
bool ret = system.execute("variable result = 0; variable i; for (i=1;i<10;i++) result = result + i;");
EXPECT_EQ(ret, true);
EXPECT_EQ(system.exist("result"), true);
EXPECT_EQ(system.isInteger32("result"), true);
EXPECT_EQ(system.getInteger32("result"), 45);
TEST(testBraceFor, 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");
//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(testFor, internal_init) {
testInterface system;
bool ret = system.execute("variable result = 0; for (variable i=1;i<10;i++) result = result + i;");
EXPECT_EQ(ret, true);
EXPECT_EQ(system.exist("result"), true);
EXPECT_EQ(system.isInteger32("result"), true);
EXPECT_EQ(system.getInteger32("result"), 45);
TEST(testBraceFor, 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");
//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(testFor, decrement) {
testInterface system;
bool ret = system.execute("variable result = 0; for (variable i=10;i>1;i--) result = result + i;");
EXPECT_EQ(ret, true);
EXPECT_EQ(system.exist("result"), true);
EXPECT_EQ(system.isInteger32("result"), true);
EXPECT_EQ(system.getInteger32("result"), 54);
TEST(testBraceFor, 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");
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_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);
}
//////////////////////////////////////
// while
//////////////////////////////////////
TEST(testBraceFor, 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");
//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) {
testInterface system;
bool ret = system.execute("variable result = 0; variable i=1; while (i<10) { result = result + i; i++;}");
EXPECT_EQ(ret, true);
EXPECT_EQ(system.exist("result"), true);
EXPECT_EQ(system.isInteger32("result"), true);
EXPECT_EQ(system.getInteger32("result"), 45);
TEST(testBraceFor, 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");
//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_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);
}

View File

@ -3,54 +3,258 @@
* @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>
#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) {
testInterface system;
bool ret = system.execute("function add(a,b) { return a+b; }; variable result = add(222,33);");
EXPECT_EQ(ret, true);
EXPECT_EQ(system.exist("result"), true);
EXPECT_EQ(system.isInteger32("result"), true);
EXPECT_EQ(system.getInteger32("result"), 255);
TEST(testBraceFunction, brace_function_0000) {
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, function_in_object) {
testInterface system;
bool ret = system.execute("variable myObject= {};myObject.add = function(a,b) { return a+b; }; variable result = myObject.add(222,33);");
EXPECT_EQ(ret, true);
EXPECT_EQ(system.exist("result"), true);
EXPECT_EQ(system.isInteger32("result"), true);
EXPECT_EQ(system.getInteger32("result"), 255);
TEST(testBraceFunction, brace_function_1000) {
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_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) {
testInterface system;
bool ret = system.execute("variable myObject= { add : function(a,b) { return a+b; } }; variable result = myObject.add(222,33);");
EXPECT_EQ(ret, true);
EXPECT_EQ(system.exist("result"), true);
EXPECT_EQ(system.isInteger32("result"), true);
EXPECT_EQ(system.getInteger32("result"), 255);
TEST(testBraceFunction, brace_function_0100) {
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_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);
}

View File

@ -10,9 +10,9 @@
#include <test-debug/debug.hpp>
#include <etest/etest.hpp>
etk::String sourceIf1Action = "action_A;if(true){action_B;}action_D;";
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 sourceIf1Action = "action_A;if(true){action_B;}action_D;";
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) {