use super::*;
use std::vec;

// ---- 10-bit packed RGB family (Ship 9e) ------------------------------

#[test]
fn x2rgb10_frame_try_new_accepts_valid_tight() {
  let buf = vec![0u8; 16 * 4 * 4];
  X2Rgb10LeFrame::try_new(&buf, 16, 4, 64).expect("valid");
}

#[test]
fn x2rgb10_frame_try_new_rejects_short_plane() {
  let small = vec![0u8; 16 * 4];
  assert!(matches!(
    X2Rgb10LeFrame::try_new(&small, 16, 4, 64),
    Err(X2Rgb10FrameError::InsufficientPlane(_))
  ));
}

#[test]
fn x2rgb10_frame_try_new_rejects_zero_dimension() {
  let buf = vec![0u8; 16 * 4 * 4];
  assert!(matches!(
    X2Rgb10LeFrame::try_new(&buf, 0, 4, 64),
    Err(X2Rgb10FrameError::ZeroDimension(_))
  ));
}

#[test]
fn x2rgb10_frame_try_new_rejects_stride_too_small() {
  let buf = vec![0u8; 16 * 4 * 4];
  assert!(matches!(
    X2Rgb10LeFrame::try_new(&buf, 16, 4, 63),
    Err(X2Rgb10FrameError::InsufficientStride(_))
  ));
}

#[test]
#[should_panic(expected = "invalid X2Rgb10Frame")]
fn x2rgb10_frame_new_panics_on_invalid() {
  let buf = vec![0u8; 10];
  let _ = X2Rgb10LeFrame::new(&buf, 16, 4, 64);
}

#[test]
fn x2rgb10_be_frame_alias_constructs() {
  // Phase 4: BE alias resolves to `X2Rgb10Frame<'_, true>`.
  let buf = vec![0u8; 16 * 4 * 4];
  let f = X2Rgb10BeFrame::try_new(&buf, 16, 4, 64).expect("valid");
  assert!(f.is_be());
  assert_eq!(f.width(), 16);
}

#[test]
fn x2bgr10_frame_try_new_accepts_valid_tight() {
  let buf = vec![0u8; 16 * 4 * 4];
  X2Bgr10LeFrame::try_new(&buf, 16, 4, 64).expect("valid");
}

#[test]
fn x2bgr10_frame_try_new_rejects_short_plane() {
  let small = vec![0u8; 16 * 4];
  assert!(matches!(
    X2Bgr10LeFrame::try_new(&small, 16, 4, 64),
    Err(X2Bgr10FrameError::InsufficientPlane(_))
  ));
}

#[test]
#[should_panic(expected = "invalid X2Bgr10Frame")]
fn x2bgr10_frame_new_panics_on_invalid() {
  let buf = vec![0u8; 10];
  let _ = X2Bgr10LeFrame::new(&buf, 16, 4, 64);
}

#[test]
fn x2bgr10_be_frame_alias_constructs() {
  let buf = vec![0u8; 16 * 4 * 4];
  let f = X2Bgr10BeFrame::try_new(&buf, 16, 4, 64).expect("valid");
  assert!(f.is_be());
}
