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

Function test_basic_route

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

Source from the content-addressed store, hash-verified

480
481 #[test]
482 fn test_basic_route() {
483 let input = r#"
484 route /test/:id {
485 """
486 Test route line1
487 Test route line2
488 """
489
490 get /a {
491 """Test endpoint"""
492 query {
493 """field name"""
494 name: str = "hello",
495 age: int = 18,
496 }
497 body {
498 """field a"""
499 @length(max=10)
500 a: str,
501 b: bool = false,
502 }
503
504 let greeting = "Hello" + name;
505 if greeting {
506 print(greeting);
507 }
508 return greeting;
509 }
510
511 post /b {
512 """Test endpoint2"""
513
514 return "endpoint2";
515 }
516 }
517 "#;
518
519 let mut parser = Parser::new(input);
520 let result = parser.parse_route();
521
522 let route = result.unwrap();
523 assert_eq!(route.docs, "Test route line1\nTest route line2");
524 assert_eq!(route.prefix, "/test/{id}");
525 assert_eq!(route.params.len(), 1);
526 assert_eq!(route.params[0], "id");
527
528 let endpoint = &route.endpoints[0];
529 assert_eq!(endpoint.docs, "Test endpoint");
530 assert_eq!(endpoint.path_specs[0].method, HttpMethod::Get);
531 assert_eq!(endpoint.path_specs[0].path, "/a");
532
533 // Verify query parameters
534 assert_eq!(endpoint.query.len(), 2);
535 assert_eq!(endpoint.query[0].docs, "field name");
536 assert_eq!(endpoint.query[0].name, "name");
537 assert_eq!(endpoint.query[1].name, "age");
538
539 // Verify body fields

Callers

nothing calls this directly

Calls 1

parse_routeMethod · 0.80

Tested by

no test coverage detected