1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4TestCase := TextInput {
5 width: 100phx;
6 height: 100phx;
7 property<string> test_text: self.text;
8 property<int> test_cursor_pos: self.cursor_position_byte_offset;
9 property<int> test_anchor_pos: self.anchor_position_byte_offset;
10 property<bool> has_selection: self.test_cursor_pos != self.test_anchor_pos;
11 property<bool> input_focused: self.has_focus;
12}
13
14/*
15```rust
16
17const LEFT_CODE: char = '\u{F702}';
18const BACK_CODE: char = '\u{0008}'; // backspace \b
19
20let instance = TestCase::new().unwrap();
21slint_testing::send_mouse_click(&instance, 50., 50.);
22assert!(instance.get_input_focused());
23assert_eq!(instance.get_test_text(), "");
24slint_testing::send_keyboard_string_sequence(&instance, "e\u{0301}");
25assert_eq!(instance.get_test_text(), "e\u{0301}");
26assert!(!instance.get_has_selection());
27
28// Test that selecting the grapheme works
29slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), true);
30slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string());
31slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), false);
32assert!(instance.get_has_selection());
33slint_testing::send_keyboard_string_sequence(&instance, &BACK_CODE.to_string());
34
35assert_eq!(instance.get_test_text(), "");
36
37slint_testing::send_keyboard_string_sequence(&instance, "e\u{0301}");
38
39// Test that backspace does not operate on the grapheme and just removes the
40// diacritic.
41slint_testing::send_keyboard_string_sequence(&instance, &BACK_CODE.to_string());
42assert_eq!(instance.get_test_cursor_pos(), 1);
43assert_eq!(instance.get_test_text(), "e");
44```
45*/
46