//! ASCII round-trips and the hard-coded golden vector.

mod common;

use common::{compress_streamed, decompress_streamed, printable_ascii};

#[test]
fn printable_ascii_has_95_chars() {
    assert_eq!(printable_ascii().chars().count(), 95);
}

#[test]
fn repeated_ascii_compresses_to_known_value() {
    let data = "hello hello hello";
    assert_eq!(data.len(), 17);

    let compressed = lzbase62::compress(data);
    assert_eq!(compressed, "tYVccfxGM");
    assert_eq!(compressed.len(), 9);

    assert_eq!(lzbase62::decompress(&compressed), data);
}

#[test]
fn printable_ascii_round_trips() {
    let sample = printable_ascii();
    let compressed = lzbase62::compress(&sample);
    assert!(!compressed.is_empty());
    assert_eq!(lzbase62::decompress(&compressed), sample);
}

#[test]
fn printable_ascii_round_trips_streaming() {
    let sample = printable_ascii();
    let compressed = compress_streamed(&sample);
    assert!(!compressed.is_empty());
    assert_eq!(decompress_streamed(&compressed), sample);
}

#[test]
fn large_ascii_shrinks_and_round_trips() {
    // `new Array(6).join(sample)` repeats the sample five times.
    let large = printable_ascii().repeat(5);
    let compressed = lzbase62::compress(&large);
    assert!(large.len() > compressed.len(), "compression must shrink");
    assert_eq!(lzbase62::decompress(&compressed), large);
}

#[test]
fn large_ascii_round_trips_streaming() {
    let large = printable_ascii().repeat(5);
    let compressed = compress_streamed(&large);
    assert!(large.len() > compressed.len());
    assert_eq!(decompress_streamed(&compressed), large);
}
