estyle/test/testDoWhile.cpp

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