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 := Window {
6 width: 100phx;
7 height: 100phx;
8 VerticalLayout {
9 padding: 0;
10 spacing: 0;
11 ti := TextInput { }
12 Rectangle { }
13 }
14
15 property <string> text <=> ti.text;
16 property <bool> input_focused: ti.has_focus;
17 property<int> test_cursor_pos: ti.cursor_position_byte_offset;
18}
19
20/*
21```rust
22
23const LEFT_CODE: char = '\u{F702}';
24
25let instance = TestCase::new().unwrap();
26slint_testing::send_mouse_click(&instance, 5., 5.);
27assert!(instance.get_input_focused());
28assert_eq!(instance.get_text(), "");
29slint_testing::send_keyboard_string_sequence(&instance, "Hallo");
30assert_eq!(instance.get_text(), "Hallo");
31instance.set_text("Yo".into());
32assert_eq!(instance.get_text(), "Yo");
33slint_testing::send_keyboard_string_sequence(&instance, "Hello Again");
34assert_eq!(instance.get_text(), "YoHello Again");
35instance.set_text("Yo".into());
36// Issue #331: assert_eq!(instance.get_test_cursor_pos(), 2);
37slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string());
38assert_eq!(instance.get_test_cursor_pos(), 1);
39```
40*/
41}
42
43#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
44 use i_slint_backend_testing as slint_testing;
45 slint_testing::init();
46
47 const LEFT_CODE: char = '\u{F702}';
48
49 let instance = TestCase::new().unwrap();
50 slint_testing::send_mouse_click(&instance, x:5., y:5.);
51 assert!(instance.get_input_focused());
52 assert_eq!(instance.get_text(), "");
53 slint_testing::send_keyboard_string_sequence(&instance, sequence:"Hallo");
54 assert_eq!(instance.get_text(), "Hallo");
55 instance.set_text("Yo".into());
56 assert_eq!(instance.get_text(), "Yo");
57 slint_testing::send_keyboard_string_sequence(&instance, sequence:"Hello Again");
58 assert_eq!(instance.get_text(), "YoHello Again");
59 instance.set_text("Yo".into());
60 // Issue #331: assert_eq!(instance.get_test_cursor_pos(), 2);
61 slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string());
62 assert_eq!(instance.get_test_cursor_pos(), 1);
63 Ok(())
64}