Skip to content

Commit 0dccf8e

Browse files
committed
Add tests
1 parent a5b9485 commit 0dccf8e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

crates/ark/src/treesitter.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,53 @@ pub(crate) fn point_end_of_previous_row(
590590
point
591591
}
592592
}
593+
594+
#[cfg(test)]
595+
mod tests {
596+
use ropey::Rope;
597+
use tree_sitter::Point;
598+
599+
use super::*;
600+
601+
#[test]
602+
fn test_point_end_of_previous_row() {
603+
let contents = Rope::from_str("hello world\nfoo bar\nbaz");
604+
let point = Point { row: 2, column: 1 };
605+
let result = point_end_of_previous_row(point, &contents);
606+
assert_eq!(result, Point { row: 1, column: 7 });
607+
}
608+
609+
#[test]
610+
fn test_point_end_of_previous_row_first_row() {
611+
let contents = Rope::from_str("hello world\nfoo bar\nbaz");
612+
let point = Point { row: 0, column: 5 };
613+
let result = point_end_of_previous_row(point, &contents);
614+
assert_eq!(result, Point { row: 0, column: 0 });
615+
}
616+
617+
#[test]
618+
fn test_point_end_of_previous_row_empty_previous_line() {
619+
let contents = Rope::from_str("hello\n\nworld");
620+
621+
let point = Point { row: 2, column: 1 };
622+
let result = point_end_of_previous_row(point, &contents);
623+
assert_eq!(result, Point { row: 1, column: 0 });
624+
625+
let point = Point { row: 1, column: 1 };
626+
let result = point_end_of_previous_row(point, &contents);
627+
assert_eq!(result, Point { row: 0, column: 5 });
628+
}
629+
630+
#[test]
631+
fn test_point_end_of_previous_row_single_line() {
632+
let contents = Rope::from_str("hello world");
633+
634+
let point = Point { row: 0, column: 0 };
635+
let result = point_end_of_previous_row(point, &contents);
636+
assert_eq!(result, Point { row: 0, column: 0 });
637+
638+
let point = Point { row: 0, column: 5 };
639+
let result = point_end_of_previous_row(point, &contents);
640+
assert_eq!(result, Point { row: 0, column: 0 });
641+
}
642+
}

0 commit comments

Comments
 (0)