aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/script/textinput.rs
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2016-04-01 14:49:14 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2016-04-02 07:33:53 -0700
commitdeca979967a61e36b7ff8b5799e413b80fd8524c (patch)
tree7a29ae4e81a265fab173119036a60ee0fb95e760 /tests/unit/script/textinput.rs
parent29fb3f11502e1d69ec1f01e5da87abf212a16264 (diff)
downloadservo-deca979967a61e36b7ff8b5799e413b80fd8524c.tar.gz
servo-deca979967a61e36b7ff8b5799e413b80fd8524c.zip
TextInput::max_length should be in code units, not bytes
Diffstat (limited to 'tests/unit/script/textinput.rs')
-rw-r--r--tests/unit/script/textinput.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/unit/script/textinput.rs b/tests/unit/script/textinput.rs
index f5ee2feeb35..318612e64af 100644
--- a/tests/unit/script/textinput.rs
+++ b/tests/unit/script/textinput.rs
@@ -118,6 +118,55 @@ fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_
}
#[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(
Lines::Single,