Skip to content

Commit

Permalink
dev: add expected message to bencode panic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Sep 5, 2023
1 parent 8b48b0c commit 2fa3742
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions contrib/bencode/src/reference/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,69 +329,68 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidByte { pos: 0 }"]
fn negative_decode_bytes_neg_len() {
BencodeRef::decode(BYTES_NEG_LEN, BDecodeOpt::default()).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(BytesEmpty { pos: 20 }"]
fn negative_decode_bytes_extra() {
BencodeRef::decode(BYTES_EXTRA, BDecodeOpt::default()).unwrap();
}

#[test]
#[should_panic]
fn negative_decode_bytes_not_utf8() {
let bencode = BencodeRef::decode(BYTES_NOT_UTF8, BDecodeOpt::default()).unwrap();

bencode.str().unwrap();
assert!(bencode.str().is_none());
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidIntParseError { pos: 1 }"]
fn negative_decode_int_nan() {
super::decode_int(INT_NAN, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidIntZeroPadding { pos: 1 }"]
fn negative_decode_int_leading_zero() {
super::decode_int(INT_LEADING_ZERO, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidIntZeroPadding { pos: 1 }"]
fn negative_decode_int_double_zero() {
super::decode_int(INT_DOUBLE_ZERO, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidIntNegativeZero { pos: 1 }"]
fn negative_decode_int_negative_zero() {
super::decode_int(INT_NEGATIVE_ZERO, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = " BencodeParseError(InvalidIntParseError { pos: 1 }"]
fn negative_decode_int_double_negative() {
super::decode_int(INT_DOUBLE_NEGATIVE, 1, crate::BEN_END).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidKeyOrdering { pos: 15, key: [97, 95, 107, 101, 121] }"]
fn negative_decode_dict_unordered_keys() {
BencodeRef::decode(DICT_UNORDERED_KEYS, BDecodeOpt::new(5, true, true)).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidKeyDuplicates { pos: 18, key: [97, 95, 107, 101, 121] }"]
fn negative_decode_dict_dup_keys_same_data() {
BencodeRef::decode(DICT_DUP_KEYS_SAME_DATA, BDecodeOpt::default()).unwrap();
}

#[test]
#[should_panic]
#[should_panic = "BencodeParseError(InvalidKeyDuplicates { pos: 18, key: [97, 95, 107, 101, 121] }"]
fn negative_decode_dict_dup_keys_diff_data() {
BencodeRef::decode(DICT_DUP_KEYS_DIFF_DATA, BDecodeOpt::default()).unwrap();
}
Expand Down

0 comments on commit 2fa3742

Please sign in to comment.