Skip to content

Commit

Permalink
test: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Oct 11, 2024
1 parent cb84880 commit 4ed3766
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 45 deletions.
8 changes: 8 additions & 0 deletions project-words.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
aliced
alicedee
alicee
alicei
alicelee
aliceli
bardei
baree
bareee
Expand All @@ -11,6 +15,7 @@ ddei
Deque
dlei
edee
eedee
eggse
elee
fdfc
Expand All @@ -23,7 +28,10 @@ fooe
fooi
foold
ldee
lled
lledee
llee
llei
llleee
ñandú
spame
Expand Down
215 changes: 170 additions & 45 deletions src/parsers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,35 +809,180 @@ mod tests {
);
}

/* todo:
#[test]
fn utf8_string_and_integer() {
assert_eq!(
bencode_to_json_unchecked(b"l5:alicei42ee"),
r#"["alice",42]"#.to_string()
);
}

utf8_string_and_integer
utf8_string_and_non_utf8_string
utf8_string_and_empty_list
utf8_string_and_list
utf8_string_and_empty_dict
utf8_string_and_dict
#[test]
fn utf8_string_and_non_utf8_string() {
assert_eq!(
bencode_to_json_unchecked(b"l5:alice1:\xFFe"),
r#"["alice","<hex>ff</hex>"]"#.to_string()
);
}

non_utf8_string_and_integer
non_utf8_string_and_utf8_string
non_utf8_string_and_empty_list
non_utf8_string_and_list
non_utf8_string_and_empty_dict
non_utf8_string_and_dict
#[test]
fn utf8_string_and_empty_list() {
assert_eq!(
bencode_to_json_unchecked(b"l5:alicelee"),
r#"["alice",[]]"#.to_string()
);
}

empty_list_and_integer
empty_list_and_string
empty_list_and_utf8_string
empty_list_and_non_utf8_string
empty_list_and_empty_dict
empty_list_and_dict
#[test]
fn utf8_string_and_list() {
assert_eq!(
bencode_to_json_unchecked(b"l5:aliceli42eee"),
r#"["alice",[42]]"#.to_string()
);
}

list_and_integer
list_and_string
list_and_utf8_string
list_and_non_utf8_string
list_and_empty_dict
list_and_dict
#[test]
fn utf8_string_and_empty_dict() {
assert_eq!(
bencode_to_json_unchecked(b"l5:alicedee"),
r#"["alice",{}]"#.to_string()
);
}

#[test]
fn utf8_string_and_dict() {
assert_eq!(
bencode_to_json_unchecked(b"l5:aliced3:fooi42eee"),
r#"["alice",{"foo":42}]"#.to_string()
);
}

#[test]
fn non_utf8_string_and_integer() {
assert_eq!(
bencode_to_json_unchecked(b"l1:\xFFi42ee"),
r#"["<hex>ff</hex>",42]"#.to_string()
);
}

#[test]
fn non_utf8_string_and_utf8_string() {
assert_eq!(
bencode_to_json_unchecked(b"l1:\xFF3:fooe"),
r#"["<hex>ff</hex>","foo"]"#.to_string()
);
}

#[test]
fn non_utf8_string_and_empty_list() {
assert_eq!(
bencode_to_json_unchecked(b"l1:\xFFlee"),
r#"["<hex>ff</hex>",[]]"#.to_string()
);
}

#[test]
fn non_utf8_string_and_list() {
assert_eq!(
bencode_to_json_unchecked(b"l1:\xFFli42eee"),
r#"["<hex>ff</hex>",[42]]"#.to_string()
);
}

#[test]
fn non_utf8_string_and_empty_dict() {
assert_eq!(
bencode_to_json_unchecked(b"l1:\xFFdee"),
r#"["<hex>ff</hex>",{}]"#.to_string()
);
}

#[test]
fn non_utf8_string_and_dict() {
assert_eq!(
bencode_to_json_unchecked(b"l1:\xFFd3:fooi42eee"),
r#"["<hex>ff</hex>",{"foo":42}]"#.to_string()
);
}

#[test]
fn empty_list_and_integer() {
assert_eq!(
bencode_to_json_unchecked(b"llei42ee"),
r"[[],42]".to_string()
);
}

#[test]
fn empty_list_and_utf8_string() {
assert_eq!(
bencode_to_json_unchecked(b"lle3:fooe"),
r#"[[],"foo"]"#.to_string()
);
}

#[test]
fn empty_list_and_non_utf8_string() {
assert_eq!(
bencode_to_json_unchecked(b"lle1:\xFFe"),
r#"[[],"<hex>ff</hex>"]"#.to_string()
);
}

#[test]
fn empty_list_and_empty_dict() {
assert_eq!(bencode_to_json_unchecked(b"lledee"), r"[[],{}]".to_string());
}

#[test]
fn empty_list_and_dict() {
assert_eq!(
bencode_to_json_unchecked(b"lled3:fooi42eee"),
r#"[[],{"foo":42}]"#.to_string()
);
}

#[test]
fn list_and_integer() {
assert_eq!(
bencode_to_json_unchecked(b"lli42eei43ee"),
r"[[42],43]".to_string()
);
}

#[test]
fn list_and_utf8_string() {
assert_eq!(
bencode_to_json_unchecked(b"lli42ee3:fooe"),
r#"[[42],"foo"]"#.to_string()
);
}

#[test]
fn list_and_non_utf8_string() {
assert_eq!(
bencode_to_json_unchecked(b"lli42ee1:\xFFe"),
r#"[[42],"<hex>ff</hex>"]"#.to_string()
);
}

#[test]
fn list_and_empty_dict() {
assert_eq!(
bencode_to_json_unchecked(b"lli42eedee"),
r"[[42],{}]".to_string()
);
}

#[test]
fn list_and_dict() {
assert_eq!(
bencode_to_json_unchecked(b"lli42eed3:fooi43eee"),
r#"[[42],{"foo":43}]"#.to_string()
);
}

/* todo:
empty_dict_and_integer
empty_dict_and_string
Expand All @@ -854,33 +999,13 @@ mod tests {
dict_and_list
*/

#[test]
fn utf8_string_and_integer() {
assert_eq!(
bencode_to_json_unchecked(b"l5:alicei42ee"),
r#"["alice",42]"#.to_string()
);
}

#[test]
fn non_utf8_string_and_an_integer() {
assert_eq!(
bencode_to_json_unchecked(b"l2:\xFF\xFEi42ee"),
r#"["<hex>fffe</hex>",42]"#.to_string()
);
}

mod integer_and_list {
use crate::parsers::tests::bencode_to_json_unchecked;

#[test]
fn second_item_empty_list() {
assert_eq!(
bencode_to_json_unchecked(b"li42elee"),
"[42,[]]".to_string()
);
}
}
}

#[test]
Expand Down

0 comments on commit 4ed3766

Please sign in to comment.