diff --git a/verilog/formatting/formatter_test.cc b/verilog/formatting/formatter_test.cc index b7397c01e..bf438b9d1 100644 --- a/verilog/formatting/formatter_test.cc +++ b/verilog/formatting/formatter_test.cc @@ -4870,12 +4870,16 @@ static const std::initializer_list kFormatterTestCases = { " a |-> ##1 b;\n" // with delay " endproperty\n" "endmodule\n"}, - {"module mp ;property p1 ; a|->## [0:1] b;endproperty endmodule", + {"module mp ;property p1 ; a|->## [0: 1] b;endproperty endmodule", "module mp;\n" " property p1;\n" - " a |-> ##[0: 1] b;\n" // with delay range - // TODO(b/152411381): fix spacing between "0:" - // (context-sensitive) + " a |-> ##[0:1] b;\n" // prefer no spaces with delay range + " endproperty\n" + "endmodule\n"}, + {"module mp ;property p1 ; a|->## [0 : 1] b;endproperty endmodule", + "module mp;\n" + " property p1;\n" + " a |-> ##[0 : 1] b;\n" // limit to one space, symmetrize " endproperty\n" "endmodule\n"}, {"module mp ;property p1 ; a## 1 b;endproperty endmodule", diff --git a/verilog/formatting/token_annotator.cc b/verilog/formatting/token_annotator.cc index 62a5f9f73..1815ae9c1 100644 --- a/verilog/formatting/token_annotator.cc +++ b/verilog/formatting/token_annotator.cc @@ -110,7 +110,7 @@ static bool PairwiseNonmergeable(const PreFormatToken& ftoken) { static bool InRangeLikeContext(const SyntaxTreeContext& context) { return context.IsInsideFirst( {NodeEnum::kSelectVariableDimension, NodeEnum::kDimensionRange, - NodeEnum::kDimensionSlice}, + NodeEnum::kDimensionSlice, NodeEnum::kCycleDelayRange}, {}); } diff --git a/verilog/formatting/token_annotator_test.cc b/verilog/formatting/token_annotator_test.cc index d0fa2e288..50346864c 100644 --- a/verilog/formatting/token_annotator_test.cc +++ b/verilog/formatting/token_annotator_test.cc @@ -3491,6 +3491,42 @@ TEST(TokenAnnotatorTest, AnnotateFormattingWithContextTest) { // no spaces preceding ':' in unit test context {0, SpacingOptions::Undecided}, }, + { + // [1:0] + DefaultStyle, + {verilog_tokentype::TK_DecNumber, "1"}, + {':', ":"}, + {NodeEnum::kCycleDelayRange}, + // no spaces preceding ':' in unit test context + {0, SpacingOptions::Undecided}, + }, + { + // [1:0] + DefaultStyle, + {':', ":"}, + {verilog_tokentype::TK_DecNumber, "0"}, + {NodeEnum::kCycleDelayRange}, + // no spaces preceding ':' in unit test context + {0, SpacingOptions::Undecided}, + }, + { + // [a:b] + DefaultStyle, + {SymbolIdentifier, "a"}, + {':', ":"}, + {NodeEnum::kCycleDelayRange}, + // no spaces preceding ':' in unit test context + {0, SpacingOptions::Undecided}, + }, + { + // [a:b] + DefaultStyle, + {':', ":"}, + {SymbolIdentifier, "b"}, + {NodeEnum::kCycleDelayRange}, + // no spaces preceding ':' in unit test context + {0, SpacingOptions::Undecided}, + }, { // [1:0] DefaultStyle,