Skip to content

Commit

Permalink
more tests + changelog update
Browse files Browse the repository at this point in the history
  • Loading branch information
4kimov committed Jan 5, 2025
1 parent 21db153 commit d548df2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

**v0.4.3:**
- More tests for `is_blocked_id`
- Cargo update

**v0.4.2:**
- Fix u64 overflow panic [[PR #5](https://github.com/sqids/sqids-rust/pull/7)]
- Cargo update
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ description = "Generate short unique ids from numbers."
repository = "https://github.com/sqids/sqids-rust"
documentation = "https://docs.rs/sqids"
homepage = "https://sqids.org/rust"
version = "0.4.2"
version = "0.4.3"
license = "MIT"
edition = "2021"
readme = "README.md"
keywords = ["ids", "encode", "short", "sqids", "hashids"]

[dependencies]
derive_builder = "0.20.2"
serde = "1.0.216"
serde_json = "1.0.133"
thiserror = "2.0.8"
serde = "1.0.217"
serde_json = "1.0.134"
thiserror = "2.0.9"
30 changes: 30 additions & 0 deletions tests/blocklist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,33 @@ fn max_encoding_attempts() {

assert_eq!(sqids.encode(&[0]).err().unwrap(), Error::BlocklistMaxAttempts);
}

#[test]
fn specific_is_blocked_id_scenarios() {
let sqids = Sqids::builder().blocklist(["hey".to_string()].into()).build().unwrap();
assert_eq!(sqids.encode(&[100]).unwrap(), "86u".to_string());

let sqids = Sqids::builder().blocklist(["86u".to_string()].into()).build().unwrap();
assert_eq!(sqids.encode(&[100]).unwrap(), "sec".to_string());

let sqids = Sqids::builder().blocklist(["vFo".to_string()].into()).build().unwrap();
assert_eq!(sqids.encode(&[1_000_000]).unwrap(), "gMvFo".to_string());

let sqids = Sqids::builder().blocklist(["lP3i".to_string()].into()).build().unwrap();
assert_eq!(sqids.encode(&[100, 202, 303, 404]).unwrap(), "oDqljxrokxRt".to_string());

let sqids = Sqids::builder().blocklist(["1HkYs".to_string()].into()).build().unwrap();
assert_eq!(sqids.encode(&[100, 202, 303, 404]).unwrap(), "oDqljxrokxRt".to_string());

let sqids = Sqids::builder().blocklist(["0hfxX".to_string()].into()).build().unwrap();
assert_eq!(
sqids.encode(&[101, 202, 303, 404, 505, 606, 707]).unwrap(),
"862REt0hfxXVdsLG8vGWD".to_string()
);

let sqids = Sqids::builder().blocklist(["hfxX".to_string()].into()).build().unwrap();
assert_eq!(
sqids.encode(&[101, 202, 303, 404, 505, 606, 707]).unwrap(),
"seu8n1jO9C4KQQDxdOxsK".to_string()
);
}

0 comments on commit d548df2

Please sign in to comment.