<commit_before>extern crate flate2;
extern crate tar;

use std::fs::File;
use flate2::read::GzDecoder;
use tar::Archive;

#[test]
fn targz() {
    let file = File::open("tests/simple.tar.gz").unwrap();
    let gz_decoder = GzDecoder::new(file).unwrap();
    let mut tar = Archive::new(gz_decoder);
    let expected = ["a", "b", "c/", "c/d"];
    let actual: Vec<_> = tar.files_mut().unwrap()
        .map(|f| f.unwrap().header().path().unwrap().to_str().unwrap().to_owned())
        .collect();
    assert_eq!(actual, expected);
}

#[test]
fn single_vol_names() {
    let file = File::open("tests/backups/single_vol/duplicity-full.20150617T182545Z.vol1.difftar.gz").unwrap();
    let gz_decoder = GzDecoder::new(file).unwrap();
    let mut tar = Archive::new(gz_decoder);
    for file in tar.files_mut().unwrap() {
        if let Ok(f) = file {
            println!("{:?} {:?}", f.header().mode(), f.header().path().unwrap())
        }
    }
}

#[test]
fn link() {
    use std::io::Read;

    let file = File::open("tests/link.tar").unwrap();
    let tar = Archive::new(file);
    let contents: Vec<_> = {
        tar.files()
           .unwrap()
           .map(|f| {
               let mut s = String::new();
               f.unwrap().read_to_string(&mut s).unwrap();
               s
           })
           .collect()
    };
    let expected = vec!["file", "file_contents"];
    assert_eq!(contents, expected);
}<commit_msg>Added tar test on symbolic links<commit_after>extern crate flate2;
extern crate tar;

use std::fs::File;
use flate2::read::GzDecoder;
use tar::Archive;

#[test]
fn targz() {
    let file = File::open("tests/simple.tar.gz").unwrap();
    let gz_decoder = GzDecoder::new(file).unwrap();
    let mut tar = Archive::new(gz_decoder);
    let expected = ["a", "b", "c/", "c/d"];
    let actual: Vec<_> = tar.files_mut()
                            .unwrap()
                            .map(|f| {
                                f.unwrap().header().path().unwrap().to_str().unwrap().to_owned()
                            })
                            .collect();
    assert_eq!(actual, expected);
}

#[test]
fn single_vol_names() {
    let file =
        File::open("tests/backups/single_vol/duplicity-full.20150617T182545Z.vol1.difftar.gz")
            .unwrap();
    let gz_decoder = GzDecoder::new(file).unwrap();
    let mut tar = Archive::new(gz_decoder);
    for file in tar.files_mut().unwrap() {
        if let Ok(f) = file {
            println!("{:?} {:?}", f.header().mode(), f.header().path().unwrap())
        }
    }
}

#[test]
fn link() {
    use std::io::Read;

    let file = File::open("tests/link.tar").unwrap();
    let tar = Archive::new(file);
    let contents: Vec<_> = {
        tar.files()
           .unwrap()
           .map(|f| {
               let mut f = f.unwrap();
               if f.header().entry_type().is_symlink() {
                   let link_name = f.header().link_name().unwrap().unwrap();
                   link_name.to_str().unwrap().to_owned()
               } else {
                   let mut s = String::new();
                   f.read_to_string(&mut s).unwrap();
                   s
               }
           })
           .collect()
    };
    let expected = vec!["file", "file_contents\n"];
    assert_eq!(contents, expected);
}
{'fraction_non_alphanumeric': 0.18530834340991537, 'fraction_numerical': 0.010278113663845224, 'mean_word_length': 2.098314606741573, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '454720', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1096, 'n_words': 208}