#[allow(unused)]
use super::super::*;
#[test]
fn test_insert_basic_emoji() {
let mut editor = Editor::new("test", vec![]);
editor.insert_char('π');
assert_eq!(editor.get_buffer().get_line(0), Some("π".to_string()));
assert_eq!(editor.cursor_position(), CursorPosition::new(0, 1));
}
#[test]
fn test_insert_multiple_emoji() {
let mut editor = Editor::new("test", vec![]);
editor.insert_char('π');
editor.insert_char('π');
editor.insert_char('π');
assert_eq!(editor.get_buffer().get_line(0), Some("πππ".to_string()));
assert_eq!(editor.cursor_position(), CursorPosition::new(0, 3));
}
#[test]
fn test_emoji_with_skin_tone_modifier() {
let mut editor = Editor::new("test", vec![]);
let emoji_with_modifier = "ππ½";
for ch in emoji_with_modifier.chars() {
editor.insert_char(ch);
}
assert_eq!(
editor.get_buffer().get_line(0),
Some(emoji_with_modifier.to_string())
);
}
#[test]
fn test_emoji_zwj_sequence() {
let mut editor = Editor::new("test", vec![]);
let family_emoji = "π¨βπ©βπ¦";
for ch in family_emoji.chars() {
editor.insert_char(ch);
}
assert_eq!(
editor.get_buffer().get_line(0),
Some(family_emoji.to_string())
);
}
#[test]
fn test_delete_emoji() {
let mut editor = Editor::new("test", vec!["Hello π World".to_string()]);
editor.set_cursor_position(CursorPosition::new(0, 8));
editor.backspace();
assert_eq!(
editor.get_buffer().get_line(0),
Some("Hello πWorld".to_string())
);
assert_eq!(editor.cursor_position(), CursorPosition::new(0, 7));
editor.set_cursor_position(CursorPosition::new(0, 7));
editor.backspace();
assert_eq!(
editor.get_buffer().get_line(0),
Some("Hello World".to_string())
);
assert_eq!(editor.cursor_position(), CursorPosition::new(0, 6));
}
#[test]
fn test_cursor_movement_over_emoji() {
let mut editor = Editor::new("test", vec!["AπB".to_string()]);
editor.set_cursor_position(CursorPosition::new(0, 0));
editor.move_right(false);
assert_eq!(
editor.cursor_position(),
CursorPosition::new(0, 1),
"Should be after 'A'"
);
editor.move_right(false);
assert_eq!(
editor.cursor_position(),
CursorPosition::new(0, 2),
"Should be after emoji"
);
editor.move_right(false);
assert_eq!(
editor.cursor_position(),
CursorPosition::new(0, 3),
"Should be after 'B'"
);
let mut editor2 = Editor::new("test", vec!["Aππ½B".to_string()]);
editor2.set_cursor_position(CursorPosition::new(0, 0));
editor2.move_right(false);
assert_eq!(
editor2.cursor_position(),
CursorPosition::new(0, 1),
"Should be after 'A'"
);
editor2.move_right(false);
assert_eq!(
editor2.cursor_position(),
CursorPosition::new(0, 2),
"Should be after waving hand emoji (before skin tone modifier)"
);
editor2.move_right(false);
assert_eq!(
editor2.cursor_position(),
CursorPosition::new(0, 3),
"Should be after skin tone modifier"
);
editor2.move_right(false);
assert_eq!(
editor2.cursor_position(),
CursorPosition::new(0, 4),
"Should be after 'B'"
);
let mut editor3 = Editor::new("test", vec!["Aπ¨βπ©βπ¦B".to_string()]);
editor3.set_cursor_position(CursorPosition::new(0, 0));
editor3.move_right(false);
assert_eq!(
editor3.cursor_position(),
CursorPosition::new(0, 1),
"Should be after 'A'"
);
editor3.move_right(false);
assert_eq!(
editor3.cursor_position(),
CursorPosition::new(0, 2),
"Should be after man emoji"
);
editor3.move_right(false); assert_eq!(editor3.cursor_position(), CursorPosition::new(0, 3));
editor3.move_right(false); assert_eq!(editor3.cursor_position(), CursorPosition::new(0, 4));
editor3.move_right(false); assert_eq!(editor3.cursor_position(), CursorPosition::new(0, 5));
editor3.move_right(false); assert_eq!(editor3.cursor_position(), CursorPosition::new(0, 6));
editor3.move_right(false);
assert_eq!(
editor3.cursor_position(),
CursorPosition::new(0, 7),
"Should be after 'B'"
);
let mut editor4 = Editor::new("test", vec!["Ae\u{0301}B".to_string()]); editor4.set_cursor_position(CursorPosition::new(0, 0));
editor4.move_right(false);
assert_eq!(
editor4.cursor_position(),
CursorPosition::new(0, 1),
"Should be after 'A'"
);
editor4.move_right(false);
assert_eq!(
editor4.cursor_position(),
CursorPosition::new(0, 2),
"Should be after 'e'"
);
editor4.move_right(false);
assert_eq!(
editor4.cursor_position(),
CursorPosition::new(0, 3),
"Should be after combining accent"
);
editor4.move_right(false);
assert_eq!(
editor4.cursor_position(),
CursorPosition::new(0, 4),
"Should be after 'B'"
);
}
#[test]
fn test_mixed_ascii_and_emoji() {
let mut editor = Editor::new("test", vec![]);
editor.insert_char('H');
editor.insert_char('i');
editor.insert_char('π');
editor.insert_char('!');
assert_eq!(editor.get_buffer().get_line(0), Some("Hiπ!".to_string()));
assert_eq!(editor.cursor_position(), CursorPosition::new(0, 4));
}