1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/text"# ] |
2 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
3 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
4 | |
5 | TestCase := TextInput { |
6 | width: 100phx; |
7 | height: 100phx; |
8 | property<string> test_text: self.text; |
9 | property<int> test_cursor_pos: self.cursor_position_byte_offset; |
10 | property<int> test_anchor_pos: self.anchor_position_byte_offset; |
11 | property<bool> has_selection: self.test_cursor_pos != self.test_anchor_pos; |
12 | property<bool> input_focused: self.has_focus; |
13 | } |
14 | |
15 | /* |
16 | ```rust |
17 | |
18 | const LEFT_CODE: char = '\u{F702}'; |
19 | const BACK_CODE: char = '\u{0008}'; // backspace \b |
20 | |
21 | let instance = TestCase::new().unwrap(); |
22 | slint_testing::send_mouse_click(&instance, 50., 50.); |
23 | assert!(instance.get_input_focused()); |
24 | assert_eq!(instance.get_test_text(), ""); |
25 | slint_testing::send_keyboard_string_sequence(&instance, "😍"); |
26 | assert_eq!(instance.get_test_text(), "😍"); |
27 | assert!(!instance.get_has_selection()); |
28 | |
29 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), true); |
30 | slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string()); |
31 | assert!(instance.get_has_selection()); |
32 | assert_eq!(instance.get_test_cursor_pos(), 0); |
33 | assert_eq!(instance.get_test_anchor_pos(), 4); |
34 | slint_testing::send_keyboard_string_sequence(&instance, &BACK_CODE.to_string()); |
35 | assert!(!instance.get_has_selection()); |
36 | |
37 | assert_eq!(instance.get_test_text(), ""); |
38 | ``` |
39 | */ |
40 | } |
41 | |
42 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
43 | use i_slint_backend_testing as slint_testing; |
44 | slint_testing::init(); |
45 | |
46 | const LEFT_CODE: char = ' \u{F702}' ; |
47 | const BACK_CODE: char = ' \u{0008}' ; // backspace \b |
48 | |
49 | let instance = TestCase::new().unwrap(); |
50 | slint_testing::send_mouse_click(&instance, 50., 50.); |
51 | assert!(instance.get_input_focused()); |
52 | assert_eq!(instance.get_test_text(), "" ); |
53 | slint_testing::send_keyboard_string_sequence(&instance, "😍" ); |
54 | assert_eq!(instance.get_test_text(), "😍" ); |
55 | assert!(!instance.get_has_selection()); |
56 | |
57 | slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), true); |
58 | slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string()); |
59 | assert!(instance.get_has_selection()); |
60 | assert_eq!(instance.get_test_cursor_pos(), 0); |
61 | assert_eq!(instance.get_test_anchor_pos(), 4); |
62 | slint_testing::send_keyboard_string_sequence(&instance, &BACK_CODE.to_string()); |
63 | assert!(!instance.get_has_selection()); |
64 | |
65 | assert_eq!(instance.get_test_text(), "" ); |
66 | Ok(()) |
67 | } |