use maraiah::defl;

include!("data/rand.rs");

fn defl_gzip(inp: &[u8], out: &[u8])
{
	let b = &inp[defl::load_gzip_header(inp).unwrap()..];
	assert_eq!(defl::load_deflate(b).unwrap().1, out.to_vec());
}

fn defl_alice(inp: &[u8])
{
	const OUTPUT: &[u8] = include_bytes!("data/defl/alice.out");

	defl_gzip(inp, OUTPUT);
}

#[test]
fn defl_alice_1()
{
	const INPUT: &[u8] = include_bytes!("data/defl/alice1.in");

	defl_alice(INPUT);
}

#[test]
fn defl_alice_2()
{
	const INPUT: &[u8] = include_bytes!("data/defl/alice2.in");

	defl_alice(INPUT);
}

#[test]
#[ignore]
fn defl_shapes()
{
	const INPUT:  &[u8] = include_bytes!("data/defl/Shapes.in");
	const OUTPUT: &[u8] = include_bytes!("data/m2/Shapes");

	defl_gzip(INPUT, OUTPUT);
}

#[test]
fn defl_good_gzip_headers()
{
	defl::load_gzip_header(include_bytes!("data/gz/ok1.in")).unwrap();
	defl::load_gzip_header(include_bytes!("data/gz/ok2.in")).unwrap();
	defl::load_gzip_header(include_bytes!("data/gz/ok3.in")).unwrap();
}

#[test]
fn defl_bad_gzip_headers()
{
	for inp in &RANDOM {
		assert!(defl::load_gzip_header(inp).is_err());
	}

	assert!(defl::load_gzip_header(include_bytes!("data/gz/bad1.in")).is_err());
	assert!(defl::load_gzip_header(include_bytes!("data/gz/bad2.in")).is_err());
	assert!(defl::load_gzip_header(include_bytes!("data/gz/bad3.in")).is_err());
	assert!(defl::load_gzip_header(include_bytes!("data/gz/bad4.in")).is_err());
	assert!(defl::load_gzip_header(include_bytes!("data/gz/bad5.in")).is_err());
	assert!(defl::load_gzip_header(include_bytes!("data/gz/bad6.in")).is_err());
	assert!(defl::load_gzip_header(include_bytes!("data/gz/bad7.in")).is_err());
}

#[test]
#[allow(unused_must_use)]
fn defl_must_not_panic()
{
	for inp in &RANDOM {
		defl::load_deflate(inp);
	}
}

// EOF
