Skip to content

Commit 06c575e

Browse files
committed
Add case
1 parent a6dc757 commit 06c575e

4 files changed

Lines changed: 26 additions & 30 deletions

crates/vespera_macro/src/parser/is_keyword_type.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,7 @@ pub fn is_keyword_type(ty: &Type, keyword: &KeywordType) -> bool {
3636
}
3737

3838
pub fn is_keyword_type_by_type_path(ty: &TypePath, keyword: &KeywordType) -> bool {
39-
if let Some(segment) = ty.path.segments.last()
40-
&& segment.ident == keyword.as_str()
41-
{
42-
true
43-
} else {
44-
false
45-
}
39+
return ty.path.segments.last().unwrap().ident == keyword.as_str();
4640
}
4741

4842
#[cfg(test)]

crates/vespera_macro/src/parser/request_body.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pub fn parse_request_body(
2929
FnArg::Typed(PatType { ty, .. }) => {
3030
if let Type::Path(type_path) = ty.as_ref() {
3131
let path = &type_path.path;
32-
if path.segments.is_empty() {
33-
return None;
34-
}
3532

3633
// Check the last segment (handles both Json<T> and vespera::axum::Json<T>)
3734
let segment = path.segments.last().unwrap();
@@ -93,13 +90,27 @@ mod tests {
9390
use insta::{assert_debug_snapshot, with_settings};
9491
use rstest::rstest;
9592
use std::collections::HashMap;
96-
use vespera_core::schema::{SchemaRef, SchemaType};
93+
94+
#[rstest]
95+
#[case("String", true)]
96+
#[case("str", true)]
97+
#[case("&String", true)]
98+
#[case("&str", true)]
99+
#[case("i32", false)]
100+
#[case("Vec<String>", false)]
101+
#[case("!", false)]
102+
fn test_is_string_like_cases(#[case] ty_src: &str, #[case] expected: bool) {
103+
let ty: Type = syn::parse_str(ty_src).expect("type parse failed");
104+
assert_eq!(is_string_like(&ty), expected);
105+
}
97106

98107
#[rstest]
99108
#[case::json("fn test(Json(payload): Json<User>) {}", true, "json")]
100109
#[case::string("fn test(just_string: String) {}", true, "string")]
101110
#[case::str("fn test(just_str: &str) {}", true, "str")]
102111
#[case::i32("fn test(just_i32: i32) {}", false, "i32")]
112+
#[case::vec_string("fn test(just_vec_string: Vec<String>) {}", false, "vec_string")]
113+
#[case::self_ref("fn test(&self) {}", false, "self_ref")]
103114
fn test_parse_request_body_cases(
104115
#[case] func_src: &str,
105116
#[case] has_body: bool,
@@ -113,23 +124,4 @@ mod tests {
113124
assert_debug_snapshot!(body);
114125
});
115126
}
116-
117-
#[test]
118-
fn test_parse_request_body_text_plain_schema() {
119-
let func: syn::ItemFn = syn::parse_str("fn test(body: &str) {}").unwrap();
120-
let arg = func.sig.inputs.first().unwrap();
121-
let body = parse_request_body(arg, &HashMap::new(), &HashMap::new())
122-
.expect("expected request body");
123-
124-
let media = body
125-
.content
126-
.get("text/plain")
127-
.expect("expected text/plain content");
128-
129-
if let SchemaRef::Inline(schema) = media.schema.as_ref().expect("schema expected") {
130-
assert_eq!(schema.schema_type, Some(SchemaType::String));
131-
} else {
132-
panic!("expected inline schema");
133-
}
134-
}
135127
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: crates/vespera_macro/src/parser/request_body.rs
3+
expression: body
4+
---
5+
None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: crates/vespera_macro/src/parser/request_body.rs
3+
expression: body
4+
---
5+
None

0 commit comments

Comments
 (0)