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]>
245 lines
6.4 KiB
Rust
245 lines
6.4 KiB
Rust
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
|
|
|
//! The `[format]` config keys — the layout choices that are off unless a
|
|
//! project turns them on (TODO §54.3).
|
|
//!
|
|
//! Every one of them changes the output of files that already format cleanly,
|
|
//! so each test asserts both directions: the shipped default leaves the file
|
|
//! exactly as it was, and the key on produces the asked-for layout and is
|
|
//! still idempotent.
|
|
|
|
use vlog_formatter::{format_source, Config};
|
|
|
|
/// A class body written the way UVM's own examples write one.
|
|
const UVM_CLASS: &str = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_begin(c)
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
`uvm_field_string(b, UVM_DEFAULT)
|
|
`uvm_object_utils_end
|
|
function new(string name = \"c\");
|
|
super.new(name);
|
|
endfunction
|
|
endclass
|
|
";
|
|
|
|
/// The same body with the field macros indented one level.
|
|
const UVM_CLASS_INDENTED: &str = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_begin(c)
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
`uvm_field_string(b, UVM_DEFAULT)
|
|
`uvm_object_utils_end
|
|
function new(string name = \"c\");
|
|
super.new(name);
|
|
endfunction
|
|
endclass
|
|
";
|
|
|
|
fn on() -> Config {
|
|
Config { uvm_utils_indent: true, ..Config::default() }
|
|
}
|
|
|
|
fn format(src: &str, config: &Config) -> String {
|
|
format_source(src, config).expect("formats")
|
|
}
|
|
|
|
#[test]
|
|
fn the_shipped_default_leaves_uvm_utils_macros_where_they_stand() {
|
|
assert_eq!(format(UVM_CLASS, &Config::default()), UVM_CLASS);
|
|
// And it un-indents a file that was written indented, which is exactly
|
|
// why the key exists: without it there is no way to keep that shape.
|
|
assert_eq!(format(UVM_CLASS_INDENTED, &Config::default()), UVM_CLASS);
|
|
}
|
|
|
|
#[test]
|
|
fn uvm_utils_indent_indents_the_run_between_begin_and_end() {
|
|
assert_eq!(format(UVM_CLASS, &on()), UVM_CLASS_INDENTED);
|
|
assert_eq!(format(UVM_CLASS_INDENTED, &on()), UVM_CLASS_INDENTED);
|
|
}
|
|
|
|
#[test]
|
|
fn uvm_utils_indent_is_idempotent() {
|
|
let once = format(UVM_CLASS, &on());
|
|
assert_eq!(format(&once, &on()), once);
|
|
}
|
|
|
|
#[test]
|
|
fn the_component_spelling_opens_the_same_level() {
|
|
let src = "\
|
|
class c extends uvm_component;
|
|
`uvm_component_utils_begin(c)
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
`uvm_component_utils_end
|
|
endclass
|
|
";
|
|
let want = "\
|
|
class c extends uvm_component;
|
|
`uvm_component_utils_begin(c)
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
`uvm_component_utils_end
|
|
endclass
|
|
";
|
|
assert_eq!(format(src, &on()), want);
|
|
}
|
|
|
|
#[test]
|
|
fn only_those_four_macro_names_open_a_level() {
|
|
// A macro pair that merely *looks* like the idiom is not it: the rule is
|
|
// four names, not a heuristic about `_begin`/`_end`.
|
|
let src = "\
|
|
class c;
|
|
`my_utils_begin(c)
|
|
`my_field(a)
|
|
`my_utils_end
|
|
endclass
|
|
";
|
|
assert_eq!(format(src, &on()), src);
|
|
}
|
|
|
|
#[test]
|
|
fn comments_inside_the_run_are_indented_with_it_and_never_dropped() {
|
|
let src = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_begin(c)
|
|
// why this field matters
|
|
`uvm_field_int(a, UVM_DEFAULT) // trailing
|
|
`uvm_object_utils_end
|
|
endclass
|
|
";
|
|
let want = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_begin(c)
|
|
// why this field matters
|
|
`uvm_field_int(a, UVM_DEFAULT) // trailing
|
|
`uvm_object_utils_end
|
|
endclass
|
|
";
|
|
assert_eq!(format(src, &on()), want);
|
|
}
|
|
|
|
#[test]
|
|
fn a_begin_with_no_end_still_prints_everything_it_opened() {
|
|
// lucisv reproduces the file it was given, unbalanced macros included.
|
|
let src = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_begin(c)
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
endclass
|
|
";
|
|
let want = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_begin(c)
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
endclass
|
|
";
|
|
assert_eq!(format(src, &on()), want);
|
|
assert_eq!(format(&format(src, &on()), &on()), want);
|
|
}
|
|
|
|
/// The other half of coverage gap L10: an enum body one-lined when it is
|
|
/// short. **This already is the default** — measured 2026-09-06, over every
|
|
/// shape the gap names — so no config key was added for it. The test pins the
|
|
/// behaviour so nothing takes it away.
|
|
#[test]
|
|
fn a_short_enum_body_is_already_one_lined_by_default() {
|
|
let broken = "\
|
|
package p;
|
|
typedef enum {
|
|
A,
|
|
B,
|
|
C
|
|
} e_t;
|
|
typedef enum logic [1:0] {
|
|
X = 0,
|
|
Y,
|
|
Z
|
|
} s_e;
|
|
enum {
|
|
IDLE,
|
|
BUSY
|
|
} state;
|
|
endpackage
|
|
";
|
|
let want = "\
|
|
package p;
|
|
typedef enum {A, B, C} e_t;
|
|
typedef enum logic [1:0] {X = 0, Y, Z} s_e;
|
|
enum {IDLE, BUSY} state;
|
|
endpackage
|
|
";
|
|
assert_eq!(format(broken, &Config::default()), want);
|
|
}
|
|
|
|
/// And a body with a comment in it still breaks, which is the condition the
|
|
/// gap named: one-lining it would put a `//` in front of the `}`.
|
|
#[test]
|
|
fn an_enum_body_with_a_comment_still_breaks_one_member_per_line() {
|
|
let src = "\
|
|
package p;
|
|
typedef enum {
|
|
A, // first
|
|
B
|
|
} e_t;
|
|
endpackage
|
|
";
|
|
assert_eq!(format(src, &Config::default()), src);
|
|
}
|
|
|
|
#[test]
|
|
fn a_nested_begin_opens_a_level_of_its_own_and_its_end_closes_that_one() {
|
|
// Real UVM code never nests these macros, but the rule tracks a stack all
|
|
// the same: the first `_end` closes the `_begin` it matches, not the run.
|
|
let src = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_begin(c)
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
`uvm_object_utils_begin(d)
|
|
`uvm_field_int(b, UVM_DEFAULT)
|
|
`uvm_object_utils_end
|
|
`uvm_field_int(e, UVM_DEFAULT)
|
|
`uvm_object_utils_end
|
|
`uvm_field_int(f, UVM_DEFAULT)
|
|
endclass
|
|
";
|
|
let want = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_begin(c)
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
`uvm_object_utils_begin(d)
|
|
`uvm_field_int(b, UVM_DEFAULT)
|
|
`uvm_object_utils_end
|
|
`uvm_field_int(e, UVM_DEFAULT)
|
|
`uvm_object_utils_end
|
|
`uvm_field_int(f, UVM_DEFAULT)
|
|
endclass
|
|
";
|
|
assert_eq!(format(src, &on()), want);
|
|
assert_eq!(format(want, &on()), want, "idempotent");
|
|
}
|
|
|
|
#[test]
|
|
fn an_end_with_no_begin_open_changes_no_indentation() {
|
|
// Nothing to close, so nothing moves — the file comes back as written.
|
|
let src = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_end
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
endclass
|
|
";
|
|
assert_eq!(format(src, &on()), src);
|
|
// And an unmatched `_end` after a closed pair closes nothing either.
|
|
let after = "\
|
|
class c extends uvm_object;
|
|
`uvm_object_utils_begin(c)
|
|
`uvm_field_int(a, UVM_DEFAULT)
|
|
`uvm_object_utils_end
|
|
`uvm_object_utils_end
|
|
`uvm_field_int(b, UVM_DEFAULT)
|
|
endclass
|
|
";
|
|
assert_eq!(format(after, &on()), after);
|
|
}
|
|
|
|
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|