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 ti := TextInput {
9 input-type: decimal;
10 }
11
12 property <bool> input_focused: ti.has_focus;
13 property <string> text <=> ti.text;
14}
15
16/*
17```rust
18use slint::platform::Key;
19
20let instance = TestCase::new().unwrap();
21slint_testing::send_mouse_click(&instance, 5., 5.);
22assert!(instance.get_input_focused());
23assert!(instance.get_text().is_empty());
24
25// accept characters as valid decimal only
26slint_testing::send_keyboard_char(&instance, 'a', true);
27assert!(instance.get_text().is_empty());
28slint_testing::send_keyboard_char(&instance, Key::Shift.into(), true);
29assert!(instance.get_text().is_empty());
30slint_testing::send_keyboard_char(&instance, '-', true);
31assert_eq!(instance.get_text(), "-");
32slint_testing::send_keyboard_char(&instance, '1', true);
33assert_eq!(instance.get_text(), "-1");
34slint_testing::send_keyboard_char(&instance, '.', true);
35assert_eq!(instance.get_text(), "-1.");
36slint_testing::send_keyboard_char(&instance, '0', true);
37assert_eq!(instance.get_text(), "-1.0");
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 use slint::platform::Key;
46
47 let instance = TestCase::new().unwrap();
48 slint_testing::send_mouse_click(&instance, 5., 5.);
49 assert!(instance.get_input_focused());
50 assert!(instance.get_text().is_empty());
51
52 // accept characters as valid decimal only
53 slint_testing::send_keyboard_char(&instance, 'a', true);
54 assert!(instance.get_text().is_empty());
55 slint_testing::send_keyboard_char(&instance, Key::Shift.into(), true);
56 assert!(instance.get_text().is_empty());
57 slint_testing::send_keyboard_char(&instance, '-', true);
58 assert_eq!(instance.get_text(), "-");
59 slint_testing::send_keyboard_char(&instance, '1', true);
60 assert_eq!(instance.get_text(), "-1");
61 slint_testing::send_keyboard_char(&instance, '.', true);
62 assert_eq!(instance.get_text(), "-1.");
63 slint_testing::send_keyboard_char(&instance, '0', true);
64 assert_eq!(instance.get_text(), "-1.0");
65 Ok(())
66}