diff --git a/Cargo.toml b/Cargo.toml index 0b4575fa..e2f67e32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tardis" -version = "0.1.0-alpha14" +version = "0.1.0-alpha15" authors = ["gudaoxuri "] description = "Elegant, clean Rust development framework" keywords = ["http", "database", "web", "redis", "mq"] diff --git a/src/basic/field.rs b/src/basic/field.rs index 94681900..c16d7730 100644 --- a/src/basic/field.rs +++ b/src/basic/field.rs @@ -11,8 +11,8 @@ lazy_static! { static ref R_CODE_CS: Regex = Regex::new(r"^[A-Za-z0-9_]+$").expect("Regular parsing error"); } -static BASE62: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; -static BASE36: &str = "abcdefghijklmnopqrstuvwxyz0123456789"; +static BASE62: &str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +static BASE36: &str = "0123456789abcdefghijklmnopqrstuvwxyz"; pub static GENERAL_SPLIT: &str = "##"; @@ -26,9 +26,9 @@ pub static GENERAL_SPLIT: &str = "##"; /// use tardis::TardisFuns; /// assert!(TardisFuns::field.is_phone("18657120202")); /// assert_eq!(TardisFuns::field.incr_by_base62("abcd1").unwrap(), "abcd2"); -/// assert!(TardisFuns::field.incr_by_base62("999").is_none()); +/// assert!(TardisFuns::field.incr_by_base62("zzz").is_none()); /// assert_eq!(TardisFuns::field.incr_by_base36("abcd1").unwrap(), "abcd2"); -/// assert!(TardisFuns::field.incr_by_base36("999").is_none()); +/// assert!(TardisFuns::field.incr_by_base36("zzz").is_none()); /// assert!(TardisFuns::field.is_code_cs("Adw834_dfds")); /// assert!(!TardisFuns::field.is_code_cs(" Adw834_dfds")); /// assert!(!TardisFuns::field.is_code_cs("Adw834_d-fds")); @@ -90,10 +90,11 @@ impl TardisField { /// use tardis::TardisFuns; /// assert_eq!(TardisFuns::field.incr_by_base62("abcd1").unwrap(), "abcd2"); /// assert_eq!(TardisFuns::field.incr_by_base62("abcd12").unwrap(), "abcd13"); - /// assert_eq!(TardisFuns::field.incr_by_base62("abcd9").unwrap(), "abceA"); - /// assert_eq!(TardisFuns::field.incr_by_base62("azzz9").unwrap(), "azz0A"); - /// assert_eq!(TardisFuns::field.incr_by_base62("a9999").unwrap(), "bAAAA"); - /// assert!(TardisFuns::field.incr_by_base62("999").is_none()); + /// assert_eq!(TardisFuns::field.incr_by_base62("abcd9").unwrap(), "abcdA"); + /// assert_eq!(TardisFuns::field.incr_by_base62("abcdz").unwrap(), "abce0"); + /// assert_eq!(TardisFuns::field.incr_by_base62("azZzz").unwrap(), "aza00"); + /// assert_eq!(TardisFuns::field.incr_by_base62("azzzz").unwrap(), "b0000"); + /// assert!(TardisFuns::field.incr_by_base62("zzz").is_none()); /// ``` /// pub fn incr_by_base62(&self, str: &str) -> Option { @@ -117,10 +118,12 @@ impl TardisField { /// use tardis::TardisFuns; /// assert_eq!(TardisFuns::field.incr_by_base36("abcd1").unwrap(), "abcd2"); /// assert_eq!(TardisFuns::field.incr_by_base36("abcd12").unwrap(), "abcd13"); - /// assert_eq!(TardisFuns::field.incr_by_base36("abcd9").unwrap(), "abcea"); - /// assert_eq!(TardisFuns::field.incr_by_base36("azzz9").unwrap(), "azz0a"); - /// assert_eq!(TardisFuns::field.incr_by_base36("a9999").unwrap(), "baaaa"); - /// assert!(TardisFuns::field.incr_by_base36("999").is_none()); + /// assert_eq!(TardisFuns::field.incr_by_base36("abcd9").unwrap(), "abcda"); + /// assert_eq!(TardisFuns::field.incr_by_base36("0000").unwrap(), "0001"); + /// assert_eq!(TardisFuns::field.incr_by_base36("000z").unwrap(), "0010"); + /// assert_eq!(TardisFuns::field.incr_by_base36("azzzy").unwrap(), "azzzz"); + /// assert_eq!(TardisFuns::field.incr_by_base36("azzzz").unwrap(), "b0000"); + /// assert!(TardisFuns::field.incr_by_base36("zzz").is_none()); /// ``` /// pub fn incr_by_base36(&self, str: &str) -> Option { diff --git a/tests/test_basic_field.rs b/tests/test_basic_field.rs index e24d391d..dc4fc023 100644 --- a/tests/test_basic_field.rs +++ b/tests/test_basic_field.rs @@ -5,19 +5,22 @@ use tardis::TardisFuns; async fn test_basic_field() -> TardisResult<()> { assert!(TardisFuns::field.is_phone("18657120202")); - assert_eq!(TardisFuns::field.incr_by_base62("abcd1").unwrap(), "abcd2"); - assert_eq!(TardisFuns::field.incr_by_base62("abcd12").unwrap(), "abcd13"); - assert_eq!(TardisFuns::field.incr_by_base62("abcd9").unwrap(), "abceA"); - assert_eq!(TardisFuns::field.incr_by_base62("azzz9").unwrap(), "azz0A"); - assert_eq!(TardisFuns::field.incr_by_base62("a9999").unwrap(), "bAAAA"); - assert!(TardisFuns::field.incr_by_base62("999").is_none()); - assert_eq!(TardisFuns::field.incr_by_base36("abcd1").unwrap(), "abcd2"); assert_eq!(TardisFuns::field.incr_by_base36("abcd12").unwrap(), "abcd13"); - assert_eq!(TardisFuns::field.incr_by_base36("abcd9").unwrap(), "abcea"); - assert_eq!(TardisFuns::field.incr_by_base36("azzz9").unwrap(), "azz0a"); - assert_eq!(TardisFuns::field.incr_by_base36("a9999").unwrap(), "baaaa"); - assert!(TardisFuns::field.incr_by_base36("999").is_none()); + assert_eq!(TardisFuns::field.incr_by_base36("abcd9").unwrap(), "abcda"); + assert_eq!(TardisFuns::field.incr_by_base36("0000").unwrap(), "0001"); + assert_eq!(TardisFuns::field.incr_by_base36("000z").unwrap(), "0010"); + assert_eq!(TardisFuns::field.incr_by_base36("azzzy").unwrap(), "azzzz"); + assert_eq!(TardisFuns::field.incr_by_base36("azzzz").unwrap(), "b0000"); + assert!(TardisFuns::field.incr_by_base36("zzz").is_none()); + + assert_eq!(TardisFuns::field.incr_by_base62("abcd1").unwrap(), "abcd2"); + assert_eq!(TardisFuns::field.incr_by_base62("abcd12").unwrap(), "abcd13"); + assert_eq!(TardisFuns::field.incr_by_base62("abcd9").unwrap(), "abcdA"); + assert_eq!(TardisFuns::field.incr_by_base62("abcdz").unwrap(), "abce0"); + assert_eq!(TardisFuns::field.incr_by_base62("azZzz").unwrap(), "aza00"); + assert_eq!(TardisFuns::field.incr_by_base62("azzzz").unwrap(), "b0000"); + assert!(TardisFuns::field.incr_by_base62("zzz").is_none()); assert!(TardisFuns::field.is_code_cs("Adw834_dfds")); assert!(!TardisFuns::field.is_code_cs(" Adw834_dfds"));