Lines
100 %
Functions
Branches
use crate::{Boundary, Document, LineNumber, Navigator, Position, Row, ViewportOffset};
use std::path::PathBuf;
fn test_document() -> Document {
Document::new(
vec![
Row::from("Test line 2"),
Row::from(""),
],
PathBuf::from("test.txt"),
)
}
fn test_row_word_nav() -> Row {
Row::from("const STATUS_FG_COLOR: color::Rgb = color::Rgb(63, 63, 63);")
fn test_row_word_nav_unicode() -> Row {
Row::from("I \u{9ec} unicode!")
#[test]
fn test_find_index_of_first_non_whitespace() {
assert_eq!(
Navigator::find_index_of_first_non_whitespace(&Row::from(" test")),
Some(2)
);
fn test_find_matching_closing_symbol() {
let doc = Document::new(vec![Row::from("fn test() {}")], PathBuf::from("test.txt"));
Navigator::find_matching_closing_symbol(
&doc,
&Position { x: 7, y: 0 },
&ViewportOffset {
columns: 0,
rows: 0
},
),
Some(Position { x: 8, y: 0 })
fn test_find_matching_closing_symbol_multiline() {
let doc = Document::new(
Row::from("fn test() {"),
Row::from(" return 2;"),
Row::from("};"),
&Position { x: 10, y: 0 },
Some(Position { x: 0, y: 2 })
fn test_find_matching_closing_symbol_no_match() {
let doc = Document::new(vec![Row::from("fn test( {}")], PathBuf::from("test.txt"));
None
fn test_find_matching_opening_symbol() {
Navigator::find_matching_opening_symbol(
&Position { x: 11, y: 0 },
Some(Position { x: 10, y: 0 })
fn test_find_matching_opening_symbol_multiline() {
&Position { x: 0, y: 2 },
fn test_find_matching_opening_symbol_no_match() {
let doc = Document::new(vec![Row::from("fn test) {}")], PathBuf::from("test.txt"));
/// Make sure that the end of the current paragraph is on the
/// next all-whitespace line.
fn test_find_line_number_of_end_of_paragraph() {
Navigator::find_line_number_of_start_or_end_of_paragraph(
&test_document(),
LineNumber::new(1),
&Boundary::End
LineNumber::new(2)
/// Make sure that the end of the current paragraph when the cursor
/// is located on the last line of the doc is the current line
fn test_find_line_number_of_end_of_paragraph_when_at_end_of_document() {
test_document().last_line_number(),
test_document().last_line_number()
/// Make sure that the start of the current paragraph is on the
/// previous all-whitespace line.
fn test_find_line_number_of_start_of_paragraph() {
&Boundary::Start
/// Make sure that the start of the current paragraph when the cursor
/// is located on the first line of the doc is the current line
fn test_find_line_number_of_start_of_paragraph_when_at_first_line() {
LineNumber::new(1)
fn test_is_word_delimiter_false() {
assert!(!Navigator::is_word_delimiter('a', 'a'));
assert!(!Navigator::is_word_delimiter('a', ' '));
assert!(!Navigator::is_word_delimiter('a', '_'));
assert!(!Navigator::is_word_delimiter('_', 'a'));
assert!(!Navigator::is_word_delimiter(':', ':'));
fn test_is_word_delimiter_true() {
assert!(Navigator::is_word_delimiter('a', ':'));
assert!(Navigator::is_word_delimiter(':', 'a'));
assert!(Navigator::is_word_delimiter(' ', 'a'));
assert!(Navigator::is_word_delimiter('"', 'a'));
assert!(Navigator::is_word_delimiter('a', '"'));
fn test_is_word_delimited_unicode() {
assert!(Navigator::is_word_delimiter(' ', '\u{9ec}'));
fn test_find_index_of_next_word() {
let test_cases: Vec<(usize, usize)> = vec![
// const STATUS_FG_COLOR
// 0.....6
(0, 6),
// const STATUS_FG_COLOR: color::Rgb
// 6..............^21
(6, 21),
// 21^.^23
(21, 23),
// 23^....^26
(23, 28),
(58, 58), // EOL
];
for (start_index, expected_next_word_start_index) in test_cases {
Navigator::find_index_of_next_or_previous_word(
&test_row_word_nav(),
start_index,
expected_next_word_start_index
fn test_find_index_of_next_word_with_unicode_chars() {
// I * unicode!
// 0.2.4......^11
(0, 2),
(2, 4),
(4, 11),
&test_row_word_nav_unicode(),
fn test_find_index_of_previous_word() {
(6, 0),
(21, 6),
(23, 21),
(28, 23),
(1, 0),
(0, 0),
fn test_find_index_of_previous_word_with_unicode() {
(11, 4),
(4, 2),
(2, 0),