use std::collections::BTreeMap;
use std::sync::OnceLock;
use serde::Deserialize;
use super::CommentStyle;
use crate::config::CommentStyleRule;
const COMMENT_STYLES_TOML: &str = include_str!("../resources/comment-styles.toml");
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "lowercase")]
enum StyleKind {
Line,
Block,
None,
}
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
struct RawStyleEntry {
kind: StyleKind,
#[serde(default)]
open: String,
#[serde(default)]
close: String,
#[serde(default)]
line: String,
#[serde(default)]
extensions: Vec<String>,
#[serde(default)]
filenames: Vec<String>,
}
impl RawStyleEntry {
fn validate(&self, key: &str) -> Result<(), String> {
if self.kind != StyleKind::Block && !self.line.is_empty() {
return Err(format!("{key}: only kind \"block\" reads line"));
}
match self.kind {
StyleKind::Line if !self.close.is_empty() => {
Err(format!("{key}: kind \"line\" must leave close empty"))
}
StyleKind::Block if self.open.is_empty() || self.close.is_empty() => {
Err(format!("{key}: kind \"block\" needs both open and close"))
}
StyleKind::None if !self.open.is_empty() || !self.close.is_empty() => {
Err(format!("{key}: kind \"none\" must leave delimiters empty"))
}
StyleKind::Line | StyleKind::Block | StyleKind::None => Ok(()),
}
}
}
fn key_to_style(key: &str) -> Option<CommentStyle> {
Some(match key {
"slash" => CommentStyle::Slash,
"hash" => CommentStyle::Hash,
"dash" => CommentStyle::Dash,
"semicolon" => CommentStyle::Semicolon,
"percent" => CommentStyle::Percent,
"asterisk-paren" => CommentStyle::AsteriskParen,
"slash-star" => CommentStyle::SlashStar,
"dot-dot" => CommentStyle::DotDot,
"bang" => CommentStyle::Bang,
"rem" => CommentStyle::Rem,
"html" => CommentStyle::Html,
"uncommentable" => CommentStyle::Uncommentable,
_ => return None,
})
}
fn parse_registry(text: &str) -> Result<Vec<(CommentStyle, RawStyleEntry)>, String> {
let raw: BTreeMap<String, RawStyleEntry> =
toml::from_str(text).map_err(|error| error.to_string())?;
let mut entries = Vec::with_capacity(raw.len());
for (key, mut entry) in raw {
let style =
key_to_style(&key).ok_or_else(|| format!("unknown comment style key: {key}"))?;
entry.validate(&key)?;
for filename in &mut entry.filenames {
*filename = filename.to_lowercase();
}
entries.push((style, entry));
}
Ok(entries)
}
static REGISTRY: OnceLock<Vec<(CommentStyle, RawStyleEntry)>> = OnceLock::new();
fn load_registry(text: &str) -> Vec<(CommentStyle, RawStyleEntry)> {
parse_registry(text).unwrap_or_else(|error| {
panic!("crates/comply/src/resources/comment-styles.toml is invalid: {error}")
})
}
fn registry() -> &'static [(CommentStyle, RawStyleEntry)] {
REGISTRY.get_or_init(|| load_registry(COMMENT_STYLES_TOML))
}
fn style_entry(style: CommentStyle) -> Option<&'static RawStyleEntry> {
registry()
.iter()
.find(|(entry_style, _)| *entry_style == style)
.map(|(_, entry)| entry)
}
pub(super) fn comment_delimiters(style: CommentStyle) -> (&'static str, &'static str) {
style_entry(style).map_or(("", ""), |entry| {
(entry.open.as_str(), entry.close.as_str())
})
}
fn builtin_is_block(style: CommentStyle) -> bool {
style_entry(style).is_some_and(|entry| entry.kind == StyleKind::Block)
}
fn builtin_lead(style: CommentStyle) -> String {
style_entry(style).map_or_else(String::new, |entry| match entry.kind {
StyleKind::Line => format!("{} ", entry.open),
StyleKind::Block | StyleKind::None => entry.line.clone(),
})
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ResolvedStyle<'a> {
style: CommentStyle,
rules: &'a [CommentStyleRule],
}
impl<'a> ResolvedStyle<'a> {
#[must_use]
pub const fn builtin(style: CommentStyle) -> Self {
Self { style, rules: &[] }
}
#[must_use]
pub const fn new(style: CommentStyle, rules: &'a [CommentStyleRule]) -> Self {
Self { style, rules }
}
#[must_use]
pub fn detect(path: &str, rules: &'a [CommentStyleRule]) -> Self {
Self::new(detect_style_with(path, rules), rules)
}
#[must_use]
pub const fn style(self) -> CommentStyle {
self.style
}
#[must_use]
pub const fn rules(self) -> &'a [CommentStyleRule] {
self.rules
}
fn rule(self) -> Option<&'a CommentStyleRule> {
match self.style {
CommentStyle::Custom(index) => self.rules.get(index as usize),
_ => None,
}
}
#[must_use]
pub fn delimiters(self) -> (&'a str, &'a str) {
self.rule().map_or_else(
|| comment_delimiters(self.style),
|rule| (rule.open.as_str(), rule.close.as_str()),
)
}
#[must_use]
pub fn is_block(self) -> bool {
self.rule().map_or_else(
|| builtin_is_block(self.style),
|rule| !rule.close.is_empty(),
)
}
#[must_use]
pub fn lead(self) -> String {
self.rule().map_or_else(
|| builtin_lead(self.style),
|rule| {
if rule.close.is_empty() {
format!("{} ", rule.open)
} else {
rule.line.clone()
}
},
)
}
}
const BUILTIN_STYLES: [CommentStyle; 12] = [
CommentStyle::Slash,
CommentStyle::Hash,
CommentStyle::Dash,
CommentStyle::Semicolon,
CommentStyle::Percent,
CommentStyle::AsteriskParen,
CommentStyle::SlashStar,
CommentStyle::DotDot,
CommentStyle::Bang,
CommentStyle::Rem,
CommentStyle::Html,
CommentStyle::Uncommentable,
];
const fn assert_style_is_listed(style: CommentStyle) {
match style {
CommentStyle::Slash
| CommentStyle::Hash
| CommentStyle::Dash
| CommentStyle::Semicolon
| CommentStyle::Percent
| CommentStyle::AsteriskParen
| CommentStyle::SlashStar
| CommentStyle::DotDot
| CommentStyle::Bang
| CommentStyle::Rem
| CommentStyle::Html
| CommentStyle::Uncommentable
| CommentStyle::Custom(_) => (),
}
}
pub(super) fn block_delimiters<'a>(rules: &'a [CommentStyleRule]) -> Vec<(&'a str, &'a str)> {
BUILTIN_STYLES
.iter()
.copied()
.inspect(|style| assert_style_is_listed(*style))
.map(comment_delimiters)
.map(|(open, close)| -> (&'a str, &'a str) { (open, close) })
.chain(
rules
.iter()
.map(|rule| (rule.open.as_str(), rule.close.as_str())),
)
.filter(|(open, close)| !open.is_empty() && !close.is_empty())
.collect()
}
pub(super) fn configured_prefixes(rules: &[CommentStyleRule]) -> Vec<&str> {
let mut prefixes: Vec<&str> = rules
.iter()
.flat_map(|rule| [rule.open.as_str(), rule.line.as_str()])
.filter(|prefix| !prefix.trim().is_empty())
.collect();
prefixes.sort_unstable_by_key(|prefix| core::cmp::Reverse(prefix.len()));
prefixes.dedup();
prefixes
}
#[must_use]
pub fn detect_style_with(path: &str, rules: &[CommentStyleRule]) -> CommentStyle {
let name = path.rsplit(['/', '\\']).next().unwrap_or(path);
let ext = name.rsplit_once('.').map_or("", |(_, e)| e).to_lowercase();
let matched = rules
.iter()
.position(|r| r.filenames.iter().any(|f| f == name))
.or_else(|| {
(!ext.is_empty())
.then(|| {
rules
.iter()
.position(|r| r.extensions.iter().any(|e| e.to_lowercase() == ext))
})
.flatten()
});
matched
.and_then(|i| u16::try_from(i).ok())
.map_or_else(|| detect_style(path), CommentStyle::Custom)
}
fn basename(path: &str) -> &str {
path.rsplit(['/', '\\']).next().unwrap_or(path)
}
#[must_use]
pub fn detect_style(path: &str) -> CommentStyle {
let name = basename(path).to_lowercase();
if let Some(style) = filename_style(&name) {
return style;
}
let Some((_, ext)) = name.rsplit_once('.') else {
return CommentStyle::Uncommentable;
};
extension_style(ext).unwrap_or(CommentStyle::Uncommentable)
}
fn filename_style(name: &str) -> Option<CommentStyle> {
registry()
.iter()
.find(|(_, entry)| entry.filenames.iter().any(|f| f == name))
.map(|(style, _)| *style)
}
fn extension_style(ext: &str) -> Option<CommentStyle> {
registry()
.iter()
.find(|(_, entry)| entry.extensions.iter().any(|e| e == ext))
.map(|(style, _)| *style)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn style_python_file() {
assert_eq!(detect_style("main.py"), CommentStyle::Hash);
}
#[test]
fn style_html_file() {
assert_eq!(detect_style("index.html"), CommentStyle::Html);
}
#[test]
fn style_binary_file() {
assert_eq!(detect_style("image.png"), CommentStyle::Uncommentable);
}
#[test]
fn an_svg_is_uncommentable_rather_than_html() {
assert_eq!(detect_style("logo.svg"), CommentStyle::Uncommentable);
}
#[test]
fn an_unknown_extension_is_refused_rather_than_guessed() {
for f in ["somefile.xyz", "app.astro", "theme.styl"] {
assert_eq!(detect_style(f), CommentStyle::Uncommentable, "{f}");
}
}
#[test]
fn the_javascript_family_uses_slashes_whatever_the_module_suffix() {
for f in [
"a.mts", "a.cts", "a.tsx", "a.jsx", "a.mjs", "a.cjs", "a.ts", "a.js",
] {
assert_eq!(detect_style(f), CommentStyle::Slash, "{f}");
}
}
#[test]
fn an_extensionless_file_is_matched_by_name() {
for f in [
"Dockerfile",
"Makefile",
"Containerfile",
"Gemfile",
"Rakefile",
] {
assert_eq!(detect_style(f), CommentStyle::Hash, "{f}");
}
assert_eq!(detect_style("Jenkinsfile"), CommentStyle::Slash);
}
#[test]
fn a_dotfile_is_matched_by_name_not_by_a_phantom_extension() {
for f in [
".gitignore",
".gitattributes",
".editorconfig",
".dockerignore",
".yamllint",
".bashrc",
".zshrc",
] {
assert_eq!(detect_style(f), CommentStyle::Hash, "{f}");
}
}
#[test]
fn a_name_match_reads_the_basename_not_the_whole_path() {
assert_eq!(detect_style(".github/CODEOWNERS"), CommentStyle::Hash);
assert_eq!(
detect_style("docs/.vitepress/config.mts"),
CommentStyle::Slash
);
assert_eq!(detect_style("a.b/Makefile"), CommentStyle::Hash);
assert_eq!(detect_style(r"win\path\main.rs"), CommentStyle::Slash);
}
#[test]
fn a_name_with_no_extension_and_no_entry_is_refused() {
for f in ["LICENSE", "README", "CHANGELOG", "AUTHORS"] {
assert_eq!(detect_style(f), CommentStyle::Uncommentable, "{f}");
}
}
#[test]
fn an_exact_name_beats_the_extension_tables() {
assert_eq!(detect_style("CMakeLists.txt"), CommentStyle::Hash);
assert_eq!(detect_style("notes.txt"), CommentStyle::Uncommentable);
}
#[test]
fn the_extension_tables_agree_with_the_reference_tool() {
let cases = [
("a.php", CommentStyle::Slash),
("a.proto", CommentStyle::Slash),
("a.gradle", CommentStyle::Slash),
("a.groovy", CommentStyle::Slash),
("a.kts", CommentStyle::Slash),
("a.tf", CommentStyle::Hash),
("a.hcl", CommentStyle::Hash),
("a.ps1", CommentStyle::Hash),
("a.psm1", CommentStyle::Hash),
("a.ex", CommentStyle::Hash),
("a.exs", CommentStyle::Hash),
("a.nix", CommentStyle::Hash),
("a.nim", CommentStyle::Hash),
("a.jl", CommentStyle::Hash),
("a.cmake", CommentStyle::Hash),
("a.bzl", CommentStyle::Hash),
("a.lua", CommentStyle::Dash),
("a.hs", CommentStyle::Dash),
("a.cabal", CommentStyle::Dash),
("a.rkt", CommentStyle::Semicolon),
("a.scm", CommentStyle::Semicolon),
("a.asm", CommentStyle::Semicolon),
("a.erl", CommentStyle::Percent),
("a.m", CommentStyle::Percent),
("a.vue", CommentStyle::Html),
("a.svelte", CommentStyle::Html),
];
for (f, expected) in cases {
assert_eq!(detect_style(f), expected, "{f}");
}
}
#[test]
fn a_configured_rule_still_claims_an_otherwise_unrecognised_extension() {
let rules = [rule(&["astro"], &[], "//")];
assert_eq!(
detect_style_with("app.astro", &rules),
CommentStyle::Custom(0)
);
assert_eq!(detect_style("app.astro"), CommentStyle::Uncommentable);
}
#[test]
fn style_sql_file() {
assert_eq!(detect_style("schema.sql"), CommentStyle::Dash);
}
#[test]
fn style_clojure_file() {
assert_eq!(detect_style("core.clj"), CommentStyle::Semicolon);
}
#[test]
fn style_latex_file() {
assert_eq!(detect_style("paper.tex"), CommentStyle::Percent);
}
#[test]
fn style_ocaml_file() {
assert_eq!(detect_style("lib.ml"), CommentStyle::AsteriskParen);
}
#[test]
fn style_stylesheets_use_slash_star() {
for f in ["main.css", "theme.scss", "vars.sass", "mixins.less"] {
assert_eq!(detect_style(f), CommentStyle::SlashStar, "{f}");
}
}
#[test]
fn style_restructuredtext_uses_dot_dot() {
assert_eq!(detect_style("guide.rst"), CommentStyle::DotDot);
}
#[test]
fn style_fortran_uses_bang() {
for f in ["a.f90", "a.f95", "a.f03", "a.f08"] {
assert_eq!(detect_style(f), CommentStyle::Bang, "{f}");
}
}
#[test]
fn a_deliberate_superset_of_reuse_gets_bang_and_rem() {
for f in ["a.bat", "a.cmd"] {
assert_eq!(detect_style(f), CommentStyle::Rem, "{f}");
}
}
fn block_rule(open: &str, line: &str, close: &str) -> CommentStyleRule {
CommentStyleRule {
extensions: vec!["vue".to_string()],
filenames: vec![],
open: open.to_string(),
line: line.to_string(),
close: close.to_string(),
}
}
#[test]
fn a_configured_style_reads_its_delimiters_out_of_the_rules() {
let rules = [block_rule("<%--", " ", "--%>")];
let resolved = ResolvedStyle::new(CommentStyle::Custom(0), &rules);
assert_eq!(resolved.delimiters(), ("<%--", "--%>"));
assert!(resolved.is_block());
assert_eq!(resolved.lead(), " ");
}
#[test]
fn a_configured_line_style_leads_with_its_opener() {
let rules = [block_rule("@@", "", "")];
let resolved = ResolvedStyle::new(CommentStyle::Custom(0), &rules);
assert_eq!(resolved.delimiters(), ("@@", ""));
assert!(!resolved.is_block());
assert_eq!(resolved.lead(), "@@ ");
}
#[test]
fn an_index_past_the_end_yields_nothing_rather_than_a_guess() {
assert_eq!(
ResolvedStyle::new(CommentStyle::Custom(7), &[]).delimiters(),
("", "")
);
}
#[test]
fn equality_compares_the_rules_a_custom_index_points_into() {
let html = [block_rule("<!--", "", "-->")];
let hash = [block_rule("#", "", "")];
assert_eq!(
ResolvedStyle::new(CommentStyle::Custom(0), &html),
ResolvedStyle::new(CommentStyle::Custom(0), &html)
);
assert_ne!(
ResolvedStyle::new(CommentStyle::Custom(0), &html),
ResolvedStyle::new(CommentStyle::Custom(0), &hash)
);
}
#[test]
fn the_debug_form_names_the_syntax_an_index_alone_cannot() {
let rules = [block_rule("<%--", " ", "--%>")];
let shown = format!("{:?}", ResolvedStyle::new(CommentStyle::Custom(0), &rules));
assert!(shown.contains("<%--"), "got: {shown}");
}
#[test]
fn builtins_answer_the_same_with_rules_as_without() {
let rules = [block_rule("<%--", " ", "--%>")];
for style in BUILTIN_STYLES {
assert_eq!(
ResolvedStyle::new(style, &rules).delimiters(),
comment_delimiters(style),
"{style:?} must ignore the rules"
);
assert_eq!(
ResolvedStyle::new(style, &rules).lead(),
ResolvedStyle::builtin(style).lead(),
"{style:?} lead must not depend on the rules"
);
}
}
#[test]
fn a_configured_block_style_is_recognised_as_one() {
let rules = [block_rule("<%--", " ", "--%>")];
assert!(
block_delimiters(&rules).contains(&("<%--", "--%>")),
"configured block styles must join the built-ins"
);
}
fn rule(exts: &[&str], files: &[&str], open: &str) -> CommentStyleRule {
CommentStyleRule {
extensions: exts.iter().map(|s| (*s).to_string()).collect(),
filenames: files.iter().map(|s| (*s).to_string()).collect(),
open: open.to_string(),
line: String::new(),
close: String::new(),
}
}
#[test]
fn a_configured_extension_wins_over_the_builtin() {
let rules = [rule(&["md"], &[], "//")];
assert_eq!(
detect_style_with("notes.md", &rules),
CommentStyle::Custom(0)
);
assert_eq!(
detect_style("notes.md"),
CommentStyle::Html,
"builtin intact"
);
}
#[test]
fn anything_unclaimed_keeps_its_builtin() {
let rules = [rule(&["vue"], &[], "<!--")];
assert_eq!(detect_style_with("main.rs", &rules), CommentStyle::Slash);
}
#[test]
fn an_exact_filename_beats_an_extension_rule() {
let rules = [rule(&["txt"], &[], "#"), rule(&[], &["NOTICE.txt"], "//")];
assert_eq!(
detect_style_with("NOTICE.txt", &rules),
CommentStyle::Custom(1)
);
assert_eq!(
detect_style_with("other.txt", &rules),
CommentStyle::Custom(0)
);
}
#[test]
fn matching_is_case_insensitive_on_the_extension() {
let rules = [rule(&["VUE"], &[], "<!--")];
assert_eq!(
detect_style_with("App.vue", &rules),
CommentStyle::Custom(0)
);
}
#[test]
fn no_rules_is_exactly_the_builtin_behaviour() {
for f in ["a.rs", "b.py", "c.md", "d.png", "unknown.xyz"] {
assert_eq!(detect_style_with(f, &[]), detect_style(f), "{f}");
}
}
#[test]
fn block_delimiters_are_derived_not_restated() {
let mut pairs = block_delimiters(&[]);
pairs.sort_unstable();
assert_eq!(pairs, vec![("(*", "*)"), ("/*", "*/"), ("<!--", "-->")]);
}
#[test]
fn only_bracketing_styles_appear() {
for (open, close) in block_delimiters(&[]) {
assert!(!open.is_empty() && !close.is_empty(), "{open:?}/{close:?}");
}
}
#[test]
fn every_builtin_style_has_a_resource_entry() {
for style in BUILTIN_STYLES {
assert!(
registry().iter().any(|(s, _)| *s == style),
"{style:?} is missing from comment-styles.toml"
);
}
}
#[test]
fn no_name_is_claimed_by_two_tables() {
let mut extensions: BTreeMap<&str, CommentStyle> = BTreeMap::new();
let mut filenames: BTreeMap<&str, CommentStyle> = BTreeMap::new();
for (style, entry) in registry() {
for ext in &entry.extensions {
let prior = extensions.insert(ext.as_str(), *style);
assert!(prior.is_none(), "{ext}: {prior:?} and {style:?}");
}
for name in &entry.filenames {
let prior = filenames.insert(name.as_str(), *style);
assert!(prior.is_none(), "{name}: {prior:?} and {style:?}");
}
}
}
#[test]
fn no_extension_entry_carries_a_dot() {
assert_eq!(detect_style("archive.tar.gz"), CommentStyle::Uncommentable);
for (style, entry) in registry() {
for ext in &entry.extensions {
assert!(!ext.contains('.'), "{style:?} lists an unreachable {ext}");
}
}
}
#[test]
fn every_resource_key_resolves_to_a_known_style() {
assert_eq!(registry().len(), BUILTIN_STYLES.len());
}
#[test]
fn the_embedded_file_parses_and_validates() {
assert!(parse_registry(COMMENT_STYLES_TOML).is_ok());
}
#[test]
fn an_unknown_key_is_rejected() {
let bad = "[not-a-style]\nkind = \"line\"\nopen = \"@\"\n";
assert!(parse_registry(bad).is_err());
}
#[test]
fn a_line_style_with_a_close_is_rejected() {
let bad = "[slash]\nkind = \"line\"\nopen = \"//\"\nclose = \"x\"\n";
assert!(parse_registry(bad).is_err());
}
#[test]
fn a_block_style_missing_open_is_rejected() {
let bad = "[html]\nkind = \"block\"\nclose = \"-->\"\n";
assert!(parse_registry(bad).is_err());
}
#[test]
fn a_block_style_missing_close_is_rejected() {
let bad = "[html]\nkind = \"block\"\nopen = \"<!--\"\n";
assert!(parse_registry(bad).is_err());
}
#[test]
fn a_none_style_with_delimiters_is_rejected() {
let bad = "[uncommentable]\nkind = \"none\"\nopen = \"x\"\n";
assert!(parse_registry(bad).is_err());
}
#[test]
fn a_table_missing_kind_is_rejected() {
let bad = "[slash]\nopen = \"//\"\n";
assert!(parse_registry(bad).is_err());
}
#[test]
fn a_block_style_declares_its_inner_prefix_in_the_file() {
let text = "[slash-star]\nkind = \"block\"\nopen = \"/*\"\nclose = \"*/\"\nline = \"|\"\n";
let parsed = parse_registry(text).expect("a block style may declare its lead");
assert_eq!(parsed[0].1.line, "|");
}
#[test]
fn a_line_prefix_outside_a_block_style_is_rejected() {
for bad in [
"[slash]\nkind = \"line\"\nopen = \"//\"\nline = \"|\"\n",
"[uncommentable]\nkind = \"none\"\nline = \"|\"\n",
] {
assert!(parse_registry(bad).is_err(), "{bad}");
}
}
#[test]
fn a_mistyped_key_is_rejected_rather_than_emptying_the_table() {
let bad = "[slash]\nkind = \"line\"\nopen = \"//\"\nextenions = [\"rs\"]\n";
assert!(parse_registry(bad).is_err());
}
#[test]
fn malformed_toml_syntax_is_rejected() {
let bad = "not even toml {{{";
assert!(parse_registry(bad).is_err());
}
#[test]
#[should_panic(expected = "comment-styles.toml is invalid")]
fn a_malformed_registry_panics_rather_than_silently_degrading() {
load_registry("not even toml {{{");
}
#[test]
fn every_style_has_delimiters() {
assert_eq!(comment_delimiters(CommentStyle::Slash), ("//", ""));
assert_eq!(comment_delimiters(CommentStyle::Hash), ("#", ""));
assert_eq!(comment_delimiters(CommentStyle::Dash), ("--", ""));
assert_eq!(comment_delimiters(CommentStyle::Semicolon), (";;;", ""));
assert_eq!(comment_delimiters(CommentStyle::Percent), ("%", ""));
assert_eq!(
comment_delimiters(CommentStyle::AsteriskParen),
("(*", "*)")
);
assert_eq!(comment_delimiters(CommentStyle::SlashStar), ("/*", "*/"));
assert_eq!(comment_delimiters(CommentStyle::DotDot), ("..", ""));
assert_eq!(comment_delimiters(CommentStyle::Bang), ("!", ""));
assert_eq!(comment_delimiters(CommentStyle::Rem), ("REM", ""));
assert_eq!(comment_delimiters(CommentStyle::Html), ("<!--", "-->"));
assert_eq!(
comment_delimiters(CommentStyle::Uncommentable),
("", ""),
"an uncommentable file has no delimiters to wrap a header in"
);
}
#[test]
fn bang_and_rem_render_bytes_matching_the_reference_tool() {
let cases = [
(
CommentStyle::Bang,
"! SPDX-FileCopyrightText: 2026 X\n!\n! SPDX-License-Identifier: MIT\n",
),
(
CommentStyle::Rem,
"REM SPDX-FileCopyrightText: 2026 X\nREM\nREM SPDX-License-Identifier: MIT\n",
),
];
for (style, expected) in cases {
let result = crate::header::generate("2026 X", "MIT", style).unwrap();
assert_eq!(result, expected, "{style:?}");
}
}
}