Skip to content

Commit

Permalink
torrent: add torrent parsing test
Browse files Browse the repository at this point in the history
  • Loading branch information
hails committed May 25, 2019
1 parent 497979f commit b44922e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,32 @@ pub fn parse(torrent: &mut BufRead) -> Result<Torrent, Error> {

Ok(parsed)
}

#[cfg(test)]
mod tests {
use super::*;
use std::fs::File;
use std::io::BufReader;

#[test]

fn parse_string_torrent() {
let file = File::open("tests/test.torrent").unwrap();

let torrent = parse(&mut BufReader::new(file)).unwrap();
assert_eq!(torrent.announce, "http://nyaa.tracker.wf:7777/announce");
assert!(torrent.announce_list.is_some());
assert_eq!(torrent.creation_date, 1276147560);

assert_eq!(torrent.info.name, "[CrunchyRip]_heroman_heroman_pv.ass");
assert_eq!(
torrent.info.pieces,
[
179, 44, 185, 20, 5, 96, 4, 178, 51, 254, 139, 204, 87, 213, 125, 68, 213, 108, 85,
199
],
);
assert_eq!(torrent.info.piece_length, 262144);
assert_eq!(torrent.info.length.unwrap(), 2084);
}
}
1 change: 1 addition & 0 deletions tests/test.torrent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d8:announce36:http://nyaa.tracker.wf:7777/announce13:announce-listll36:http://nyaa.tracker.wf:7777/announceel44:udp://tracker.openbittorrent.com:80/announceel43:http://open.nyaatorrents.info:6544/announceel33:udp://open.stealth.si:80/announceel42:udp://tracker.opentrackr.org:1337/announceel43:udp://tracker.coppersurfer.tk:6969/announceel37:udp://exodus.desync.com:6969/announceee7:comment27:https://nyaa.si/view/13637810:created by6:NyaaV213:creation datei1276147560e8:encoding5:UTF-84:infod6:lengthi2084e4:name35:[CrunchyRip]_heroman_heroman_pv.ass12:piece lengthi262144e6:pieces20:�,�`�3���W�}D�lU�ee

0 comments on commit b44922e

Please sign in to comment.