#[cfg(test)] mod test { use json::object; use df_fields::Field; #[test] fn str() { let data = df_fields::str::Str::new(true, "str", "string", 6, "carry").field(); println!("Str: {}", data.clone()); assert_eq!(r#"{"require":true,"field":"str","mode":"string","title":"string","length":6,"def":"carry","dec":""}"#, data.to_string()); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::str::Pass::new(true, "pass", "密码", 3, "111111").field(); println!("Pass: {}", data.clone()); let field = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", field.clone()); let data = df_fields::verify(data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::str::Tel::new(true, "tel", "电话", "111111").field(); println!("tel: {}", data.clone()); let field = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", field.clone()); let data = df_fields::verify(data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::str::Email::new(true, "email", "邮件", "111111").field(); println!("email: {}", data.clone()); let field = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", field.clone()); let verify = df_fields::verify(data["field"].as_str().unwrap(), data.clone()); println!("field: {}", verify.clone()); } #[test] fn int() { let data = df_fields::int::Int::new(true, "int", "整数", 3, 0).field(); println!("Int: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::int::Switch::new(true, "Switch", "开关", true).field(); println!("Switch: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::int::AutoKey::new(true, "autokey", "自动主键").field(); println!("AutoKey: {}", data); let field = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", field.clone()); let data = df_fields::verify(data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); } #[test] fn text() { let data = df_fields::text::Text::new(true, "text", "长文本", "我的").field(); println!("Text: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::text::Table::new(true, "text", "长文本", "goods_ord", vec!["name", "code"], "test.test.test").field(); println!("Table: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::text::File::new(true, "file", "附件", 3, false, 0, vec![]).field(); println!("File: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::text::Json::new(true, "json", "JSON", object! {name:"111"}).field(); println!("File: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::text::Url::new(true, "url", "网址", "http").field(); println!("File: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); } #[test] fn float() { let data = df_fields::float::Float::new(true, "float", "小数", 12, 2, 12.20).field(); println!("Float: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::str::Key::new(true, "key", "自定义主键", 20).field(); println!("Key: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); } #[test] fn select() { let data = df_fields::select::Select::new(true, "select", "多选", vec!["我的", "你的", "他的"], vec!["你的"]).field(); println!("Select: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::select::Radio::new(true, "radio", "单选", vec!["我的", "你的", "他的"], "我的").field(); println!("Radio: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::select::Select::new(true, "select", "多选", vec!["我的", "你的", "他的"], vec!["你的", "他的"]).sql("mysql"); println!("Select: {}", data); let data = df_fields::select::Radio::new(true, "radio", "单选", vec!["我的", "你的", "他的"], "我的").sql("mysql"); println!("Radio: {}", data); } #[test] fn datetime() { let data = df_fields::datetime::Datetime::new(true, "datetime", "日期时间", "").field(); println!("Datetime: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::datetime::Year::new(true, "year", "年", 1920).field(); println!("Year: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::datetime::Date::new(true, "date", "日期", "").field(); println!("Date: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::datetime::Time::new(true, "time", "时间", "").field(); println!("Time: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); let data = df_fields::datetime::Timestamp::new(true, "timestamp", "时间戳", 4, 0.0).field(); println!("Timestamp: {}", data); let data = df_fields::field("mysql", data["field"].as_str().unwrap(), data.clone()); println!("field: {}", data.clone()); } #[test] fn date() { let data = df_fields::datetime::Timestamp::timestamp(); println!("timestamp: {} s", data); let datetime = df_fields::datetime::Datetime::timestamp_to_datetime(data); println!("timestamp_to_datetime: {} ", datetime); let data = df_fields::datetime::Date::timestamp_to_date(data); println!("timestamp_to_date: {} ", data); let data = df_fields::datetime::Timestamp::timestamp_ms(); println!("timestamp: {} ms", data); let data = df_fields::datetime::Timestamp::timestamp_μs(); println!("timestamp: {} μs", data); let data = df_fields::datetime::Timestamp::timestamp_ns(); println!("timestamp: {} ns", data); let data = df_fields::datetime::Date::date(); println!("date: {}", data); let data = df_fields::datetime::Timestamp::date_to_timestamp(data.as_str().clone()); println!("date: {}", data); let data = df_fields::datetime::Time::time(); println!("date: {}", data); let data = df_fields::datetime::Datetime::datetime(); println!("date: {}", data); let data = df_fields::datetime::Timestamp::datetime_to_timestamp(data.as_str().clone()); println!("date: {}", data); let data = df_fields::datetime::Year::year(); println!("date: {}", data); let data = df_fields::datetime::Timestamp::timestamp(); let data = df_fields::datetime::Year::timestamp_to_year(data); println!("date: {}", data); } }