diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6875baf..ce46ab2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: if: ${{ matrix.os != 'windows-latest' }} - run: cargo test --features=search -- --skip src\lib.rs if: ${{ matrix.os == 'windows-latest' }} - - run: cargo test --no-default-features --features=ratatui-crossterm,search -- --skip src + - run: cargo test --no-default-features --features=ratatui-crossterm,search -- --skip .rs lint: runs-on: ubuntu-latest steps: diff --git a/src/cursor.rs b/src/cursor.rs index 2b42f4b..f4c0e99 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -321,3 +321,31 @@ impl CursorMove { } } } + +#[cfg(test)] +mod tests { + // Seaparate tests for ratatui support + #[test] + fn in_viewport() { + use crate::tui::buffer::Buffer; + use crate::tui::layout::Rect; + use crate::tui::widgets::Widget; + use crate::{CursorMove, TextArea}; + + let mut textarea: TextArea = (0..20).into_iter().map(|i| i.to_string()).collect(); + let r = Rect { + x: 0, + y: 0, + width: 24, + height: 8, + }; + let mut b = Buffer::empty(r.clone()); + textarea.widget().render(r, &mut b); + + textarea.move_cursor(CursorMove::Bottom); + assert_eq!(textarea.cursor(), (19, 0)); + + textarea.move_cursor(CursorMove::InViewport); + assert_eq!(textarea.cursor(), (7, 0)); + } +} diff --git a/src/scroll.rs b/src/scroll.rs index ef83abf..ef46fe5 100644 --- a/src/scroll.rs +++ b/src/scroll.rs @@ -178,3 +178,33 @@ impl From<(i16, i16)> for Scrolling { Self::Delta { rows, cols } } } + +#[cfg(test)] +mod tests { + use super::*; + + // Seaparate tests for ratatui support + #[test] + fn delta() { + use crate::tui::buffer::Buffer; + use crate::tui::layout::Rect; + use crate::tui::widgets::Widget; + use crate::TextArea; + + let mut textarea: TextArea = (0..20).into_iter().map(|i| i.to_string()).collect(); + let r = Rect { + x: 0, + y: 0, + width: 24, + height: 8, + }; + let mut b = Buffer::empty(r.clone()); + textarea.widget().render(r, &mut b); + + textarea.scroll(Scrolling::Delta { rows: 2, cols: 0 }); + assert_eq!(textarea.cursor(), (2, 0)); + + textarea.scroll((1, 0)); + assert_eq!(textarea.cursor(), (3, 0)); + } +} diff --git a/src/textarea.rs b/src/textarea.rs index 9673cf3..5e14415 100644 --- a/src/textarea.rs +++ b/src/textarea.rs @@ -1597,3 +1597,33 @@ impl<'a> TextArea<'a> { self.move_cursor(CursorMove::InViewport); } } + +#[cfg(test)] +mod tests { + use super::*; + + // Seaparate tests for ratatui support + #[test] + fn scroll() { + use crate::tui::buffer::Buffer; + use crate::tui::layout::Rect; + use crate::tui::widgets::Widget; + + let mut textarea: TextArea = (0..20).into_iter().map(|i| i.to_string()).collect(); + let r = Rect { + x: 0, + y: 0, + width: 24, + height: 8, + }; + let mut b = Buffer::empty(r.clone()); + textarea.widget().render(r, &mut b); + + textarea.scroll((15, 0)); + assert_eq!(textarea.cursor(), (15, 0)); + textarea.scroll((-5, 0)); + assert_eq!(textarea.cursor(), (15, 0)); + textarea.scroll((-5, 0)); + assert_eq!(textarea.cursor(), (12, 0)); + } +}