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
5TestCase := 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
18const LEFT_CODE: char = '\u{F702}';
19const BACK_CODE: char = '\u{0008}'; // backspace \b
20
21let instance = TestCase::new().unwrap();
22slint_testing::send_mouse_click(&instance, 50., 50.);
23assert!(instance.get_input_focused());
24assert_eq!(instance.get_test_text(), "");
25slint_testing::send_keyboard_string_sequence(&instance, "😍");
26assert_eq!(instance.get_test_text(), "😍");
27assert!(!instance.get_has_selection());
28
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());
31assert!(instance.get_has_selection());
32assert_eq!(instance.get_test_cursor_pos(), 0);
33assert_eq!(instance.get_test_anchor_pos(), 4);
34slint_testing::send_keyboard_string_sequence(&instance, &BACK_CODE.to_string());
35assert!(!instance.get_has_selection());
36
37assert_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}