Skip to content

Commit

Permalink
No space between 'default' and ':'.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 282073240
  • Loading branch information
fangism authored and hzeller committed Dec 2, 2019
1 parent 376f335 commit 8ab6d9b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions verilog/formatting/formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,13 @@ static const std::initializer_list<FormatterTestCase> kFormatterTestCases = {
" assign a = 1;\n"
" end\n"
"endmodule\n"},
{// "default:", not "default :"
"function f; case (x) default: x=y; endcase endfunction\n",
"function f;\n"
" case (x)\n"
" default: x = y;\n"
" endcase\n"
"endfunction\n"},

// This tests checks for not breaking around hierarchy operators.
{"function\nvoid\twarranty;"
Expand Down
8 changes: 7 additions & 1 deletion verilog/formatting/token_annotator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,16 @@ static WithReason<int> SpacesRequiredBetween(const PreFormatToken& left,

// Keywords:

if (right.TokenEnum() == ':') {
if (left.TokenEnum() == TK_default) {
return {0, "No space inside \"default:\""};
}
}

// "if (...)", "for (...) instead of "if(...)", "for(...)",
// "case ...", "return ..."
if (left.format_token_enum == FormatTokenType::keyword) {
// Make sure function-like keywords, however, to not get a space.
// TODO(b/144605476): function-like keywords, however, do not get a space.
return {1, "Space between flow control keywords and ("};
}

Expand Down
8 changes: 8 additions & 0 deletions verilog/formatting/token_annotator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,14 @@ TEST(TokenAnnotatorTest, AnnotateFormattingInfoTest) {
{yytokentype::TK_1step, "1step"},
{';', ";"},
}},

// default:
{DefaultStyle,
0,
{{0, SpacingOptions::Undecided}, {0, SpacingOptions::Undecided}},
{{yytokentype::TK_default, "default"}, {':', ":"}}},

// TODO(fangism): ": ;"
};

int test_index = 0;
Expand Down

0 comments on commit 8ab6d9b

Please sign in to comment.