From 59eee1f75a701432cb6766cdd42adc8ae7a0f7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Thu, 25 May 2017 21:25:25 +0200 Subject: [PATCH] Remove duplicate newl at end of code generation for a file --- src/code_generator.cpp | 6 ++++-- test/code_generator.cpp | 9 +++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/code_generator.cpp b/src/code_generator.cpp index fa78193..2a6dc53 100644 --- a/src/code_generator.cpp +++ b/src/code_generator.cpp @@ -60,8 +60,10 @@ namespace code_generator::output output(type_safe::ref(generator), type_safe::ref(f), true); if (output) { - write_container(output, f, newl); - output << newl; + auto need_sep = write_container(output, f, newl); + if (!need_sep) + // file empty, write newl + output << newl; } } diff --git a/test/code_generator.cpp b/test/code_generator.cpp index e6e9d56..7f0cd7e 100644 --- a/test/code_generator.cpp +++ b/test/code_generator.cpp @@ -35,8 +35,7 @@ enum class bar void func(int(*)(int)); -extern void(* ptr)(int(*)(int))=&func; -)"; +extern void(* ptr)(int(*)(int))=&func;)"; auto file = parse({}, "code_generator.cpp", code); REQUIRE(get_code(*file) == code); @@ -49,8 +48,7 @@ namespace a {} namespace b = a; using c = int*; -typedef int d; -)"; +typedef int d;)"; auto synopsis = R"(namespace a{ } @@ -59,8 +57,7 @@ namespace b=excluded; using c=excluded; -using d=excluded; -)"; +using d=excluded;)"; auto file = parse({}, "code_generator_exclude_target.cpp", code); REQUIRE(get_code(*file, code_generator::exclude_target) == synopsis);