File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments