mirror of
https://github.com/servo/servo.git
synced 2025-06-18 22:34:30 +01:00
TextInput::max_length should be in code units, not bytes
This commit is contained in:
parent
29fb3f1150
commit
deca979967
3 changed files with 120 additions and 30 deletions
|
@ -117,6 +117,55 @@ fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_
|
|||
assert_eq!(textinput.get_content(), "atooe");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_line_textinput_with_max_length_multibyte() {
|
||||
let mut textinput = TextInput::new(
|
||||
Lines::Single,
|
||||
DOMString::from(""),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(2)
|
||||
);
|
||||
|
||||
textinput.insert_char('á');
|
||||
assert_eq!(textinput.get_content(), "á");
|
||||
textinput.insert_char('é');
|
||||
assert_eq!(textinput.get_content(), "áé");
|
||||
textinput.insert_char('i');
|
||||
assert_eq!(textinput.get_content(), "áé");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_line_textinput_with_max_length_multi_code_unit() {
|
||||
let mut textinput = TextInput::new(
|
||||
Lines::Single,
|
||||
DOMString::from(""),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(3)
|
||||
);
|
||||
|
||||
textinput.insert_char('\u{10437}');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}");
|
||||
textinput.insert_char('\u{10437}');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}");
|
||||
textinput.insert_char('x');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}x");
|
||||
textinput.insert_char('x');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}x");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_line_textinput_with_max_length_inside_char() {
|
||||
let mut textinput = TextInput::new(
|
||||
Lines::Single,
|
||||
DOMString::from("\u{10437}"),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(1)
|
||||
);
|
||||
|
||||
textinput.insert_char('x');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_after_max_length_is_reached() {
|
||||
let mut textinput = TextInput::new(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue