estyle/test/testWhile.cpp

443 lines
21 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 sourceWhile1Action = "action_A;while(true){action_B;}action_D;";
static etk::String sourceWhile1ActionNoBrace = "action_A;while(true)action_B;action_D;";
static etk::String sourceWhile2Action = "action_A;while(true){action_B;action_C;}action_D;";
TEST(testWhile, brace_while_0000) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
//interface.properties.set("brace-while-in-space-after", "true");
//interface.properties.set("brace-while-out-new-line-before", "true");
//interface.properties.set("brace-while-out-new-line-after", "true");
//interface.properties.set("brace-while-out-space-before", "true");
//interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true){action_B;}action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_1000) {
estyle::Generator interface;
interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
//interface.properties.set("brace-while-in-space-after", "true");
interface.properties.set("brace-while-out-new-line-before", "true");
//interface.properties.set("brace-while-out-new-line-after", "true");
//interface.properties.set("brace-while-out-space-before", "true");
//interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true)\n{action_B;\n}action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_1010) {
estyle::Generator interface;
interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
interface.properties.set("brace-while-in-space-before", "true");
//interface.properties.set("brace-while-in-space-after", "true");
interface.properties.set("brace-while-out-new-line-before", "true");
//interface.properties.set("brace-while-out-new-line-after", "true");
interface.properties.set("brace-while-out-space-before", "true");
//interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true)\n{action_B;\n}action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_1011) {
estyle::Generator interface;
interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
interface.properties.set("brace-while-in-space-before", "true");
interface.properties.set("brace-while-in-space-after", "true");
interface.properties.set("brace-while-out-new-line-before", "true");
//interface.properties.set("brace-while-out-new-line-after", "true");
interface.properties.set("brace-while-out-space-before", "true");
interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true)\n{ action_B;\n} action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_1100) {
estyle::Generator interface;
interface.properties.set("brace-while-in-new-line-before", "true");
interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
//interface.properties.set("brace-while-in-space-after", "true");
interface.properties.set("brace-while-out-new-line-before", "true");
interface.properties.set("brace-while-out-new-line-after", "true");
//interface.properties.set("brace-while-out-space-before", "true");
//interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_1101) {
estyle::Generator interface;
interface.properties.set("brace-while-in-new-line-before", "true");
interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
interface.properties.set("brace-while-in-space-after", "true");
interface.properties.set("brace-while-out-new-line-before", "true");
interface.properties.set("brace-while-out-new-line-after", "true");
//interface.properties.set("brace-while-out-space-before", "true");
interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_1110) {
estyle::Generator interface;
interface.properties.set("brace-while-in-new-line-before", "true");
interface.properties.set("brace-while-in-new-line-after", "true");
interface.properties.set("brace-while-in-space-before", "true");
//interface.properties.set("brace-while-in-space-after", "true");
interface.properties.set("brace-while-out-new-line-before", "true");
interface.properties.set("brace-while-out-new-line-after", "true");
interface.properties.set("brace-while-out-space-before", "true");
//interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_1111) {
estyle::Generator interface;
interface.properties.set("brace-while-in-new-line-before", "true");
interface.properties.set("brace-while-in-new-line-after", "true");
interface.properties.set("brace-while-in-space-before", "true");
interface.properties.set("brace-while-in-space-after", "true");
interface.properties.set("brace-while-out-new-line-before", "true");
interface.properties.set("brace-while-out-new-line-after", "true");
interface.properties.set("brace-while-out-space-before", "true");
interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true)\n{\n\taction_B;\n}\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_1001) {
estyle::Generator interface;
interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
interface.properties.set("brace-while-in-space-after", "true");
interface.properties.set("brace-while-out-new-line-before", "true");
//interface.properties.set("brace-while-out-new-line-after", "true");
//interface.properties.set("brace-while-out-space-before", "true");
interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true)\n{ action_B;\n} action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_0100) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
//interface.properties.set("brace-while-in-space-after", "true");
//interface.properties.set("brace-while-out-new-line-before", "true");
interface.properties.set("brace-while-out-new-line-after", "true");
//interface.properties.set("brace-while-out-space-before", "true");
//interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true){\n\taction_B;}\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_0101) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
interface.properties.set("brace-while-in-space-after", "true");
//interface.properties.set("brace-while-out-new-line-before", "true");
interface.properties.set("brace-while-out-new-line-after", "true");
//interface.properties.set("brace-while-out-space-before", "true");
interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true){\n\taction_B;}\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_0110) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
interface.properties.set("brace-while-in-new-line-after", "true");
interface.properties.set("brace-while-in-space-before", "true");
//interface.properties.set("brace-while-in-space-after", "true");
//interface.properties.set("brace-while-out-new-line-before", "true");
interface.properties.set("brace-while-out-new-line-after", "true");
interface.properties.set("brace-while-out-space-before", "true");
//interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true) {\n\taction_B; }\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_0010) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
interface.properties.set("brace-while-in-space-before", "true");
//interface.properties.set("brace-while-in-space-after", "true");
//interface.properties.set("brace-while-out-new-line-before", "true");
//interface.properties.set("brace-while-out-new-line-after", "true");
interface.properties.set("brace-while-out-space-before", "true");
//interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true) {action_B; }action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_0011) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
interface.properties.set("brace-while-in-space-before", "true");
interface.properties.set("brace-while-in-space-after", "true");
//interface.properties.set("brace-while-out-new-line-before", "true");
//interface.properties.set("brace-while-out-new-line-after", "true");
interface.properties.set("brace-while-out-space-before", "true");
interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true) { action_B; } action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_0111) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
interface.properties.set("brace-while-in-new-line-after", "true");
interface.properties.set("brace-while-in-space-before", "true");
interface.properties.set("brace-while-in-space-after", "true");
//interface.properties.set("brace-while-out-new-line-before", "true");
interface.properties.set("brace-while-out-new-line-after", "true");
interface.properties.set("brace-while-out-space-before", "true");
interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true) {\n\taction_B; }\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_0001) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
interface.properties.set("brace-while-in-space-after", "true");
//interface.properties.set("brace-while-out-new-line-before", "true");
//interface.properties.set("brace-while-out-new-line-after", "true");
//interface.properties.set("brace-while-out-space-before", "true");
interface.properties.set("brace-while-out-space-after", "true");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true){ action_B;} action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_single_00) {
estyle::Generator interface;
//interface.properties.set("brace-while-single-one-line-size-max", "40");
interface.properties.set("brace-while-single", "true");
//interface.properties.set("brace-while-single-in-new-line", "true");
//interface.properties.set("brace-while-single-in-space", "true");
//interface.properties.set("brace-while-single-out-new-line", "true");
//interface.properties.set("brace-while-single-out-space", "true");
etk::String outRef = "action_A;while(true)action_B;action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_single_10) {
estyle::Generator interface;
//interface.properties.set("brace-while-single-one-line-size-max", "40");
interface.properties.set("brace-while-single", "true");
interface.properties.set("brace-while-single-in-new-line", "true");
//interface.properties.set("brace-while-single-in-space", "true");
interface.properties.set("brace-while-single-out-new-line", "true");
//interface.properties.set("brace-while-single-out-space", "true");
etk::String outRef = "action_A;while(true)\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_single_01) {
estyle::Generator interface;
//interface.properties.set("brace-while-single-one-line-size-max", "40");
interface.properties.set("brace-while-single", "true");
//interface.properties.set("brace-while-single-in-new-line", "true");
interface.properties.set("brace-while-single-in-space", "true");
//interface.properties.set("brace-while-single-out-new-line", "true");
interface.properties.set("brace-while-single-out-space", "true");
etk::String outRef = "action_A;while(true) action_B; action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_single_11) {
estyle::Generator interface;
//interface.properties.set("brace-while-single-one-line-size-max", "40");
interface.properties.set("brace-while-single", "true");
interface.properties.set("brace-while-single-in-new-line", "true");
interface.properties.set("brace-while-single-in-space", "true");
interface.properties.set("brace-while-single-out-new-line", "true");
interface.properties.set("brace-while-single-out-space", "true");
etk::String outRef = "action_A;while(true)\n\taction_B;\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_oneLine_0) {
estyle::Generator interface;
interface.properties.set("brace-while-in-new-line-before", "true");
interface.properties.set("brace-while-in-new-line-after", "true");
interface.properties.set("brace-while-in-space-before", "true");
interface.properties.set("brace-while-in-space-after", "true");
interface.properties.set("brace-while-out-new-line-before", "true");
interface.properties.set("brace-while-out-new-line-after", "true");
interface.properties.set("brace-while-out-space-before", "true");
//interface.properties.set("brace-while-out-space-after", "true");
interface.properties.set("brace-while-single-one-line-size-max", "40");
//interface.properties.set("brace-while-single", "true");
etk::String outRef = "action_A;while(true) { action_B; }\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, brace_while_oneLine_1) {
estyle::Generator interface;
interface.properties.set("brace-while-single-one-line-size-max", "40");
interface.properties.set("brace-while-single", "true");
interface.properties.set("brace-while-single-in-new-line", "true");
interface.properties.set("brace-while-single-in-space", "true");
interface.properties.set("brace-while-single-out-new-line", "true");
interface.properties.set("brace-while-single-out-space", "true");
etk::String outRef = "action_A;while(true) action_B;\naction_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
output = interface.process(sourceWhile1ActionNoBrace);
EXPECT_EQ(output, outRef);
}
TEST(testWhile, condition_0) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
etk::String outRef = "action_A;while(true){action_B;}action_D;";
etk::String output = interface.process(sourceWhile1Action);
EXPECT_EQ(output, outRef);
//output = interface.process(sourceWhile1ActionNoBrace);
//EXPECT_EQ(output, outRef);
}
TEST(testWhile, condition_1) {
estyle::Generator interface;
//interface.properties.set("brace-while-in-new-line-before", "true");
//interface.properties.set("brace-while-in-new-line-after", "true");
//interface.properties.set("brace-while-in-space-before", "true");
etk::String outRef = "action_A;while (condition<6 && my_stupid_variable == 77){action_B;}action_D;";
etk::String base = "action_A;while(condition<6 && my_stupid_variable == 77){action_B;}action_D;";
etk::String output = interface.process(base);
EXPECT_EQ(output, outRef);
interface.properties.set("condition-while-multi-line-big-size", "20");
output = interface.process(base);
outRef = "action_A;while ( condition<6\n && my_stupid_variable==77 ){action_B;}action_D;";
EXPECT_EQ(output, outRef);
}