use crate::chopper::error::Result;
use crate::chopper::types::Row;
use crate::sink::sink::Sink;

pub struct AssertingSink {
    rows: Vec<Row>,
    current_row: usize,
}

impl AssertingSink {
    pub fn new(rows: Vec<Row>) -> AssertingSink {
        AssertingSink {
            rows,
            current_row: 0,
        }
    }
}

impl Sink for AssertingSink {
    fn write(&mut self, row: Box<Row>) -> Result<()> {
        assert_ne!(self.rows.len(), self.current_row);
        assert_eq!(row.as_ref(), &self.rows[self.current_row]);
        self.current_row += 1;
        Ok(())
    }

    fn flush(&mut self) -> Result<()> {
        assert_eq!(self.rows.len(), self.current_row);
        Ok(())
    }
}
