Skip to content

Commit 51fc0d4

Browse files
committed
Refactor
1 parent 3afb7a7 commit 51fc0d4

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

crates/vespera_macro/src/schema_macro/type_utils.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ pub fn capitalize_first(s: &str) -> String {
211211
mod tests {
212212
use super::*;
213213
use rstest::rstest;
214+
fn empty_type_path() -> syn::Type {
215+
syn::Type::Path(syn::TypePath {
216+
qself: None,
217+
path: syn::Path {
218+
leading_colon: None,
219+
segments: syn::punctuated::Punctuated::new(),
220+
},
221+
})
222+
}
214223

215224
#[rstest]
216225
#[case("hello", "Hello")]
@@ -296,6 +305,18 @@ mod tests {
296305
assert!(!is_option_type(&ty));
297306
}
298307

308+
#[test]
309+
fn test_is_option_type_non_path() {
310+
let ty: syn::Type = syn::parse_str("&str").unwrap();
311+
assert!(!is_option_type(&ty));
312+
}
313+
314+
#[test]
315+
fn test_is_option_type_empty_path() {
316+
let ty = empty_type_path();
317+
assert!(!is_option_type(&ty));
318+
}
319+
299320
#[test]
300321
fn test_is_seaorm_relation_type_has_one() {
301322
let ty: syn::Type = syn::parse_str("HasOne<User>").unwrap();
@@ -326,6 +347,12 @@ mod tests {
326347
assert!(!is_seaorm_relation_type(&ty));
327348
}
328349

350+
#[test]
351+
fn test_is_seaorm_relation_type_empty_path() {
352+
let ty = empty_type_path();
353+
assert!(!is_seaorm_relation_type(&ty));
354+
}
355+
329356
#[test]
330357
fn test_is_seaorm_model_with_sea_orm_attr() {
331358
let struct_item: syn::ItemStruct = syn::parse_str(
@@ -446,4 +473,13 @@ mod tests {
446473
let output = tokens.to_string();
447474
assert!(output.contains("crate :: models :: CustomType < T >"));
448475
}
476+
477+
#[test]
478+
fn test_resolve_type_to_absolute_path_empty_segments() {
479+
let ty = empty_type_path();
480+
let module_path = vec!["crate".to_string()];
481+
let tokens = resolve_type_to_absolute_path(&ty, &module_path);
482+
let output = tokens.to_string();
483+
assert!(output.trim().is_empty());
484+
}
449485
}

0 commit comments

Comments
 (0)