Skip to content

Commit

Permalink
Fix DeriveActiveEnum expand enum variant starts with number (#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 authored Nov 15, 2022
1 parent 2f555e1 commit 1be6673
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sea-orm-macros/src/derives/active_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ impl ActiveEnum {
let enum_variant_iden = format_ident!("{}Variant", ident);
let enum_variants: Vec<syn::Ident> = str_variants
.iter()
.map(|v| format_ident!("{}", v.to_camel_case()))
.map(|v| {
if v.chars().next().map(char::is_numeric).unwrap_or(false) {
format_ident!("_{}", v)
} else {
format_ident!("{}", v.to_camel_case())
}
})
.collect();

quote!(
Expand Down
27 changes: 27 additions & 0 deletions tests/common/features/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,30 @@ pub enum Tea {
#[sea_orm(string_value = "BreakfastTea")]
BreakfastTea,
}

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "media_type")]
pub enum MediaType {
#[sea_orm(string_value = "UNKNOWN")]
Unknown,
#[sea_orm(string_value = "BITMAP")]
Bitmap,
#[sea_orm(string_value = "DRAWING")]
Drawing,
#[sea_orm(string_value = "AUDIO")]
Audio,
#[sea_orm(string_value = "VIDEO")]
Video,
#[sea_orm(string_value = "MULTIMEDIA")]
Multimedia,
#[sea_orm(string_value = "OFFICE")]
Office,
#[sea_orm(string_value = "TEXT")]
Text,
#[sea_orm(string_value = "EXECUTABLE")]
Executable,
#[sea_orm(string_value = "ARCHIVE")]
Archive,
#[sea_orm(string_value = "3D")]
_3D,
}

0 comments on commit 1be6673

Please sign in to comment.