From 6f3802fd9f39c4e5847d130b4417b5cdfb66972d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 22 Feb 2026 22:53:09 +0900 Subject: refactor(console): add console_format! proc macro and migrate all commands Introduce a Symfony Console-style tag macro that replaces verbose patterns like `console::info(&format!("text {name}"))` with `console_format!("text {name}")`. Supports all 6 tag types (info, comment, error, question, highlight, warning) with format argument distribution across multiple tagged segments. Co-Authored-By: Claude Opus 4.6 --- crates/mozart-console-macros/tests/integration.rs | 94 +++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 crates/mozart-console-macros/tests/integration.rs (limited to 'crates/mozart-console-macros/tests') diff --git a/crates/mozart-console-macros/tests/integration.rs b/crates/mozart-console-macros/tests/integration.rs new file mode 100644 index 0000000..36a4e03 --- /dev/null +++ b/crates/mozart-console-macros/tests/integration.rs @@ -0,0 +1,94 @@ +use mozart_core::console_format; + +#[test] +fn plain_text_no_tags() { + let result = console_format!("hello world"); + assert_eq!(result, "hello world"); +} + +#[test] +fn plain_text_with_format_args() { + let x = 42; + let result = console_format!("value is {}", x); + assert_eq!(result, "value is 42"); +} + +#[test] +fn single_info_tag() { + // The output should contain the text (colored), verify it contains the raw text + let result = console_format!("done"); + assert!(result.contains("done"), "expected 'done' in: {result}"); +} + +#[test] +fn single_tag_with_format_arg() { + let name = "foo"; + let result = console_format!("Removing {name}"); + assert!( + result.contains("Removing foo"), + "expected 'Removing foo' in: {result}" + ); +} + +#[test] +fn multiple_tags() { + let label = "pkg"; + let version = "1.0"; + let result = console_format!("{} : {}", label, version); + assert!(result.contains("pkg"), "expected 'pkg' in: {result}"); + assert!(result.contains("1.0"), "expected '1.0' in: {result}"); + assert!(result.contains(" : "), "expected ' : ' in: {result}"); +} + +#[test] +fn comment_tag() { + let result = console_format!("note"); + assert!(result.contains("note")); +} + +#[test] +fn error_tag() { + let result = console_format!("fail"); + assert!(result.contains("fail")); +} + +#[test] +fn question_tag() { + let result = console_format!("ask"); + assert!(result.contains("ask")); +} + +#[test] +fn highlight_tag() { + let result = console_format!("important"); + assert!(result.contains("important")); +} + +#[test] +fn warning_tag() { + let result = console_format!("caution"); + assert!(result.contains("caution")); +} + +#[test] +fn escaped_braces() { + let result = console_format!("{{literal}}"); + assert!( + result.contains("{literal}"), + "expected '{{literal}}' in: {result}" + ); +} + +#[test] +fn tag_with_plain_before_after() { + let result = console_format!("before middle after"); + assert!(result.contains("before ")); + assert!(result.contains("middle")); + assert!(result.contains(" after")); +} + +#[test] +fn unknown_tag_is_literal() { + let result = console_format!("text"); + assert_eq!(result, "text"); +} -- cgit v1.3.1