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 := 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 |
18 | use slint::platform::Key; |
19 | |
20 | let instance = TestCase::new().unwrap(); |
21 | slint_testing::send_mouse_click(&instance, 5., 5.); |
22 | assert!(instance.get_input_focused()); |
23 | assert!(instance.get_text().is_empty()); |
24 | |
25 | // accept characters as valid decimal only |
26 | slint_testing::send_keyboard_char(&instance, 'a', true); |
27 | assert!(instance.get_text().is_empty()); |
28 | slint_testing::send_keyboard_char(&instance, Key::Shift.into(), true); |
29 | assert!(instance.get_text().is_empty()); |
30 | slint_testing::send_keyboard_char(&instance, '-', true); |
31 | assert_eq!(instance.get_text(), "-"); |
32 | slint_testing::send_keyboard_char(&instance, '1', true); |
33 | assert_eq!(instance.get_text(), "-1"); |
34 | slint_testing::send_keyboard_char(&instance, '.', true); |
35 | assert_eq!(instance.get_text(), "-1."); |
36 | slint_testing::send_keyboard_char(&instance, '0', true); |
37 | assert_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 | } |