Skip to content

Commit d548df2

Browse files
committed
more tests + changelog update
1 parent 21db153 commit d548df2

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
**v0.4.3:**
4+
- More tests for `is_blocked_id`
5+
- Cargo update
6+
37
**v0.4.2:**
48
- Fix u64 overflow panic [[PR #5](https://github.com/sqids/sqids-rust/pull/7)]
59
- Cargo update

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ description = "Generate short unique ids from numbers."
44
repository = "https://github.com/sqids/sqids-rust"
55
documentation = "https://docs.rs/sqids"
66
homepage = "https://sqids.org/rust"
7-
version = "0.4.2"
7+
version = "0.4.3"
88
license = "MIT"
99
edition = "2021"
1010
readme = "README.md"
1111
keywords = ["ids", "encode", "short", "sqids", "hashids"]
1212

1313
[dependencies]
1414
derive_builder = "0.20.2"
15-
serde = "1.0.216"
16-
serde_json = "1.0.133"
17-
thiserror = "2.0.8"
15+
serde = "1.0.217"
16+
serde_json = "1.0.134"
17+
thiserror = "2.0.9"

tests/blocklist.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,33 @@ fn max_encoding_attempts() {
119119

120120
assert_eq!(sqids.encode(&[0]).err().unwrap(), Error::BlocklistMaxAttempts);
121121
}
122+
123+
#[test]
124+
fn specific_is_blocked_id_scenarios() {
125+
let sqids = Sqids::builder().blocklist(["hey".to_string()].into()).build().unwrap();
126+
assert_eq!(sqids.encode(&[100]).unwrap(), "86u".to_string());
127+
128+
let sqids = Sqids::builder().blocklist(["86u".to_string()].into()).build().unwrap();
129+
assert_eq!(sqids.encode(&[100]).unwrap(), "sec".to_string());
130+
131+
let sqids = Sqids::builder().blocklist(["vFo".to_string()].into()).build().unwrap();
132+
assert_eq!(sqids.encode(&[1_000_000]).unwrap(), "gMvFo".to_string());
133+
134+
let sqids = Sqids::builder().blocklist(["lP3i".to_string()].into()).build().unwrap();
135+
assert_eq!(sqids.encode(&[100, 202, 303, 404]).unwrap(), "oDqljxrokxRt".to_string());
136+
137+
let sqids = Sqids::builder().blocklist(["1HkYs".to_string()].into()).build().unwrap();
138+
assert_eq!(sqids.encode(&[100, 202, 303, 404]).unwrap(), "oDqljxrokxRt".to_string());
139+
140+
let sqids = Sqids::builder().blocklist(["0hfxX".to_string()].into()).build().unwrap();
141+
assert_eq!(
142+
sqids.encode(&[101, 202, 303, 404, 505, 606, 707]).unwrap(),
143+
"862REt0hfxXVdsLG8vGWD".to_string()
144+
);
145+
146+
let sqids = Sqids::builder().blocklist(["hfxX".to_string()].into()).build().unwrap();
147+
assert_eq!(
148+
sqids.encode(&[101, 202, 303, 404, 505, 606, 707]).unwrap(),
149+
"seu8n1jO9C4KQQDxdOxsK".to_string()
150+
);
151+
}

0 commit comments

Comments
 (0)