Files
lucisv/crates/vlog_formatter/tests/cases/fences.cases
T
lucioandClaude Fable 5 02f68655b5 Add error-recovery and format-fences (jointly: entangled in format.rs)
error-recovery (vlog_parser): parse_source_tolerant never fails —
errors become positioned ParseDiagnostics and ItemKind::Error /
StmtKind::Error leaves (raw text + span, nesting invariant intact),
with recovery at documented sync tokens, bracket-balanced skipping,
and stray-closer collapse. Strict parse_source is byte-identical in
behavior (shared grammar, tolerant flag). Guarantees tested:
tolerant==strict on 500 valid sources; depth/links budgets neither
reset nor leak across recovery (mutation-tested); no panic across
27k+ truncation cuts, every single-char fixture deletion, 1MB of
semicolons (500k recoveries, 344ms). The future LSP parses mid-edit
code; the formatter still refuses on the first error.

format-fences (vlog_formatter): // verilog_format: off|on and
// vfmt: off|on emit fenced item ranges as exact source bytes via
spans (Doc::Verbatim), Verible-style item-level regions per scope,
unmatched off to end of scope, byte-exact including indentation and
idempotent at every join (24 adversarial probes). ~2000 corpus fence
injections: zero region byte changes, zero new verification
failures. verify.rs untouched; with no fences output is
byte-identical (corpus TSV md5 unchanged).

Also surfaced and queued in TODO: comment-in-list refusals
(112/1868 injection trials) and the double-blank leading-comment
nit — the next comments round.

Dev: 2 Opus agents; QA: 2 Sonnet agents; reviews in
docs/features/{error-recovery,format-fences}/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-19 05:23:05 -07:00

426 lines
6.0 KiB
Plaintext

# a fenced region comes out byte-exact, weird spacing and all
module m;
// verilog_format: off
wire [3:0] a = 4'h1;
wire [31:0] bb= 32'h2;
// verilog_format: on
wire c;
endmodule
----
module m;
// verilog_format: off
wire [3:0] a = 4'h1;
wire [31:0] bb= 32'h2;
// verilog_format: on
wire c;
endmodule
====
# the vfmt alias fences the same region
module m;
// vfmt: off
wire [3:0] a;
// vfmt: on
wire b;
endmodule
----
module m;
// vfmt: off
wire [3:0] a;
// vfmt: on
wire b;
endmodule
====
# the two spellings are interchangeable across one region
module m;
// verilog_format: off
wire a;
// vfmt: on
wire b;
endmodule
----
module m;
// verilog_format: off
wire a;
// vfmt: on
wire b;
endmodule
====
# a region keeps its own indentation, first line included
module m;
// vfmt: off
wire a;
wire b;
// vfmt: on
wire c;
endmodule
----
module m;
// vfmt: off
wire a;
wire b;
// vfmt: on
wire c;
endmodule
====
# a fence at the top of the file
// vfmt: off
module m; endmodule
// vfmt: on
module n;
wire a;
endmodule
----
// vfmt: off
module m; endmodule
// vfmt: on
module n;
wire a;
endmodule
====
# an unmatched off runs to the end of the file
module m;
wire a;
endmodule
// vfmt: off
module n; wire b; endmodule
----
module m;
wire a;
endmodule
// vfmt: off
module n; wire b; endmodule
====
# an unmatched off runs to the end of the module body, not past endmodule
module m;
wire a;
// vfmt: off
wire b;
wire c;
endmodule
module n;
wire d;
endmodule
----
module m;
wire a;
// vfmt: off
wire b;
wire c;
endmodule
module n;
wire d;
endmodule
====
# an unmatched off keeps the comment trailing its last item
module m;
// vfmt: off
wire a; // note
endmodule
----
module m;
// vfmt: off
wire a; // note
endmodule
====
# an unmatched off swallows the scope's dangling comments too
module m;
// vfmt: off
wire a;
// dangling one
// dangling two
endmodule
----
module m;
// vfmt: off
wire a;
// dangling one
// dangling two
endmodule
====
# an on written after endmodule cannot close an off inside the module
module m;
// vfmt: off
wire a;
endmodule
// vfmt: on
module n;
wire b;
endmodule
----
module m;
// vfmt: off
wire a;
endmodule
// vfmt: on
module n;
wire b;
endmodule
====
# two regions in one file
module m;
// vfmt: off
wire a;
// vfmt: on
wire b;
// vfmt: off
wire c;
// vfmt: on
wire d;
endmodule
----
module m;
// vfmt: off
wire a;
// vfmt: on
wire b;
// vfmt: off
wire c;
// vfmt: on
wire d;
endmodule
====
# a fence with trailing text is not a fence
module m;
// vfmt: off (just for now)
wire a;
// vfmt: on
wire b;
endmodule
----
module m;
// vfmt: off (just for now)
wire a;
// vfmt: on
wire b;
endmodule
====
# a block comment is not a fence
module m;
/* vfmt: off */
wire a;
/* vfmt: on */
wire b;
endmodule
----
module m;
/* vfmt: off */
wire a;
/* vfmt: on */
wire b;
endmodule
====
# a fence written after code on the same line is not a fence
module m;
wire z; // vfmt: off
wire a;
endmodule
----
module m;
wire z; // vfmt: off
wire a;
endmodule
====
# an on with no open off is an ordinary comment
module m;
// vfmt: on
wire a;
endmodule
----
module m;
// vfmt: on
wire a;
endmodule
====
# a second off inside an open region is just text, the first on closes
module m;
// vfmt: off
wire a;
// vfmt: off
wire b;
// vfmt: on
wire c;
// vfmt: on
wire d;
endmodule
----
module m;
// vfmt: off
wire a;
// vfmt: off
wire b;
// vfmt: on
wire c;
// vfmt: on
wire d;
endmodule
====
# a region of nothing but comments
module m;
// vfmt: off
// +-------+
// | ascii |
// +-------+
// vfmt: on
wire a;
endmodule
----
module m;
// vfmt: off
// +-------+
// | ascii |
// +-------+
// vfmt: on
wire a;
endmodule
====
# comments before the off fence are still formatted, and never dropped
module m;
wire z;
// doc for the table
// vfmt: off
wire a;
// vfmt: on
wire b;
endmodule
----
module m;
wire z;
// doc for the table
// vfmt: off
wire a;
// vfmt: on
wire b;
endmodule
====
# valid-but-ugly code inside a region is left exactly as written
module m;
// vfmt: off
always@(posedge clk)if(en)q<=d;else q <= 1'b0;
assign y = {a,b , c} ;
// vfmt: on
assign z = a + b;
endmodule
----
module m;
// vfmt: off
always@(posedge clk)if(en)q<=d;else q <= 1'b0;
assign y = {a,b , c} ;
// vfmt: on
assign z = a + b;
endmodule
====
# attributes and directives inside a region are source bytes like anything else
module m;
// vfmt: off
(* keep *) wire a;
`ifdef FOO
wire b;
`endif
// vfmt: on
wire c;
endmodule
----
module m;
// vfmt: off
(* keep *) wire a;
`ifdef FOO
wire b;
`endif
// vfmt: on
wire c;
endmodule
====
# fences work in a package body
package p;
// vfmt: off
localparam int A =1;
// vfmt: on
localparam int B =2;
endpackage
----
package p;
// vfmt: off
localparam int A =1;
// vfmt: on
localparam int B = 2;
endpackage
====
# fences work inside a generate begin..end block
module m;
generate
if (X) begin : g
// vfmt: off
wire a;
// vfmt: on
wire b;
end
endgenerate
endmodule
----
module m;
generate
if (X) begin : g
// vfmt: off
wire a;
// vfmt: on
wire b;
end
endgenerate
endmodule
====
# a statement-level fence has no effect this round
module m;
always @(*) begin
// vfmt: off
x = 1;
// vfmt: on
y = 2;
end
endmodule
----
module m;
always @(*) begin
// vfmt: off
x = 1;
// vfmt: on
y = 2;
end
endmodule
====
# a blank line before the off fence survives, collapsed to one
module m;
wire z;
// vfmt: off
wire a;
// vfmt: on
endmodule
----
module m;
wire z;
// vfmt: off
wire a;
// vfmt: on
endmodule
====
# a region ending the file keeps exactly one final newline
module m;
wire a;
endmodule
// vfmt: off
`define WIDTH 8
----
module m;
wire a;
endmodule
// vfmt: off
`define WIDTH 8
====