Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed May 29, 2024
1 parent 461aa92 commit e3f64b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sea-orm-macros/src/derives/active_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ActiveEnum {
_ => return Err(Error::InputNotEnum),
};

let mut is_string = false;
let mut is_string = rename_all_rule.is_some();
let mut is_int = false;
let mut variants = Vec::new();

Expand Down Expand Up @@ -129,7 +129,7 @@ impl ActiveEnum {
.map_err(Error::Syn)?;
}

if (is_string || rename_rule.is_some() || rename_all_rule.is_some()) && is_int {
if is_string && is_int {
return Err(Error::TT(quote_spanned! {
ident_span => compile_error!("All enum variants should specify the same `*_value` macro attribute, either `string_value` or `num_value` but not both");
}));
Expand Down
12 changes: 12 additions & 0 deletions sea-orm-macros/tests/derive_active_enum_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ pub enum TestEnum2 {
HelloWorldTwo,
}

#[derive(Debug, EnumIter, DeriveActiveEnum, Eq, PartialEq)]
#[sea_orm(
rs_type = "String",
db_type = "String(StringLen::None)",
rename_all = "snake_case"
)]
pub enum TestEnum3 {
HelloWorld,
}

#[test]
fn derive_active_enum_value() {
assert_eq!(TestEnum::DefaultVariant.to_value(), "defaultVariant");
Expand Down Expand Up @@ -124,4 +134,6 @@ fn derive_active_enum_from_value() {
fn derive_active_enum_value_2() {
assert_eq!(TestEnum2::HelloWorld.to_value(), "hello_world");
assert_eq!(TestEnum2::HelloWorldTwo.to_value(), "helloWorldTwo");

assert_eq!(TestEnum3::HelloWorld.to_value(), "hello_world");
}

0 comments on commit e3f64b1

Please sign in to comment.