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]>
207 lines
6.0 KiB
Rust
207 lines
6.0 KiB
Rust
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
|
|
|
//! The organize-imports offer promises exactly what the refactoring delivers.
|
|
//!
|
|
//! Take 5 §P1c (`docs/features/perf5-p1/README.md`) added
|
|
//! [`vlog_refactor::organize_offer`], which answers the two counts a code
|
|
//! action's title carries without rendering a verified edit. This file is the
|
|
//! proof that its answer — the counts *and* the refusal sentence — is
|
|
//! [`vlog_refactor::organize_counts`]'s answer at **every byte offset** of
|
|
//! every fixture, and that the only thing it does not reproduce is
|
|
//! `check::verify_splice`, which no fixture here reaches.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use vlog_parser::{parse_source_tolerant, tokenize};
|
|
use vlog_refactor::{organize_counts, organize_offer, organize_offer_in, organize_title};
|
|
|
|
/// A module importing two packages, one of them unused and written first, so
|
|
/// there is both a removal and a sort to promise.
|
|
const USER: &str = "\
|
|
module user (
|
|
input logic clk_i
|
|
);
|
|
import b_pkg::*;
|
|
import a_pkg::*;
|
|
logic q;
|
|
assign q = A_ONE;
|
|
endmodule
|
|
";
|
|
|
|
/// Imports already sorted with every one used: the refusal that is not an
|
|
/// error, and the one a lightbulb must not appear for.
|
|
const TIDY: &str = "\
|
|
module tidy;
|
|
import a_pkg::*;
|
|
logic q;
|
|
assign q = A_ONE;
|
|
endmodule
|
|
";
|
|
|
|
/// A duplicate import and a commented one, which is the shape that produces a
|
|
/// warning instead of a deletion.
|
|
const COMMENTED: &str = "\
|
|
module commented;
|
|
import a_pkg::*;
|
|
// why this one is here
|
|
import b_pkg::*;
|
|
import a_pkg::*;
|
|
logic q;
|
|
assign q = A_ONE;
|
|
endmodule
|
|
";
|
|
|
|
/// An import of a package nothing in scope declares — the conservative
|
|
/// silence, which the offer must keep.
|
|
const UNKNOWN: &str = "\
|
|
module unknown;
|
|
import nowhere_pkg::*;
|
|
import a_pkg::*;
|
|
logic q;
|
|
assign q = A_ONE;
|
|
endmodule
|
|
";
|
|
|
|
/// A compilation-unit import run above a module, and a package with its own.
|
|
const FILE_SCOPE: &str = "\
|
|
import b_pkg::*;
|
|
import a_pkg::*;
|
|
package inner_pkg;
|
|
import a_pkg::*;
|
|
localparam int K = A_ONE;
|
|
endpackage
|
|
module uses;
|
|
logic q;
|
|
assign q = A_ONE;
|
|
endmodule
|
|
";
|
|
|
|
/// A buffer that does not parse: refused by both, with the same sentence.
|
|
const BROKEN: &str = "\
|
|
module broken;
|
|
import a_pkg::*;
|
|
logic ;;; w
|
|
endmodule
|
|
";
|
|
|
|
const A_PKG: &str = "\
|
|
package a_pkg;
|
|
localparam int A_ONE = 1;
|
|
endpackage
|
|
";
|
|
|
|
const B_PKG: &str = "\
|
|
package b_pkg;
|
|
localparam int B_ONE = 2;
|
|
endpackage
|
|
";
|
|
|
|
fn file(name: &str) -> PathBuf {
|
|
PathBuf::from("/rtl").join(name)
|
|
}
|
|
|
|
fn workspace(name: &str, text: &str) -> Vec<(PathBuf, String)> {
|
|
vec![
|
|
(file(name), text.to_string()),
|
|
(file("a_pkg.sv"), A_PKG.to_string()),
|
|
(file("b_pkg.sv"), B_PKG.to_string()),
|
|
]
|
|
}
|
|
|
|
fn crlf(text: &str) -> String {
|
|
text.replace('\n', "\r\n")
|
|
}
|
|
|
|
/// The counts the refactoring promises, without its edit.
|
|
fn eager(files: &[(PathBuf, String)], path: &Path, offset: u32) -> Result<(usize, usize), String> {
|
|
organize_counts(files, path, offset).map(|(_, removed, sorted)| (removed, sorted))
|
|
}
|
|
|
|
fn agree_everywhere(name: &str, text: &str) {
|
|
let files = workspace(name, text);
|
|
let path = file(name);
|
|
for offset in 0..=text.len() as u32 {
|
|
assert_eq!(
|
|
eager(&files, &path, offset),
|
|
organize_offer(&files, &path, offset),
|
|
"at offset {offset} of {name}"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_offer_promises_what_the_refactoring_delivers_at_every_offset() {
|
|
agree_everywhere("user.sv", USER);
|
|
}
|
|
|
|
#[test]
|
|
fn an_already_tidy_run_is_refused_by_both_with_the_same_sentence() {
|
|
agree_everywhere("tidy.sv", TIDY);
|
|
let files = workspace("tidy.sv", TIDY);
|
|
let at = TIDY.find("import a_pkg").expect("the import") as u32;
|
|
assert_eq!(
|
|
organize_offer(&files, &file("tidy.sv"), at),
|
|
Err("these imports are already sorted, and every one of them is used.".to_string())
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_commented_import_counts_the_same_in_both_answers() {
|
|
agree_everywhere("commented.sv", COMMENTED);
|
|
}
|
|
|
|
#[test]
|
|
fn an_unknown_package_silences_both_answers() {
|
|
agree_everywhere("unknown.sv", UNKNOWN);
|
|
let files = workspace("unknown.sv", UNKNOWN);
|
|
let at = UNKNOWN.find("import nowhere_pkg").expect("the import") as u32;
|
|
assert!(organize_offer(&files, &file("unknown.sv"), at).is_err(), "the offer stays silent");
|
|
}
|
|
|
|
#[test]
|
|
fn a_file_scope_run_and_a_package_run_agree_at_every_offset() {
|
|
agree_everywhere("file_scope.sv", FILE_SCOPE);
|
|
}
|
|
|
|
#[test]
|
|
fn a_buffer_that_does_not_parse_is_refused_by_both() {
|
|
agree_everywhere("broken.sv", BROKEN);
|
|
}
|
|
|
|
#[test]
|
|
fn the_offer_agrees_over_crlf_line_endings() {
|
|
agree_everywhere("user.sv", &crlf(USER));
|
|
agree_everywhere("commented.sv", &crlf(COMMENTED));
|
|
}
|
|
|
|
#[test]
|
|
fn the_parsed_form_answers_what_the_text_form_answers_at_every_offset() {
|
|
for (name, text) in [("user.sv", USER), ("commented.sv", COMMENTED), ("broken.sv", BROKEN)] {
|
|
let files = workspace(name, text);
|
|
let path = file(name);
|
|
let (tree, diagnostics) = parse_source_tolerant(text);
|
|
let semantics = vlog_semantic::analyze(&tree, text);
|
|
let tokens = tokenize(text).expect("the fixture lexes");
|
|
for offset in 0..=text.len() as u32 {
|
|
assert_eq!(
|
|
organize_offer(&files, &path, offset),
|
|
organize_offer_in(&files, &path, &tree, &diagnostics, &semantics, &tokens, offset),
|
|
"at offset {offset} of {name}"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The fixtures really do reach an offer — a parity suite over an action that
|
|
/// is never offered proves nothing.
|
|
#[test]
|
|
fn the_fixture_really_is_offered_the_action_with_the_title_it_promises() {
|
|
let files = workspace("user.sv", USER);
|
|
let at = USER.find("import b_pkg").expect("the import") as u32;
|
|
let (removed, sorted) = organize_offer(&files, &file("user.sv"), at).expect("an offer");
|
|
assert_eq!((removed, sorted), (1, 1), "one unused import goes and one is written back");
|
|
assert_eq!(organize_title(removed, sorted), "lucisv: organize imports (removes 1, sorts 1)");
|
|
}
|
|
|
|
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|