estyle/test/testFor.cpp

310 lines
15 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 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;";
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(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(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);
}
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(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);
}