1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-03 14:26:17 +03:00

add some unit tests to check ratatui support

because doctests are run with tui-rs
Этот коммит содержится в:
rhysd
2023-04-13 23:10:34 +09:00
родитель 70279751ee
Коммит 87c6b03edf
4 изменённых файлов: 89 добавлений и 1 удалений

2
.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:

Просмотреть файл

@@ -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));
}
}

Просмотреть файл

@@ -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));
}
}

Просмотреть файл

@@ -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));
}
}