Skip to content

Commit

Permalink
tests: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Oct 10, 2024
1 parent 88115c2 commit 17f77c5
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/parsers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,24 @@ mod tests {
assert!(matches!(result, Err(Error::PrematureEndOfDict)));
}

#[test]
fn when_the_first_field_value_is_empty() {
let dict_with_missing_key_value = b"d3:fooe";

let result = try_bencode_to_json(dict_with_missing_key_value);

assert!(matches!(result, Err(Error::PrematureEndOfDict)));
}

#[test]
fn when_the_second_field_value_is_empty() {
let dict_with_missing_key_value = b"d3:foo3:bar3:fooe";

let result = try_bencode_to_json(dict_with_missing_key_value);

assert!(matches!(result, Err(Error::PrematureEndOfDict)));
}

mod when_the_field_key_is_not_a_string_for_example {
use crate::parsers::error::Error;
use crate::parsers::BencodeType;
Expand Down Expand Up @@ -888,8 +906,6 @@ mod tests {

let result = try_bencode_to_json(field_with_list_key);

println!("{result:?}");

assert!(matches!(
result,
Err(Error::ExpectedStringForDictKeyGot(BencodeType::List))
Expand All @@ -902,8 +918,6 @@ mod tests {

let result = try_bencode_to_json(field_with_list_key);

println!("{result:?}");

assert!(matches!(
result,
Err(Error::ExpectedStringForDictKeyGot(BencodeType::List))
Expand All @@ -916,8 +930,6 @@ mod tests {

let result = try_bencode_to_json(field_with_list_key);

println!("{result:?}");

assert!(matches!(
result,
Err(Error::ExpectedStringForDictKeyGot(BencodeType::Dict))
Expand All @@ -930,21 +942,12 @@ mod tests {

let result = try_bencode_to_json(field_with_list_key);

println!("{result:?}");

assert!(matches!(
result,
Err(Error::ExpectedStringForDictKeyGot(BencodeType::Dict))
));
}
}

/* todo:
Error cases:
- A dictionary with one key pair, but only the key without value.
*/
}
}
}

0 comments on commit 17f77c5

Please sign in to comment.