@@ -222,6 +222,74 @@ mod tests {
use crate::{Buffer, DisplayMap, MultiBuffer};
use language::Point;
+ #[gpui::test]
+ fn test_previous_word_start(cx: &mut gpui::MutableAppContext) {
+ fn assert(marked_text: &str, cx: &mut gpui::MutableAppContext) {
+ let (snapshot, display_points) = marked_snapshot(marked_text, cx);
+ dbg!(&display_points);
+ assert_eq!(
+ previous_word_start(&snapshot, display_points[1]),
+ display_points[0]
+ );
+ }
+
+ assert("\n| |lorem", cx);
+ assert(" |lorem|", cx);
+ assert(" |lor|em", cx);
+ assert("\nlorem\n| |ipsum", cx);
+ assert("\n\n|\n|", cx);
+ assert(" |lorem |ipsum", cx);
+ assert("lorem|-|ipsum", cx);
+ assert("lorem|-#$@|ipsum", cx);
+ assert("|lorem_|ipsum", cx);
+ assert(" |defγ|", cx);
+ assert(" |bcΔ|", cx);
+ assert(" ab|——|cd", cx);
+ }
+
+ #[gpui::test]
+ fn test_next_word_end(cx: &mut gpui::MutableAppContext) {
+ fn assert(marked_text: &str, cx: &mut gpui::MutableAppContext) {
+ let (snapshot, display_points) = marked_snapshot(marked_text, cx);
+ assert_eq!(
+ next_word_end(&snapshot, display_points[0]),
+ display_points[1]
+ );
+ }
+
+ assert("\n| lorem|", cx);
+ assert(" |lorem|", cx);
+ assert(" lor|em|", cx);
+ assert(" lorem| |\nipsum\n", cx);
+ assert("\n|\n|\n\n", cx);
+ assert("lorem| ipsum| ", cx);
+ assert("lorem|-|ipsum", cx);
+ assert("lorem|#$@-|ipsum", cx);
+ assert("lorem|_ipsum|", cx);
+ assert(" |bcΔ|", cx);
+ assert(" ab|——|cd", cx);
+ }
+
+ #[gpui::test]
+ fn test_surrounding_word(cx: &mut gpui::MutableAppContext) {
+ fn assert(marked_text: &str, cx: &mut gpui::MutableAppContext) {
+ let (snapshot, display_points) = marked_snapshot(marked_text, cx);
+ assert_eq!(
+ surrounding_word(&snapshot, display_points[1]),
+ display_points[0]..display_points[2]
+ );
+ }
+
+ assert("||lorem| ipsum", cx);
+ assert("|lo|rem| ipsum", cx);
+ assert("|lorem|| ipsum", cx);
+ assert("lorem| | |ipsum", cx);
+ assert("lorem\n|||\nipsum", cx);
+ assert("lorem\n||ipsum|", cx);
+ assert("lorem,|| |ipsum", cx);
+ assert("|lorem||, ipsum", cx);
+ }
+
#[gpui::test]
fn test_move_up_and_down_with_excerpts(cx: &mut gpui::MutableAppContext) {
let family_id = cx.font_cache().load_family(&["Helvetica"]).unwrap();
@@ -291,49 +359,6 @@ mod tests {
);
}
- #[gpui::test]
- fn test_previous_word_start(cx: &mut gpui::MutableAppContext) {
- fn assert(marked_text: &str, cx: &mut gpui::MutableAppContext) {
- let (snapshot, display_points) = marked_snapshot(marked_text, cx);
- dbg!(&display_points);
- assert_eq!(
- previous_word_start(&snapshot, display_points[1]),
- display_points[0]
- );
- }
-
- assert("\n| |lorem", cx);
- assert(" |lorem|", cx);
- assert(" |lor|em", cx);
- assert("\nlorem\n| |ipsum", cx);
- assert("\n\n|\n|", cx);
- assert(" |lorem |ipsum", cx);
- assert("lorem|-|ipsum", cx);
- assert("lorem|-#$@|ipsum", cx);
- assert("|lorem_|ipsum", cx);
- }
-
- #[gpui::test]
- fn test_next_word_end(cx: &mut gpui::MutableAppContext) {
- fn assert(marked_text: &str, cx: &mut gpui::MutableAppContext) {
- let (snapshot, display_points) = marked_snapshot(marked_text, cx);
- assert_eq!(
- next_word_end(&snapshot, display_points[0]),
- display_points[1]
- );
- }
-
- assert("\n| lorem|", cx);
- assert(" |lorem|", cx);
- assert(" lor|em|", cx);
- assert(" lorem| |\nipsum\n", cx);
- assert("\n|\n|\n\n", cx);
- assert("lorem| ipsum| ", cx);
- assert("lorem|-|ipsum", cx);
- assert("lorem|#$@-|ipsum", cx);
- assert("lorem|_ipsum|", cx);
- }
-
// Returns a snapshot from text containing '|' character markers with the markers removed, and DisplayPoints for each one.
fn marked_snapshot(
text: &str,
@@ -368,139 +393,4 @@ mod tests {
(snapshot, marked_display_points)
}
-
- #[gpui::test]
- fn test_prev_next_word_boundary_multibyte(cx: &mut gpui::MutableAppContext) {
- let tab_size = 4;
- let family_id = cx.font_cache().load_family(&["Helvetica"]).unwrap();
- let font_id = cx
- .font_cache()
- .select_font(family_id, &Default::default())
- .unwrap();
- let font_size = 14.0;
-
- let buffer = MultiBuffer::build_simple("a bcΔ defγ hi—jk", cx);
- let display_map = cx
- .add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, 1, cx));
- let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
- assert_eq!(
- previous_word_start(&snapshot, DisplayPoint::new(0, 12)),
- DisplayPoint::new(0, 7)
- );
- assert_eq!(
- previous_word_start(&snapshot, DisplayPoint::new(0, 7)),
- DisplayPoint::new(0, 2)
- );
- assert_eq!(
- previous_word_start(&snapshot, DisplayPoint::new(0, 6)),
- DisplayPoint::new(0, 2)
- );
- assert_eq!(
- previous_word_start(&snapshot, DisplayPoint::new(0, 2)),
- DisplayPoint::new(0, 0)
- );
- assert_eq!(
- previous_word_start(&snapshot, DisplayPoint::new(0, 1)),
- DisplayPoint::new(0, 0)
- );
-
- assert_eq!(
- next_word_end(&snapshot, DisplayPoint::new(0, 0)),
- DisplayPoint::new(0, 1)
- );
- assert_eq!(
- next_word_end(&snapshot, DisplayPoint::new(0, 1)),
- DisplayPoint::new(0, 6)
- );
- assert_eq!(
- next_word_end(&snapshot, DisplayPoint::new(0, 2)),
- DisplayPoint::new(0, 6)
- );
- assert_eq!(
- next_word_end(&snapshot, DisplayPoint::new(0, 6)),
- DisplayPoint::new(0, 12)
- );
- assert_eq!(
- next_word_end(&snapshot, DisplayPoint::new(0, 7)),
- DisplayPoint::new(0, 12)
- );
- }
-
- #[gpui::test]
- fn test_surrounding_word(cx: &mut gpui::MutableAppContext) {
- let tab_size = 4;
- let family_id = cx.font_cache().load_family(&["Helvetica"]).unwrap();
- let font_id = cx
- .font_cache()
- .select_font(family_id, &Default::default())
- .unwrap();
- let font_size = 14.0;
- let buffer = MultiBuffer::build_simple("lorem ipsum dolor\n sit\n\n\n\n", cx);
- let display_map = cx
- .add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, 1, cx));
- let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
-
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 0)),
- DisplayPoint::new(0, 0)..DisplayPoint::new(0, 5),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 2)),
- DisplayPoint::new(0, 0)..DisplayPoint::new(0, 5),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 5)),
- DisplayPoint::new(0, 0)..DisplayPoint::new(0, 5),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 6)),
- DisplayPoint::new(0, 6)..DisplayPoint::new(0, 11),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 7)),
- DisplayPoint::new(0, 6)..DisplayPoint::new(0, 11),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 11)),
- DisplayPoint::new(0, 6)..DisplayPoint::new(0, 11),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 13)),
- DisplayPoint::new(0, 11)..DisplayPoint::new(0, 14),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 14)),
- DisplayPoint::new(0, 14)..DisplayPoint::new(0, 19),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 17)),
- DisplayPoint::new(0, 14)..DisplayPoint::new(0, 19),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(0, 19)),
- DisplayPoint::new(0, 14)..DisplayPoint::new(0, 19),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(1, 0)),
- DisplayPoint::new(1, 0)..DisplayPoint::new(1, 4),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(1, 1)),
- DisplayPoint::new(1, 0)..DisplayPoint::new(1, 4),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(1, 6)),
- DisplayPoint::new(1, 4)..DisplayPoint::new(1, 7),
- );
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(1, 7)),
- DisplayPoint::new(1, 4)..DisplayPoint::new(1, 7),
- );
-
- // Don't consider runs of multiple newlines to be a "word"
- assert_eq!(
- surrounding_word(&snapshot, DisplayPoint::new(3, 0)),
- DisplayPoint::new(3, 0)..DisplayPoint::new(3, 0),
- );
- }
}