Every tracked file that can carry a comment (880 of them) now opens with "Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with "Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com", in the file's own comment syntax. No behaviour change: the diff outside the version bump and changelogs is comment lines only. - tools/stamp_author.py: writes the lines; idempotent, `--check` lists what is missing. Headers go under a shebang and under Markdown front matter. - Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the LICENSE files (already carry the copyright line). - tools/linux_check.sh: --help reads its header from line 3, now that the author line sits under the shebang. - tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
556 lines
21 KiB
Rust
556 lines
21 KiB
Rust
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
|
|
|
//! `convert_to_ansi`: a Verilog-2001 header rewritten ANSI-style.
|
|
//!
|
|
//! Behaviour tests, written against the public API the way an editor calls it.
|
|
//! The merge rules are IEEE 1800 §23.2.2.2's, one test each; the refusals are
|
|
//! the list in `docs/features/ansi-conversion/README.md`, one test each.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use vlog_refactor::{convert_to_ansi, port_actions, RefactorEdit, TextEdit};
|
|
|
|
const TOP: &str = "/rtl/m.sv";
|
|
|
|
fn files(source: &str) -> Vec<(PathBuf, String)> {
|
|
vec![(PathBuf::from(TOP), source.to_string())]
|
|
}
|
|
|
|
/// Apply an edit to the one file it touches.
|
|
fn applied(source: &str, edit: &RefactorEdit) -> String {
|
|
let (_, edits) = edit.edits.first().expect("one file edited");
|
|
let mut out = String::new();
|
|
let mut cursor = 0usize;
|
|
for TextEdit { range, new_text } in edits {
|
|
out.push_str(&source[cursor..range.start as usize]);
|
|
out.push_str(new_text);
|
|
cursor = range.end as usize;
|
|
}
|
|
out.push_str(&source[cursor..]);
|
|
out
|
|
}
|
|
|
|
/// Convert at the module's name, which is inside every non-ANSI header.
|
|
fn convert(source: &str) -> Result<String, String> {
|
|
let at = source.find("module ").map_or(0, |i| i + 7) as u32;
|
|
let edit = convert_to_ansi(&files(source), Path::new(TOP), at)?;
|
|
assert!(edit.edits.len() == 1, "only the module's own file is edited");
|
|
Ok(applied(source, &edit))
|
|
}
|
|
|
|
/// The sentence a refusal is.
|
|
fn refused(source: &str) -> String {
|
|
convert(source).expect_err("this one is refused")
|
|
}
|
|
|
|
fn count_comments(text: &str) -> usize {
|
|
text.match_indices("//").count() + text.match_indices("/*").count()
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// IEEE 1800 §23.2.2.2, one merge rule at a time
|
|
// ----------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn a_bare_port_declaration_becomes_a_bare_ansi_port() {
|
|
let source = "module m (a, b);\n input a;\n inout b;\nendmodule\n";
|
|
assert_eq!(convert(source).expect("converted"), "module m (input a, inout b);\nendmodule\n");
|
|
}
|
|
|
|
#[test]
|
|
fn a_vector_port_keeps_its_packed_range() {
|
|
let source = "module m (b);\n output [7:0] b;\nendmodule\n";
|
|
assert_eq!(convert(source).expect("converted"), "module m (output [7:0] b);\nendmodule\n");
|
|
}
|
|
|
|
#[test]
|
|
fn a_port_completed_by_a_variable_declaration_merges_the_two() {
|
|
// The LRM's own example: `output [7:0] b; reg [7:0] b;` is `output reg
|
|
// [7:0] b`.
|
|
let source = "module m (b);\n output [7:0] b;\n reg [7:0] b;\nendmodule\n";
|
|
assert_eq!(convert(source).expect("converted"), "module m (output reg [7:0] b);\nendmodule\n");
|
|
}
|
|
|
|
#[test]
|
|
fn a_scalar_port_completed_by_a_scalar_variable_merges_too() {
|
|
let source = "module m (b);\n output b;\n reg b;\nendmodule\n";
|
|
assert_eq!(convert(source).expect("converted"), "module m (output reg b);\nendmodule\n");
|
|
}
|
|
|
|
#[test]
|
|
fn a_port_completed_by_a_logic_declaration_merges() {
|
|
let source = "module m (b);\n output b;\n logic [3:0] b;\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (output logic [3:0] b);\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_port_completed_by_a_net_declaration_merges() {
|
|
let source = "module m (a);\n input a;\n wire [1:0] a;\nendmodule\n";
|
|
assert_eq!(convert(source).expect("converted"), "module m (input wire [1:0] a);\nendmodule\n");
|
|
}
|
|
|
|
#[test]
|
|
fn a_port_declaration_that_is_already_complete_needs_no_second_one() {
|
|
let source = "module m (a);\n input wire signed [7:0] a;\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (input wire signed [7:0] a);\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn signing_written_on_either_half_reaches_the_ansi_port() {
|
|
let port = "module m (b);\n output signed [7:0] b;\n reg [7:0] b;\nendmodule\n";
|
|
assert_eq!(
|
|
convert(port).expect("converted"),
|
|
"module m (output reg signed [7:0] b);\nendmodule\n"
|
|
);
|
|
let var = "module m (b);\n output [7:0] b;\n reg signed [7:0] b;\nendmodule\n";
|
|
assert_eq!(
|
|
convert(var).expect("converted"),
|
|
"module m (output reg signed [7:0] b);\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_packed_range_written_on_only_one_half_is_the_merged_one() {
|
|
let source = "module m (b);\n output b;\n reg [7:0] b;\nendmodule\n";
|
|
assert_eq!(convert(source).expect("converted"), "module m (output reg [7:0] b);\nendmodule\n");
|
|
}
|
|
|
|
#[test]
|
|
fn identical_unpacked_dimensions_survive_the_merge() {
|
|
let source = "module m (mem);\n output [7:0] mem [0:3];\n reg [7:0] mem [0:3];\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (output reg [7:0] mem [0:3]);\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn one_declaration_may_declare_several_ports() {
|
|
let source = "module m (a, b, c);\n input a, b;\n output c;\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (input a, input b, output c);\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_user_defined_type_is_written_as_the_source_spells_it() {
|
|
let source = "module m (a);\n input a;\n pkg::word_t a;\nendmodule\n";
|
|
assert_eq!(convert(source).expect("converted"), "module m (input pkg::word_t a);\nendmodule\n");
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// layout, comments and the body
|
|
// ----------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn a_one_per_line_header_stays_one_per_line() {
|
|
let source = "module m (\n a,\n b\n);\n input a;\n output [7:0] b;\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (\n input a,\n output [7:0] b\n);\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn the_headers_own_comments_are_not_touched() {
|
|
let source = "module m (\n a, // the clock\n b\n);\n input a;\n output b;\nendmodule\n";
|
|
let out = convert(source).expect("converted");
|
|
assert!(out.contains("input a, // the clock"), "{out}");
|
|
assert_eq!(count_comments(&out), count_comments(source));
|
|
}
|
|
|
|
#[test]
|
|
fn a_trailing_comment_moves_onto_the_port_it_described() {
|
|
let source =
|
|
"module m (\n a,\n b\n);\n input a; // the clock\n output b; // the data\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (\n input a, // the clock\n output b // the data\n);\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_leading_comment_moves_onto_its_own_line_above_the_port() {
|
|
let source =
|
|
"module m (\n a,\n b\n);\n // the clock\n input a;\n output b;\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (\n // the clock\n input a,\n output b\n);\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn both_halves_of_a_merged_port_keep_their_comments() {
|
|
// Two comments never become one: a `//` swallows the line, so only one
|
|
// may sit beside the port and the rest go above it.
|
|
let source = "module m (\n b\n);\n output [7:0] b; // the port\n reg [7:0] b; // the storage\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (\n // the port\n // the storage\n output reg [7:0] b\n);\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_block_comment_moves_into_an_inline_header() {
|
|
let source = "module m (a, b);\n /* first */ input a;\n output b;\nendmodule\n";
|
|
let out = convert(source).expect("converted");
|
|
assert!(out.contains("/* first */ input a"), "{out}");
|
|
assert_eq!(count_comments(&out), count_comments(source));
|
|
}
|
|
|
|
#[test]
|
|
fn every_comment_in_the_module_survives_the_conversion() {
|
|
let source = concat!(
|
|
"// about the file\n",
|
|
"module m (\n",
|
|
" a, // in the header\n",
|
|
" b\n",
|
|
");\n",
|
|
" // above the input\n",
|
|
" input a; // beside the input\n",
|
|
" /* above the output */\n",
|
|
" output [7:0] b; /* beside the output */\n",
|
|
" // an ordinary body comment\n",
|
|
" wire c;\n",
|
|
"endmodule\n"
|
|
);
|
|
let out = convert(source).expect("converted");
|
|
assert_eq!(count_comments(&out), count_comments(source), "{out}");
|
|
for comment in [
|
|
"// about the file",
|
|
"// in the header",
|
|
"// above the input",
|
|
"// beside the input",
|
|
"/* above the output */",
|
|
"/* beside the output */",
|
|
"// an ordinary body comment",
|
|
] {
|
|
assert!(out.contains(comment), "{comment} is gone from {out}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_parameter_written_between_the_declarations_is_left_alone() {
|
|
let source =
|
|
"module m (a, b);\n input a;\n parameter W = 8;\n output [W-1:0] b;\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (input a, output [W-1:0] b);\n parameter W = 8;\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn body_declarations_that_are_not_ports_stay_where_they_are() {
|
|
let source = "module m (a);\n input a;\n wire b;\n reg [3:0] c;\nendmodule\n";
|
|
assert_eq!(
|
|
convert(source).expect("converted"),
|
|
"module m (input a);\n wire b;\n reg [3:0] c;\nendmodule\n"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_twenty_port_header_of_mixed_declarations_converts_whole() {
|
|
let mut header = String::from("module wide (\n");
|
|
let mut body = String::new();
|
|
for n in 0..20 {
|
|
let comma = if n == 19 { "" } else { "," };
|
|
header.push_str(&format!(" p{n}{comma}\n"));
|
|
match n % 5 {
|
|
0 => body.push_str(&format!(" input p{n};\n")),
|
|
1 => body.push_str(&format!(" input [7:0] p{n};\n")),
|
|
2 => body.push_str(&format!(" output p{n};\n reg p{n};\n")),
|
|
3 => {
|
|
body.push_str(&format!(" output signed [3:0] p{n};\n wire signed [3:0] p{n};\n"))
|
|
}
|
|
_ => body.push_str(&format!(" inout wire p{n};\n")),
|
|
}
|
|
}
|
|
let source = format!("{header});\n{body}endmodule\n");
|
|
let out = convert(&source).expect("converted");
|
|
assert!(out.contains(" input p0,"), "{out}");
|
|
assert!(out.contains(" input [7:0] p1,"), "{out}");
|
|
assert!(out.contains(" output reg p2,"), "{out}");
|
|
assert!(out.contains(" output wire signed [3:0] p3,"), "{out}");
|
|
assert!(out.contains(" inout wire p4,"), "{out}");
|
|
assert!(out.contains(" inout wire p19\n);"), "{out}");
|
|
assert!(!out.contains(" input p0;"), "the body declarations are gone: {out}");
|
|
assert_eq!(out.matches("p19").count(), 1, "{out}");
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// idempotency
|
|
// ----------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn converting_a_converted_header_refuses_because_it_is_already_ansi() {
|
|
let source = "module m (a, b);\n input a;\n output [7:0] b;\nendmodule\n";
|
|
let once = convert(source).expect("converted");
|
|
let again = convert(&once).expect_err("nothing left to convert");
|
|
assert!(again.contains("already declares its ports ANSI-style"), "{again}");
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// the refusals
|
|
// ----------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn a_position_in_no_module_is_refused() {
|
|
let source = "// nothing here\nmodule m (a);\n input a;\nendmodule\n";
|
|
let said = convert_to_ansi(&files(source), Path::new(TOP), 2).expect_err("no module");
|
|
assert_eq!(said, "there is no module declaration at this position.");
|
|
}
|
|
|
|
#[test]
|
|
fn a_file_outside_the_scope_is_refused() {
|
|
let source = "module m (a);\n input a;\nendmodule\n";
|
|
let said = convert_to_ansi(&files(source), Path::new("/elsewhere.sv"), 8)
|
|
.expect_err("outside the scope");
|
|
assert!(said.contains("is not one of the files lucisv indexes"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn an_ansi_header_is_refused() {
|
|
let said = refused("module m (input a);\nendmodule\n");
|
|
assert!(said.contains("already declares its ports ANSI-style"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_module_with_no_ports_is_refused() {
|
|
assert!(refused("module m ();\nendmodule\n").contains("declares no ports"));
|
|
assert!(refused("module m;\nendmodule\n").contains("declares no ports"));
|
|
}
|
|
|
|
#[test]
|
|
fn an_interface_is_out_of_scope_this_round() {
|
|
let source = "interface it (a);\n input a;\nendinterface\n";
|
|
let at = source.find("it (").expect("name") as u32;
|
|
let said = convert_to_ansi(&files(source), Path::new(TOP), at).expect_err("an interface");
|
|
assert!(said.contains("is an `interface`, not a module"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_port_expression_is_refused() {
|
|
let concat = "module m ({x, y}, b);\n input x, y;\n input b;\nendmodule\n";
|
|
assert!(refused(concat).contains("writes a port expression"), "{}", refused(concat));
|
|
let named = "module m (.a({x, y}), b);\n input x, y;\n input b;\nendmodule\n";
|
|
assert!(refused(named).contains("writes a port expression"), "{}", refused(named));
|
|
}
|
|
|
|
#[test]
|
|
fn a_file_that_does_not_parse_is_refused() {
|
|
let source = "module m (a);\n input a;\n always @(posedge do begin end\nendmodule\n";
|
|
assert!(refused(source).contains("does not parse"), "{}", refused(source));
|
|
}
|
|
|
|
#[test]
|
|
fn a_header_name_with_no_declaration_is_refused() {
|
|
let source = "module m (a, c);\n input a;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("names `c`, but its body declares no direction for it"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_declaration_for_a_name_the_header_does_not_carry_is_refused() {
|
|
let source = "module m (a);\n input a;\n output z;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(
|
|
said.contains("declares a direction for `z`, which its header does not name"),
|
|
"{said}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_port_declared_twice_is_refused() {
|
|
let source = "module m (a);\n input a;\n input a;\nendmodule\n";
|
|
assert!(refused(source).contains("declares a direction for `a` twice"), "{}", refused(source));
|
|
}
|
|
|
|
#[test]
|
|
fn a_variable_declared_twice_is_refused() {
|
|
let source = "module m (b);\n output b;\n reg b;\n reg b;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("declares `b` twice outside its port declaration"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_complete_port_declared_again_is_refused() {
|
|
let source = "module m (b);\n output reg b;\n reg b;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("IEEE 1800 §23.2.2.2 makes that an error"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn packed_ranges_that_disagree_are_refused() {
|
|
let source = "module m (b);\n output [7:0] b;\n reg [3:0] b;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("packed range"), "{said}");
|
|
assert!(said.contains("asks for identical ones"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn unpacked_dimensions_that_disagree_are_refused() {
|
|
let source = "module m (mem);\n output [7:0] mem [0:3];\n reg [7:0] mem [0:7];\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("unpacked dimension"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn signing_that_disagrees_is_refused() {
|
|
let source = "module m (b);\n output signed [7:0] b;\n reg unsigned [7:0] b;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("`signed`") && said.contains("`unsigned`"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_declaration_shared_with_a_local_is_refused() {
|
|
let source = "module m (b);\n output [7:0] b;\n reg [7:0] b, scratch;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("split the declaration first"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn an_initialiser_is_refused() {
|
|
let source = "module m (b);\n output b;\n reg b = 1'b0;\nendmodule\n";
|
|
assert!(refused(source).contains("does not move an initialiser"), "{}", refused(source));
|
|
}
|
|
|
|
#[test]
|
|
fn an_attribute_on_an_absorbed_declaration_is_refused() {
|
|
// `Item.span` covers the `(* ... *)`, so the deletion would take it with
|
|
// the declaration and only the comments are carried; `(* keep *)` changes
|
|
// what a synthesizer does, and where an attribute belongs in an ANSI port
|
|
// list is a design question rather than a merge rule.
|
|
let source = "module m (a);\n (* keep *) input a;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("`(* keep *)` on `m`'s declaration of `a` would be dropped"), "{said}");
|
|
assert!(said.contains("move the attribute onto the port by hand"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn an_attribute_on_the_completing_declaration_is_refused_too() {
|
|
// The other half of the merge is absorbed by the same deletion.
|
|
let source = "module m (b);\n output b;\n (* mark_debug = \"true\" *) reg b;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("would be dropped"), "{said}");
|
|
assert!(said.contains("mark_debug"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_declaration_inside_a_generate_region_is_refused() {
|
|
let source = "module m (b);\n output b;\n generate\n reg b;\n endgenerate\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("inside a generate region"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn compiler_directives_in_the_port_list_are_refused() {
|
|
let source = "module m (\n a,\n`ifdef WIDE\n b,\n`endif\n c\n);\n input a;\n input b;\n input c;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("port list carries compiler directives"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_declaration_inside_a_conditional_arm_is_refused() {
|
|
let source = "module m (a, b);\n input a;\n`ifdef WIDE\n input b;\n`endif\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("conditionally compiled"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_directive_between_the_declarations_is_refused() {
|
|
let source = "module m (a, b);\n input a;\n`include \"more.svh\"\n input b;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("is written among the declarations"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_comment_written_inside_a_declaration_is_refused() {
|
|
let source = "module m (a);\n input /* which */ a;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("inside a declaration the conversion would delete"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_line_comment_that_has_nowhere_to_go_is_refused() {
|
|
let source = "module m (a, b);\n input a; // the clock\n output b;\nendmodule\n";
|
|
let said = refused(source);
|
|
assert!(said.contains("break `m`'s port list across lines first"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_module_declared_twice_in_the_workspace_is_refused() {
|
|
let source = "module m (a);\n input a;\nendmodule\n";
|
|
let files = vec![
|
|
(PathBuf::from(TOP), source.to_string()),
|
|
(PathBuf::from("/rtl/other.sv"), source.to_string()),
|
|
];
|
|
let said = convert_to_ansi(&files, Path::new(TOP), 8).expect_err("declared twice");
|
|
assert!(said.contains("is declared in more than one indexed file"), "{said}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_header_that_names_a_port_twice_is_refused() {
|
|
let source = "module m (a, a);\n input a;\nendmodule\n";
|
|
assert!(refused(source).contains("names `a` twice"), "{}", refused(source));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// the code action
|
|
// ----------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn the_action_is_offered_anywhere_in_a_non_ansi_header() {
|
|
let source = "module m (\n a,\n b\n);\n input a;\n output [7:0] b;\nendmodule\n";
|
|
let files = files(source);
|
|
for needle in ["module m", "m (", "a,", "b\n)"] {
|
|
let at = source.find(needle).expect(needle) as u32;
|
|
let titles: Vec<String> =
|
|
port_actions(&files, Path::new(TOP), at).into_iter().map(|a| a.title).collect();
|
|
assert!(
|
|
titles.iter().any(|t| t == "lucisv: convert ports to ANSI (2 ports)"),
|
|
"at {needle:?}: {titles:?}"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_action_is_not_offered_in_the_body_or_in_an_ansi_module() {
|
|
let source = "module m (\n a\n);\n input a;\n wire w;\n assign w = a;\nendmodule\n";
|
|
let at = source.find("assign").expect("body") as u32;
|
|
assert!(port_actions(&files(source), Path::new(TOP), at).is_empty());
|
|
|
|
let ansi = "module m (input a);\n wire w;\n assign w = a;\nendmodule\n";
|
|
let at = ansi.find("module m").expect("header") as u32;
|
|
let titles: Vec<String> =
|
|
port_actions(&files(ansi), Path::new(TOP), at).into_iter().map(|a| a.title).collect();
|
|
assert!(!titles.iter().any(|t| t.contains("convert ports to ANSI")), "{titles:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn the_action_says_one_port_in_the_singular() {
|
|
let source = "module m (a);\n input a;\nendmodule\n";
|
|
let at = source.find("module m").expect("header") as u32;
|
|
let titles: Vec<String> =
|
|
port_actions(&files(source), Path::new(TOP), at).into_iter().map(|a| a.title).collect();
|
|
assert!(titles.contains(&"lucisv: convert ports to ANSI (1 port)".to_string()), "{titles:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_comment_on_a_declaration_of_two_ports_is_written_once() {
|
|
// The declaration is absorbed by both ports; its comment belongs to the
|
|
// first of them and must not be copied onto the second.
|
|
let source = "module m (\n a,\n b\n);\n input a, b; // both of them\nendmodule\n";
|
|
let out = convert(source).expect("converted");
|
|
assert_eq!(out.matches("// both of them").count(), 1, "{out}");
|
|
assert_eq!(out, "module m (\n input a, // both of them\n input b\n);\nendmodule\n");
|
|
}
|
|
|
|
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|