Skip to content

Commit ca6d655

Browse files
authored
Feat support dash in path (#27)
* support dash in path * test: test_path_with_dash
1 parent 36cd6be commit ca6d655

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

aiscript-runtime/src/parser.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ impl<'a> Parser<'a> {
443443
path.push_str(self.current.lexeme);
444444
self.advance();
445445
}
446+
TokenType::Minus => {
447+
path.push('-');
448+
self.advance();
449+
}
446450
TokenType::OpenBrace | TokenType::Comma => break,
447451
_ => return Err(format!("Unexpected token in path: {:?}", self.current.kind)),
448452
}
@@ -930,4 +934,33 @@ mod tests {
930934
let result = parser.parse_route();
931935
assert!(result.is_ok());
932936
}
937+
938+
#[test]
939+
fn test_path_with_dash() {
940+
let input = r#"
941+
route /api {
942+
get /get-messages {
943+
return "Messages";
944+
}
945+
946+
post /user-profile/update-settings {
947+
return "Settings updated";
948+
}
949+
}
950+
"#;
951+
952+
let mut parser = Parser::new(input);
953+
let result = parser.parse_route();
954+
955+
let route = result.unwrap();
956+
assert_eq!(route.prefix, "/api");
957+
958+
let endpoint1 = &route.endpoints[0];
959+
assert_eq!(endpoint1.path_specs[0].method, HttpMethod::Get);
960+
assert_eq!(endpoint1.path_specs[0].path, "/get-messages");
961+
962+
let endpoint2 = &route.endpoints[1];
963+
assert_eq!(endpoint2.path_specs[0].method, HttpMethod::Post);
964+
assert_eq!(endpoint2.path_specs[0].path, "/user-profile/update-settings");
965+
}
933966
}

0 commit comments

Comments
 (0)