Skip to content

Commit

Permalink
Update macro call arg tests with comment test cases.
Browse files Browse the repository at this point in the history
Filed bug for the one formatter_test test case that is still wrong.

issues #225

PiperOrigin-RevId: 302728312
  • Loading branch information
fangism authored and hzeller committed Mar 24, 2020
1 parent 67beaba commit 0dac7a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
13 changes: 9 additions & 4 deletions verilog/formatting/formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,15 @@ static const std::initializer_list<FormatterTestCase> kFormatterTestCases = {
" aa, //bb\n"
" bb, // cc\n"
" cc)\n"},
{// macro call with argument including comment
"`FOO(aa, bb//cc\ndd)\n",
"`FOO(aa, bb//cc\n"
"dd)\n"}, // TODO(fangism): Improve formatting arguments with comments
{// macro call with argument including trailing EOL comment
"`FOO(aa, bb,//cc\ndd)\n",
"`FOO(aa, bb, //cc\n"
" dd)\n"},
{// macro call with argument including EOL comment on own line
"`FOOOO(aa, bb,\n//cc\ndd)\n",
"`FOOOO(aa, bb, //cc\n"
// TODO(b/152324712): //cc comment should start its own line
" dd)\n"},
{" // leading comment\n"
" `define FOO \\\n" // multiline macro definition
"1\n"
Expand Down
1 change: 1 addition & 0 deletions verilog/formatting/tree_unwrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,7 @@ void TreeUnwrapper::Visit(const verible::SyntaxTreeLeaf& leaf) {
// Pick one, even if both work.
if (current_context_.DirectParentIsOneOf({
// NodeEnum:xxxx // due to element:
NodeEnum::kMacroArgList, // MacroArg
NodeEnum::kPortDeclarationList, // kPort, kPortDeclaration
NodeEnum::kPortActualList, // kActualNamedPort,
// kActualPositionalPort
Expand Down
21 changes: 14 additions & 7 deletions verilog/formatting/tree_unwrapper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3349,24 +3349,31 @@ const TreeUnwrapperTestData kUnwrapPreprocessorTestCases[] = {
"macro call with comments in argument list",
"`FOO(aa, //aa\nbb , // bb\ncc)\n",
N(0, L(0, {"`FOO", "("}),
N(2, L(2, {"aa"}), L(2, {",", "//aa"}), L(2, {"bb"}),
L(2, {",", "// bb"}), L(2, {"cc", ")"}))),
N(2, //
L(2, {"aa", ",", "//aa"}), //
L(2, {"bb", ",", "// bb"}), //
L(2, {"cc", ")"}))),
},

{
"macro call with comment before first argument",
"`FOO(// aa\naa, // bb\nbb, // cc\ncc)\n",
N(0, L(0, {"`FOO", "(", "// aa"}),
N(2, L(2, {"aa"}), L(2, {",", "// bb"}), L(2, {"bb"}),
L(2, {",", "// cc"}), L(2, {"cc", ")"}))),
N(2, //
L(2, {"aa", ",", "// bb"}), //
L(2, {"bb", ",", "// cc"}), //
L(2, {"cc", ")"}))),
},

{
// TODO(fangism): Improve formatting arguments with comments
"macro call with argument including comment",
"`FOO(aa, bb // cc\ndd)\n",
"`FOO(aa, bb,\n// cc\ndd)\n",
N(0, L(0, {"`FOO", "("}),
N(2, L(2, {"aa", ","}), L(2, {"bb // cc\ndd", ")"}))),
N(2, //
L(2, {"aa", ","}), //
L(2, {"bb", ","}), //
L(2, {"// cc"}), // indented to same level as surrounding args
L(2, {"dd", ")"}))),
},

{
Expand Down

0 comments on commit 0dac7a3

Please sign in to comment.