Skip to content

Commit

Permalink
formatter_test: Added end-to-end always_wrap_module_instantiations tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Bylicki <[email protected]>
  • Loading branch information
jbylicki committed May 5, 2023
1 parent 8d48a04 commit f25c9f4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions verilog/formatting/formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15438,6 +15438,42 @@ TEST(FormatterEndToEndTest, VerilogFormatTest) {
}
}

TEST(FormatterEndToEndTest, AlwaysWrapModuleInstantiation) {
static constexpr FormatterTestCase kTestCases[] = {
{" module foo ; bar bq();endmodule\n",
"module foo;\n"
" bar bq ();\n" // single instance
"endmodule\n"},
{" module foo ; bar bq(), bq2( );endmodule\n",
"module foo;\n"
" bar bq (), bq2 ();\n" // multiple empty instances, still fitting on one line
"endmodule\n"},
{"module foo; bar #(.N(N)) bq (.bus(bus));endmodule\n",
// instance parameter and port fits on line
"module foo;\n"
" bar #(\n .N(N)\n ) bq (\n .bus(bus)\n );\n"
"endmodule\n"},
{"module foo; bar bq (.bus(bus));endmodule\n",
"module foo;\n"
" bar bq (\n .bus(bus)\n );\n"
"endmodule\n"},
};
FormatStyle style;
style.column_limit = 40;
style.indentation_spaces = 2;
style.wrap_spaces = 4;
style.always_wrap_module_instantiations = true;
for (const auto& test_case : kTestCases) {
VLOG(1) << "code-to-format:\n" << test_case.input << "<EOF>";
std::ostringstream stream;
const auto status =
FormatVerilog(test_case.input, "<filename>", style, stream);
// Require these test cases to be valid.
EXPECT_OK(status) << status.message();
EXPECT_EQ(stream.str(), test_case.expected) << "code:\n" << test_case.input;
}
}

TEST(FormatterEndToEndTest, AutoInferAlignment) {
static constexpr FormatterTestCase kTestCases[] = {
{"", ""},
Expand Down

0 comments on commit f25c9f4

Please sign in to comment.