sea-orm/tests/derive_iden_tests.rs
darkmmon 866025a733
implement DeriveIden in sea-orm only (#1740)
* WIP, implementing Iden

* completed implementation for DeriveIden and added basic test cases

* added feature flag to prevent sea-orm::sea-query::DeriveIden from crashing when sea-query is not used

* fixed doc test and adjusted test case

* enable `sea-query-derive`'s `sea-orm` feature

* Bump `sea-query-derive` to v0.4

* Update Cargo.toml

* Update Cargo.toml

* adjusted test cases and updated so that iden attribute will not be snake cased

* Update Cargo.toml

* Update main.rs

---------

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
2023-07-13 16:28:35 +08:00

47 lines
959 B
Rust

pub mod common;
pub use common::{features::*, setup::*, TestContext};
use sea_orm::entity::prelude::*;
use sea_orm_macros::DeriveIden;
#[derive(DeriveIden)]
pub enum Class {
Id,
Title,
Text,
}
#[derive(DeriveIden)]
pub enum Book {
Id,
#[sea_orm(iden = "turtle")]
Title,
#[sea_orm(iden = "TeXt")]
Text,
#[sea_orm(iden = "ty_pe")]
Type,
}
#[derive(DeriveIden)]
struct Glyph;
#[derive(DeriveIden)]
#[sea_orm(iden = "weRd")]
struct Word;
#[test]
fn main() -> Result<(), DbErr> {
assert_eq!(Class::Id.to_string(), "id");
assert_eq!(Class::Title.to_string(), "title");
assert_eq!(Class::Text.to_string(), "text");
assert_eq!(Book::Id.to_string(), "id");
assert_eq!(Book::Title.to_string(), "turtle");
assert_eq!(Book::Text.to_string(), "TeXt");
assert_eq!(Book::Type.to_string(), "ty_pe");
assert_eq!(Glyph.to_string(), "glyph");
assert_eq!(Word.to_string(), "weRd");
Ok(())
}