mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Create a helper function to create TextInput structs in its unit test.
This commit is contained in:
parent
b098339f92
commit
dab3926622
1 changed files with 21 additions and 21 deletions
|
@ -16,9 +16,13 @@ use script::clipboard_provider::DummyClipboardContext;
|
||||||
use script::textinput::{TextInput, Selection, Lines, Direction};
|
use script::textinput::{TextInput, Selection, Lines, Direction};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
|
||||||
|
fn text_input(lines: Lines, s: &str) -> TextInput<DummyClipboardContext> {
|
||||||
|
TextInput::new(lines, s.to_owned(), DummyClipboardContext::new(""))
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_delete_char() {
|
fn test_textinput_delete_char() {
|
||||||
let mut textinput = TextInput::new(Lines::Single, "abcdefg".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Single, "abcdefg");
|
||||||
textinput.adjust_horizontal(2, Selection::NotSelected);
|
textinput.adjust_horizontal(2, Selection::NotSelected);
|
||||||
textinput.delete_char(Direction::Backward);
|
textinput.delete_char(Direction::Backward);
|
||||||
assert_eq!(textinput.get_content(), "acdefg");
|
assert_eq!(textinput.get_content(), "acdefg");
|
||||||
|
@ -30,7 +34,7 @@ fn test_textinput_delete_char() {
|
||||||
textinput.delete_char(Direction::Forward);
|
textinput.delete_char(Direction::Forward);
|
||||||
assert_eq!(textinput.get_content(), "afg");
|
assert_eq!(textinput.get_content(), "afg");
|
||||||
|
|
||||||
let mut textinput = TextInput::new(Lines::Single, "a🌠b".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Single, "a🌠b");
|
||||||
// Same as "Right" key
|
// Same as "Right" key
|
||||||
textinput.adjust_horizontal_by_one(Direction::Forward, Selection::NotSelected);
|
textinput.adjust_horizontal_by_one(Direction::Forward, Selection::NotSelected);
|
||||||
textinput.delete_char(Direction::Forward);
|
textinput.delete_char(Direction::Forward);
|
||||||
|
@ -40,7 +44,7 @@ fn test_textinput_delete_char() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_insert_char() {
|
fn test_textinput_insert_char() {
|
||||||
let mut textinput = TextInput::new(Lines::Single, "abcdefg".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Single, "abcdefg");
|
||||||
textinput.adjust_horizontal(2, Selection::NotSelected);
|
textinput.adjust_horizontal(2, Selection::NotSelected);
|
||||||
textinput.insert_char('a');
|
textinput.insert_char('a');
|
||||||
assert_eq!(textinput.get_content(), "abacdefg");
|
assert_eq!(textinput.get_content(), "abacdefg");
|
||||||
|
@ -49,7 +53,7 @@ fn test_textinput_insert_char() {
|
||||||
textinput.insert_char('b');
|
textinput.insert_char('b');
|
||||||
assert_eq!(textinput.get_content(), "ababefg");
|
assert_eq!(textinput.get_content(), "ababefg");
|
||||||
|
|
||||||
let mut textinput = TextInput::new(Lines::Single, "a🌠c".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Single, "a🌠c");
|
||||||
// Same as "Right" key
|
// Same as "Right" key
|
||||||
textinput.adjust_horizontal_by_one(Direction::Forward, Selection::NotSelected);
|
textinput.adjust_horizontal_by_one(Direction::Forward, Selection::NotSelected);
|
||||||
textinput.adjust_horizontal_by_one(Direction::Forward, Selection::NotSelected);
|
textinput.adjust_horizontal_by_one(Direction::Forward, Selection::NotSelected);
|
||||||
|
@ -60,7 +64,7 @@ fn test_textinput_insert_char() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_get_sorted_selection() {
|
fn test_textinput_get_sorted_selection() {
|
||||||
let mut textinput = TextInput::new(Lines::Single, "abcdefg".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Single, "abcdefg");
|
||||||
textinput.adjust_horizontal(2, Selection::NotSelected);
|
textinput.adjust_horizontal(2, Selection::NotSelected);
|
||||||
textinput.adjust_horizontal(2, Selection::Selected);
|
textinput.adjust_horizontal(2, Selection::Selected);
|
||||||
let (begin, end) = textinput.get_sorted_selection().unwrap();
|
let (begin, end) = textinput.get_sorted_selection().unwrap();
|
||||||
|
@ -77,7 +81,7 @@ fn test_textinput_get_sorted_selection() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_replace_selection() {
|
fn test_textinput_replace_selection() {
|
||||||
let mut textinput = TextInput::new(Lines::Single, "abcdefg".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Single, "abcdefg");
|
||||||
textinput.adjust_horizontal(2, Selection::NotSelected);
|
textinput.adjust_horizontal(2, Selection::NotSelected);
|
||||||
textinput.adjust_horizontal(2, Selection::Selected);
|
textinput.adjust_horizontal(2, Selection::Selected);
|
||||||
|
|
||||||
|
@ -87,7 +91,7 @@ fn test_textinput_replace_selection() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_current_line_length() {
|
fn test_textinput_current_line_length() {
|
||||||
let mut textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||||
assert_eq!(textinput.current_line_length(), 3);
|
assert_eq!(textinput.current_line_length(), 3);
|
||||||
|
|
||||||
textinput.adjust_vertical(1, Selection::NotSelected);
|
textinput.adjust_vertical(1, Selection::NotSelected);
|
||||||
|
@ -99,7 +103,7 @@ fn test_textinput_current_line_length() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_adjust_vertical() {
|
fn test_textinput_adjust_vertical() {
|
||||||
let mut textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||||
textinput.adjust_horizontal(3, Selection::NotSelected);
|
textinput.adjust_horizontal(3, Selection::NotSelected);
|
||||||
textinput.adjust_vertical(1, Selection::NotSelected);
|
textinput.adjust_vertical(1, Selection::NotSelected);
|
||||||
assert_eq!(textinput.edit_point.line, 1);
|
assert_eq!(textinput.edit_point.line, 1);
|
||||||
|
@ -116,7 +120,7 @@ fn test_textinput_adjust_vertical() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_adjust_horizontal() {
|
fn test_textinput_adjust_horizontal() {
|
||||||
let mut textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||||
textinput.adjust_horizontal(4, Selection::NotSelected);
|
textinput.adjust_horizontal(4, Selection::NotSelected);
|
||||||
assert_eq!(textinput.edit_point.line, 1);
|
assert_eq!(textinput.edit_point.line, 1);
|
||||||
assert_eq!(textinput.edit_point.index, 0);
|
assert_eq!(textinput.edit_point.index, 0);
|
||||||
|
@ -136,14 +140,12 @@ fn test_textinput_adjust_horizontal() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_handle_return() {
|
fn test_textinput_handle_return() {
|
||||||
let mut single_line_textinput = TextInput::new(
|
let mut single_line_textinput = text_input(Lines::Single, "abcdef");
|
||||||
Lines::Single, "abcdef".to_owned(), DummyClipboardContext::new(""));
|
|
||||||
single_line_textinput.adjust_horizontal(3, Selection::NotSelected);
|
single_line_textinput.adjust_horizontal(3, Selection::NotSelected);
|
||||||
single_line_textinput.handle_return();
|
single_line_textinput.handle_return();
|
||||||
assert_eq!(single_line_textinput.get_content(), "abcdef");
|
assert_eq!(single_line_textinput.get_content(), "abcdef");
|
||||||
|
|
||||||
let mut multi_line_textinput = TextInput::new(
|
let mut multi_line_textinput = text_input(Lines::Multiple, "abcdef");
|
||||||
Lines::Multiple, "abcdef".to_owned(), DummyClipboardContext::new(""));
|
|
||||||
multi_line_textinput.adjust_horizontal(3, Selection::NotSelected);
|
multi_line_textinput.adjust_horizontal(3, Selection::NotSelected);
|
||||||
multi_line_textinput.handle_return();
|
multi_line_textinput.handle_return();
|
||||||
assert_eq!(multi_line_textinput.get_content(), "abc\ndef");
|
assert_eq!(multi_line_textinput.get_content(), "abc\ndef");
|
||||||
|
@ -151,8 +153,7 @@ fn test_textinput_handle_return() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_select_all() {
|
fn test_textinput_select_all() {
|
||||||
let mut textinput = TextInput::new(
|
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||||
Lines::Multiple, "abc\nde\nf".to_owned(), DummyClipboardContext::new(""));
|
|
||||||
assert_eq!(textinput.edit_point.line, 0);
|
assert_eq!(textinput.edit_point.line, 0);
|
||||||
assert_eq!(textinput.edit_point.index, 0);
|
assert_eq!(textinput.edit_point.index, 0);
|
||||||
|
|
||||||
|
@ -163,17 +164,16 @@ fn test_textinput_select_all() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_get_content() {
|
fn test_textinput_get_content() {
|
||||||
let single_line_textinput = TextInput::new(Lines::Single, "abcdefg".to_owned(), DummyClipboardContext::new(""));
|
let single_line_textinput = text_input(Lines::Single, "abcdefg");
|
||||||
assert_eq!(single_line_textinput.get_content(), "abcdefg");
|
assert_eq!(single_line_textinput.get_content(), "abcdefg");
|
||||||
|
|
||||||
let multi_line_textinput = TextInput::new(
|
let multi_line_textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||||
Lines::Multiple, "abc\nde\nf".to_owned(), DummyClipboardContext::new(""));
|
|
||||||
assert_eq!(multi_line_textinput.get_content(), "abc\nde\nf");
|
assert_eq!(multi_line_textinput.get_content(), "abc\nde\nf");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_set_content() {
|
fn test_textinput_set_content() {
|
||||||
let mut textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||||
assert_eq!(textinput.get_content(), "abc\nde\nf");
|
assert_eq!(textinput.get_content(), "abc\nde\nf");
|
||||||
|
|
||||||
textinput.set_content("abc\nf".to_owned());
|
textinput.set_content("abc\nf".to_owned());
|
||||||
|
@ -206,7 +206,7 @@ fn test_clipboard_paste() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_textinput_cursor_position_correct_after_clearing_selection() {
|
fn test_textinput_cursor_position_correct_after_clearing_selection() {
|
||||||
let mut textinput = TextInput::new(Lines::Single, "abcdef".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Single, "abcdef");
|
||||||
|
|
||||||
// Single line - Forward
|
// Single line - Forward
|
||||||
textinput.adjust_horizontal(3, Selection::Selected);
|
textinput.adjust_horizontal(3, Selection::Selected);
|
||||||
|
@ -230,7 +230,7 @@ fn test_textinput_cursor_position_correct_after_clearing_selection() {
|
||||||
assert_eq!(textinput.edit_point.index, 0);
|
assert_eq!(textinput.edit_point.index, 0);
|
||||||
|
|
||||||
|
|
||||||
let mut textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned(), DummyClipboardContext::new(""));
|
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||||
|
|
||||||
// Multiline - Forward
|
// Multiline - Forward
|
||||||
textinput.adjust_horizontal(4, Selection::Selected);
|
textinput.adjust_horizontal(4, Selection::Selected);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue