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}';
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, "Test");
25assert_eq!(instance.get_test_text(), "Test");
26assert!(!instance.get_has_selection());
27
28slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true);
29slint_testing::send_keyboard_string_sequence(&instance, "a");
30slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), false);
31slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), true);
32slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string());
33slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string());
34slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), false);
35slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true);
36slint_testing::send_keyboard_string_sequence(&instance, "x");
37slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), false);
38assert!(!instance.get_has_selection());
39assert_eq!(instance.get_test_text(), "st");
40assert_eq!(instance.get_test_cursor_pos(), 0);
41```
42*/
43}
44
45#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
46 use i_slint_backend_testing as slint_testing;
47 slint_testing::init();
48
49 const LEFT_CODE: char = '\u{F702}';
50
51 let instance = TestCase::new().unwrap();
52 slint_testing::send_mouse_click(&instance, 50., 50.);
53 assert!(instance.get_input_focused());
54 assert_eq!(instance.get_test_text(), "");
55 slint_testing::send_keyboard_string_sequence(&instance, "Test");
56 assert_eq!(instance.get_test_text(), "Test");
57 assert!(!instance.get_has_selection());
58
59 slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true);
60 slint_testing::send_keyboard_string_sequence(&instance, "a");
61 slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), false);
62 slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), true);
63 slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string());
64 slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string());
65 slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Shift.into(), false);
66 slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), true);
67 slint_testing::send_keyboard_string_sequence(&instance, "x");
68 slint_testing::send_keyboard_char(&instance, slint::private_unstable_api::re_exports::Key::Control.into(), false);
69 assert!(!instance.get_has_selection());
70 assert_eq!(instance.get_test_text(), "st");
71 assert_eq!(instance.get_test_cursor_pos(), 0);
72 Ok(())
73}