diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-22 22:53:09 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-22 22:53:22 +0900 |
| commit | 6f3802fd9f39c4e5847d130b4417b5cdfb66972d (patch) | |
| tree | 166cca2cf0645d280bfa376a513a049c70241dea /crates/mozart-console-macros/tests | |
| parent | 1d33728151b282949e7e14646e722d7775de4453 (diff) | |
| download | php-mozart-6f3802fd9f39c4e5847d130b4417b5cdfb66972d.tar.gz php-mozart-6f3802fd9f39c4e5847d130b4417b5cdfb66972d.tar.zst php-mozart-6f3802fd9f39c4e5847d130b4417b5cdfb66972d.zip | |
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!("<info>text {name}</info>")`. 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 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart-console-macros/tests')
| -rw-r--r-- | crates/mozart-console-macros/tests/integration.rs | 94 |
1 files changed, 94 insertions, 0 deletions
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!("<info>done</info>"); + assert!(result.contains("done"), "expected 'done' in: {result}"); +} + +#[test] +fn single_tag_with_format_arg() { + let name = "foo"; + let result = console_format!("<info>Removing {name}</info>"); + 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!("<info>{}</info> : <comment>{}</comment>", 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!("<comment>note</comment>"); + assert!(result.contains("note")); +} + +#[test] +fn error_tag() { + let result = console_format!("<error>fail</error>"); + assert!(result.contains("fail")); +} + +#[test] +fn question_tag() { + let result = console_format!("<question>ask</question>"); + assert!(result.contains("ask")); +} + +#[test] +fn highlight_tag() { + let result = console_format!("<highlight>important</highlight>"); + assert!(result.contains("important")); +} + +#[test] +fn warning_tag() { + let result = console_format!("<warning>caution</warning>"); + assert!(result.contains("caution")); +} + +#[test] +fn escaped_braces() { + let result = console_format!("<info>{{literal}}</info>"); + assert!( + result.contains("{literal}"), + "expected '{{literal}}' in: {result}" + ); +} + +#[test] +fn tag_with_plain_before_after() { + let result = console_format!("before <info>middle</info> after"); + assert!(result.contains("before ")); + assert!(result.contains("middle")); + assert!(result.contains(" after")); +} + +#[test] +fn unknown_tag_is_literal() { + let result = console_format!("<bold>text</bold>"); + assert_eq!(result, "<bold>text</bold>"); +} |
