Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions pkgs/id/src/world_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,18 @@ pub fn parse_line(line: &str) -> Option<WorldLine> {
prefix: (!prefix.is_empty()).then(|| prefix.to_owned()),
});
}
if line == "/document" {
return Some(WorldLine::Message("usage: /document <name>".to_owned()));
}
if let Some(rest) = line.strip_prefix("/document ") {
let name = rest.trim();
if !name.is_empty() && name == rest {
return Some(WorldLine::Document(name.to_owned()));
}
return Some(WorldLine::Message("usage: /document <name>".to_owned()));
}
if let Some(rest) = line.strip_prefix("/logs") {
let rest = rest.trim();
if line == "/logs" || line.starts_with("/logs ") {
let rest = line.strip_prefix("/logs").unwrap_or_default().trim();
if rest.is_empty() {
return Some(WorldLine::Logs { seconds: None });
}
Expand All @@ -90,6 +93,9 @@ pub fn parse_line(line: &str) -> Option<WorldLine> {
}
return Some(WorldLine::Message("usage: /logs [seconds]".to_owned()));
}
if line == "/input" {
return Some(WorldLine::Message("usage: /input <hex>".to_owned()));
}
if let Some(hex) = line.strip_prefix("/input ") {
if !hex.is_empty() && hex.len() % 2 == 0 && hex.bytes().all(|b| b.is_ascii_hexdigit()) {
return Some(WorldLine::Input(hex.to_ascii_lowercase()));
Expand Down Expand Up @@ -158,6 +164,34 @@ mod tests {
);
}

#[test]
fn glued_and_bare_verbs_do_not_parse_as_commands() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prefix the new test name with test_

The new test omits the test_ prefix explicitly required by the Naming rule in pkgs/id/AGENTS.md. Rename it to test_glued_and_bare_verbs_do_not_parse_as_commands to comply with the scoped repository convention.

AGENTS.md reference: pkgs/id/AGENTS.md:L140-L140

Useful? React with 👍 / 👎.

// #1507: every verb needs its boundary — exact, or the verb, a space,
// and its argument. A glued argument is not the command.
assert_eq!(
parse_line("/logs5"),
Some(WorldLine::Message("unknown command; type /help".into()))
);
assert_eq!(
parse_line("/logs55"),
Some(WorldLine::Message("unknown command; type /help".into()))
);
assert_eq!(
parse_line("/logs\t5"),
Some(WorldLine::Message("unknown command; type /help".into()))
);
// A bare verb that takes an argument answers with its usage, like
// the trailing-space form already did — not "unknown command".
assert_eq!(
parse_line("/document"),
Some(WorldLine::Message("usage: /document <name>".into()))
);
assert_eq!(
parse_line("/input"),
Some(WorldLine::Message("usage: /input <hex>".into()))
);
}

#[test]
fn unknown_and_malformed_commands_become_messages() {
assert_eq!(
Expand Down
Loading