estyle/test/testIf.cpp

369 lines
17 KiB
C++

/**
* @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 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(testIf, brace_0000) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
//interface.properties.set("brace-if-in-space-before", "true");
//interface.properties.set("brace-if-in-space-after", "true");
//interface.properties.set("brace-if-out-new-line-before", "true");
//interface.properties.set("brace-if-out-new-line-after", "true");
//interface.properties.set("brace-if-out-space-before", "true");
//interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true){action_B;}action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_1000) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
//interface.properties.set("brace-if-in-space-before", "true");
//interface.properties.set("brace-if-in-space-after", "true");
interface.properties.set("brace-if-out-new-line-before", "true");
//interface.properties.set("brace-if-out-new-line-after", "true");
//interface.properties.set("brace-if-out-space-before", "true");
//interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true)\n{action_B;\n}action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_1010) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
interface.properties.set("brace-if-in-space-before", "true");
//interface.properties.set("brace-if-in-space-after", "true");
interface.properties.set("brace-if-out-new-line-before", "true");
//interface.properties.set("brace-if-out-new-line-after", "true");
interface.properties.set("brace-if-out-space-before", "true");
//interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true)\n{action_B;\n}action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_1011) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
interface.properties.set("brace-if-in-space-before", "true");
interface.properties.set("brace-if-in-space-after", "true");
interface.properties.set("brace-if-out-new-line-before", "true");
//interface.properties.set("brace-if-out-new-line-after", "true");
interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true)\n{ action_B;\n} action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_1100) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
//interface.properties.set("brace-if-in-space-before", "true");
//interface.properties.set("brace-if-in-space-after", "true");
interface.properties.set("brace-if-out-new-line-before", "true");
interface.properties.set("brace-if-out-new-line-after", "true");
//interface.properties.set("brace-if-out-space-before", "true");
//interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_1101) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
//interface.properties.set("brace-if-in-space-before", "true");
interface.properties.set("brace-if-in-space-after", "true");
interface.properties.set("brace-if-out-new-line-before", "true");
interface.properties.set("brace-if-out-new-line-after", "true");
//interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_1110) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
interface.properties.set("brace-if-in-space-before", "true");
//interface.properties.set("brace-if-in-space-after", "true");
interface.properties.set("brace-if-out-new-line-before", "true");
interface.properties.set("brace-if-out-new-line-after", "true");
interface.properties.set("brace-if-out-space-before", "true");
//interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_1111) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
interface.properties.set("brace-if-in-space-before", "true");
interface.properties.set("brace-if-in-space-after", "true");
interface.properties.set("brace-if-out-new-line-before", "true");
interface.properties.set("brace-if-out-new-line-after", "true");
interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_1001) {
estyle::Generator interface;
interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
//interface.properties.set("brace-if-in-space-before", "true");
interface.properties.set("brace-if-in-space-after", "true");
interface.properties.set("brace-if-out-new-line-before", "true");
//interface.properties.set("brace-if-out-new-line-after", "true");
//interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true)\n{ action_B;\n} action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_0100) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
//interface.properties.set("brace-if-in-space-before", "true");
//interface.properties.set("brace-if-in-space-after", "true");
//interface.properties.set("brace-if-out-new-line-before", "true");
interface.properties.set("brace-if-out-new-line-after", "true");
//interface.properties.set("brace-if-out-space-before", "true");
//interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true){\n\taction_B;}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_0101) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
//interface.properties.set("brace-if-in-space-before", "true");
interface.properties.set("brace-if-in-space-after", "true");
//interface.properties.set("brace-if-out-new-line-before", "true");
interface.properties.set("brace-if-out-new-line-after", "true");
//interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true){\n\taction_B;}\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_0110) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
interface.properties.set("brace-if-in-space-before", "true");
//interface.properties.set("brace-if-in-space-after", "true");
//interface.properties.set("brace-if-out-new-line-before", "true");
interface.properties.set("brace-if-out-new-line-after", "true");
interface.properties.set("brace-if-out-space-before", "true");
//interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true) {\n\taction_B; }\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_0010) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
interface.properties.set("brace-if-in-space-before", "true");
//interface.properties.set("brace-if-in-space-after", "true");
//interface.properties.set("brace-if-out-new-line-before", "true");
//interface.properties.set("brace-if-out-new-line-after", "true");
interface.properties.set("brace-if-out-space-before", "true");
//interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true) {action_B; }action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_0011) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
interface.properties.set("brace-if-in-space-before", "true");
interface.properties.set("brace-if-in-space-after", "true");
//interface.properties.set("brace-if-out-new-line-before", "true");
//interface.properties.set("brace-if-out-new-line-after", "true");
interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true) { action_B; } action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_0111) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
interface.properties.set("brace-if-in-new-line-after", "true");
interface.properties.set("brace-if-in-space-before", "true");
interface.properties.set("brace-if-in-space-after", "true");
//interface.properties.set("brace-if-out-new-line-before", "true");
interface.properties.set("brace-if-out-new-line-after", "true");
interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true) {\n\taction_B; }\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_0001) {
estyle::Generator interface;
//interface.properties.set("brace-if-in-new-line-before", "true");
//interface.properties.set("brace-if-in-new-line-after", "true");
//interface.properties.set("brace-if-in-space-before", "true");
interface.properties.set("brace-if-in-space-after", "true");
//interface.properties.set("brace-if-out-new-line-before", "true");
//interface.properties.set("brace-if-out-new-line-after", "true");
//interface.properties.set("brace-if-out-space-before", "true");
interface.properties.set("brace-if-out-space-after", "true");
//interface.properties.set("brace-if-single", "true");
etk::String outRef = "action_A;if(true){ action_B;} action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_single_00) {
estyle::Generator interface;
//interface.properties.set("brace-if-single-one-line-size-max", "40");
interface.properties.set("brace-if-single", "true");
//interface.properties.set("brace-if-single-in-new-line", "true");
//interface.properties.set("brace-if-single-in-space", "true");
//interface.properties.set("brace-if-single-out-new-line", "true");
//interface.properties.set("brace-if-single-out-space", "true");
etk::String outRef = "action_A;if(true)action_B;action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_single_10) {
estyle::Generator interface;
//interface.properties.set("brace-if-single-one-line-size-max", "40");
interface.properties.set("brace-if-single", "true");
interface.properties.set("brace-if-single-in-new-line", "true");
//interface.properties.set("brace-if-single-in-space", "true");
interface.properties.set("brace-if-single-out-new-line", "true");
//interface.properties.set("brace-if-single-out-space", "true");
etk::String outRef = "action_A;if(true)\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_single_01) {
estyle::Generator interface;
//interface.properties.set("brace-if-single-one-line-size-max", "40");
interface.properties.set("brace-if-single", "true");
//interface.properties.set("brace-if-single-in-new-line", "true");
interface.properties.set("brace-if-single-in-space", "true");
//interface.properties.set("brace-if-single-out-new-line", "true");
interface.properties.set("brace-if-single-out-space", "true");
etk::String outRef = "action_A;if(true) action_B; action_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testIf, brace_single_11) {
estyle::Generator interface;
//interface.properties.set("brace-if-single-one-line-size-max", "40");
interface.properties.set("brace-if-single", "true");
interface.properties.set("brace-if-single-in-new-line", "true");
interface.properties.set("brace-if-single-in-space", "true");
interface.properties.set("brace-if-single-out-new-line", "true");
interface.properties.set("brace-if-single-out-space", "true");
etk::String outRef = "action_A;if(true)\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceIf1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceIf1ActionNoBrace);
EXPECT_EQ(output, outRef);
}