Remove duplicate newl at end of code generation for a file

This commit is contained in:
Jonathan Müller 2017-05-25 21:25:25 +02:00
commit 59eee1f75a
2 changed files with 7 additions and 8 deletions

View file

@ -60,8 +60,10 @@ namespace
code_generator::output output(type_safe::ref(generator), type_safe::ref(f), true); code_generator::output output(type_safe::ref(generator), type_safe::ref(f), true);
if (output) if (output)
{ {
write_container(output, f, newl); auto need_sep = write_container(output, f, newl);
output << newl; if (!need_sep)
// file empty, write newl
output << newl;
} }
} }

View file

@ -35,8 +35,7 @@ enum class bar
void func(int(*)(int)); void func(int(*)(int));
extern void(* ptr)(int(*)(int))=&func; extern void(* ptr)(int(*)(int))=&func;)";
)";
auto file = parse({}, "code_generator.cpp", code); auto file = parse({}, "code_generator.cpp", code);
REQUIRE(get_code(*file) == code); REQUIRE(get_code(*file) == code);
@ -49,8 +48,7 @@ namespace a {}
namespace b = a; namespace b = a;
using c = int*; using c = int*;
typedef int d; typedef int d;)";
)";
auto synopsis = R"(namespace a{ auto synopsis = R"(namespace a{
} }
@ -59,8 +57,7 @@ namespace b=excluded;
using c=excluded; using c=excluded;
using d=excluded; using d=excluded;)";
)";
auto file = parse({}, "code_generator_exclude_target.cpp", code); auto file = parse({}, "code_generator_exclude_target.cpp", code);
REQUIRE(get_code(*file, code_generator::exclude_target) == synopsis); REQUIRE(get_code(*file, code_generator::exclude_target) == synopsis);