Skip to content

Commit

Permalink
Fix base36 and base62 encoding character order error.
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Jul 6, 2022
1 parent f18f6f0 commit a5c9f87
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tardis"
version = "0.1.0-alpha14"
version = "0.1.0-alpha15"
authors = ["gudaoxuri <i@sunisle.org>"]
description = "Elegant, clean Rust development framework"
keywords = ["http", "database", "web", "redis", "mq"]
Expand Down
27 changes: 15 additions & 12 deletions src/basic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "##";

Expand All @@ -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"));
Expand Down Expand Up @@ -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<String> {
Expand All @@ -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<String> {
Expand Down
25 changes: 14 additions & 11 deletions tests/test_basic_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit a5c9f87

Please sign in to comment.