Skip to content

Commit 8d89d34

Browse files
committed
lib: Increase specification coverage
1 parent 36909ef commit 8d89d34

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Patch
44

5+
- Increase test coverage for specifications
56
- Update readme and documentation
67
- Add maintenance-related badges to Cargo.toml
78

lib/tests/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ fn specification() {
369369
spec.translate.from.push_str("1");
370370
spec.translate.to.push_str("0");
371371
assert_eq!(errmsg(spec.encoding()), "'1' has conflicting definitions");
372+
spec.translate.from.push_str("12");
373+
assert_eq!(errmsg(spec.encoding()), "translate from/to length mismatch");
374+
spec.translate.from = "Z".to_string();
375+
spec.translate.to = "2".to_string();
376+
assert_eq!(errmsg(spec.encoding()), "'2' is undefined");
372377
let mut spec = Specification::new();
373378
spec.wrap.width = 1;
374379
spec.wrap.separator.push_str("\n");
@@ -394,6 +399,28 @@ fn specification() {
394399
"invalid wrap width or separator length");
395400
}
396401

402+
#[test]
403+
fn round_trip() {
404+
let test = |e: Encoding| {
405+
assert_eq!(e.specification().encoding().unwrap(), e);
406+
};
407+
test(data_encoding::HEXLOWER);
408+
test(data_encoding::HEXLOWER_PERMISSIVE);
409+
test(data_encoding::HEXUPPER);
410+
test(data_encoding::HEXUPPER_PERMISSIVE);
411+
test(data_encoding::BASE32);
412+
test(data_encoding::BASE32_NOPAD);
413+
test(data_encoding::BASE32HEX);
414+
test(data_encoding::BASE32HEX_NOPAD);
415+
test(data_encoding::BASE32_DNSSEC);
416+
test(data_encoding::BASE32_DNSCURVE);
417+
test(data_encoding::BASE64);
418+
test(data_encoding::BASE64_NOPAD);
419+
test(data_encoding::BASE64_MIME);
420+
test(data_encoding::BASE64URL);
421+
test(data_encoding::BASE64URL_NOPAD);
422+
}
423+
397424
#[test]
398425
fn is_canonical() {
399426
fn test(expect: bool, update: &Fn(&mut Specification)) {

0 commit comments

Comments
 (0)