estyle/test/testElse.cpp

372 lines
18 KiB
C++
Raw Normal View History

/**
* @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;";
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_0000) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
//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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_1000) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
//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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_1010) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_1011) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_1100) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
//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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_1101) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
//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");
2018-01-01 04:05:20 +01:00
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_1110) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_1111) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
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");
2018-01-01 04:05:20 +01:00
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_1001) {
estyle::Generator interface;
interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
//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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_0100) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
//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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_0101) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
//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");
2018-01-01 04:05:20 +01:00
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_0110) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_0010) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_0011) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_0111) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
interface.properties.set("brace-else-in-new-line-after", "true");
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");
2018-01-01 04:05:20 +01:00
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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_0001) {
estyle::Generator interface;
//interface.properties.set("brace-else-in-new-line-before", "true");
//interface.properties.set("brace-else-in-new-line-after", "true");
//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);
}
2018-01-01 04:05:20 +01:00
TEST(testElse, brace_else_single_00) {
estyle::Generator interface;
//interface.properties.set("brace-else-single-one-line-size-max", "40");
interface.properties.set("brace-else-single", "true");
//interface.properties.set("brace-else-single-in-new-line", "true");
//interface.properties.set("brace-else-single-in-space", "true");
//interface.properties.set("brace-else-single-out-new-line", "true");
//interface.properties.set("brace-else-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else action_B;\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testElse, brace_else_single_10) {
estyle::Generator interface;
//interface.properties.set("brace-else-single-one-line-size-max", "40");
interface.properties.set("brace-else-single", "true");
interface.properties.set("brace-else-single-in-new-line", "true");
//interface.properties.set("brace-else-single-in-space", "true");
interface.properties.set("brace-else-single-out-new-line", "true");
//interface.properties.set("brace-else-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testElse, brace_else_single_01) {
estyle::Generator interface;
//interface.properties.set("brace-else-single-one-line-size-max", "40");
interface.properties.set("brace-else-single", "true");
//interface.properties.set("brace-else-single-in-new-line", "true");
interface.properties.set("brace-else-single-in-space", "true");
//interface.properties.set("brace-else-single-out-new-line", "true");
interface.properties.set("brace-else-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else action_B; action_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}
TEST(testElse, brace_else_single_11) {
estyle::Generator interface;
//interface.properties.set("brace-else-single-one-line-size-max", "40");
interface.properties.set("brace-else-single", "true");
interface.properties.set("brace-else-single-in-new-line", "true");
interface.properties.set("brace-else-single-in-space", "true");
interface.properties.set("brace-else-single-out-new-line", "true");
interface.properties.set("brace-else-single-out-space", "true");
etk::String outputRef = "action_A;\nif (true ){action_K:} else\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceElse1Action);
EXPECT_EQ(output, outputRef);
output = interface.process(sourceElse1ActionNoBrace);
EXPECT_EQ(output, outputRef);
}