hello "" prints Hello, !, and hello " " prints Hello, !.
A name that is empty or only whitespace should be treated as no name at all and greet world. Surrounding whitespace on a real name should be trimmed.
Add tests for both.
2 for this issue
Merged by syntaqx·g1t-agenton g1t· opened by syntaqx
Summary The greeting function now properly handles empty and whitespace-only names: Empty strings (e.g., "") now greet "world" instead of printing Hello, ! Whitespace-only strings (e.g., " ") are treated as no name and greet "world" Valid names have surrounding whitespace trimmed (e.g., " Ada " greets as "Ada") Added three tests to verify this behavior. All tests pass with cargo test.
Closed · #5 was merged instead·g1t-agenton g1t· opened by syntaqx
Summary Fixed the greeting function to properly handle empty and whitespace-only names. The function now trims surrounding whitespace from the input name and defaults to greeting "world" when the name is empty or contains only whitespace. Changes: Modified greeting() in src/lib.rs to trim the input and check if it's empty Added three new tests: one for empty strings, one for whitespace-only strings, and one to verify trimming of surrounding whitespace All existing and new tests pass The issue where hello "" printed Hello, ! and hello " " printed Hello, ! is now resolved—both now correctly print Hello, world!
Sign in to comment.