MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / test_path_param_validation

Function test_path_param_validation

aiscript-runtime/src/parser.rs:767–936  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

765
766 #[test]
767 fn test_path_param_validation() {
768 // Test 1: Successful case - path parameters in path spec match path block
769 let input = r#"
770 get /users/:id/posts/:postId {
771 path {
772 @string(min_len=3)
773 id: str,
774 postId: int,
775 }
776
777 return "Valid";
778 }
779 "#;
780
781 let mut parser = Parser::new(input);
782 let result = parser.parse_route();
783 assert!(result.is_ok());
784 let route = result.unwrap();
785 assert_eq!(route.endpoints.len(), 1);
786
787 // Test 2: Path parameter name mismatch (postid vs postId)
788 let input = r#"
789 get /users/:id/posts/:postid {
790 path {
791 @string(min_len=3)
792 id: str,
793 postId: int,
794 }
795
796 return "Invalid";
797 }
798 "#;
799
800 let mut parser = Parser::new(input);
801 let result = parser.parse_route();
802 assert!(result.is_err());
803 let error = result.unwrap_err();
804 assert!(error.contains("Path parameter case mismatch"));
805 assert!(error.contains("'postid' in URL vs 'postId' in path block"));
806
807 // Test 3: Extra parameter in path block
808 let input = r#"
809 get /users/:id/posts/:postId {
810 path {
811 @string(min_len=3)
812 id: str,
813 postId: int,
814 name: str
815 }
816
817 return "Invalid";
818 }
819 "#;
820
821 let mut parser = Parser::new(input);
822 let result = parser.parse_route();
823 assert!(result.is_err());
824 let error = result.unwrap_err();

Callers

nothing calls this directly

Calls 1

parse_routeMethod · 0.80

Tested by

no test coverage detected