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 | export component TestCase { |
6 | width: 100phx; |
7 | height: 100phx; |
8 | |
9 | ti := TextInput {} |
10 | |
11 | in-out property<string> test_text <=> ti.text; |
12 | |
13 | callback do_select(); |
14 | do_select => { |
15 | ti.select_all(); |
16 | } |
17 | |
18 | callback do_copy(); |
19 | do_copy => { |
20 | ti.copy(); |
21 | } |
22 | |
23 | callback do_cut(); |
24 | do_cut => { |
25 | ti.cut(); |
26 | } |
27 | |
28 | callback do_paste(); |
29 | do_paste => { |
30 | ti.paste(); |
31 | } |
32 | |
33 | callback do_deselect(); |
34 | do_deselect => { |
35 | ti.clear-selection(); |
36 | } |
37 | |
38 | callback set_selection_offsets(int, int); |
39 | set_selection_offsets(start, end) => { |
40 | ti.set-selection-offsets(start, end); |
41 | } |
42 | |
43 | out property<bool> has_selection: ti.cursor_position_byte_offset != ti.anchor_position_byte_offset; |
44 | out property<int> test_cursor_pos: ti.cursor_position_byte_offset; |
45 | out property<int> test_anchor_pos: ti.anchor_position_byte_offset; |
46 | } |
47 | |
48 | /* |
49 | ```rust |
50 | let instance = TestCase::new().unwrap(); |
51 | instance.set_test_text("Hello World".into()); |
52 | assert!(!instance.get_has_selection()); |
53 | instance.invoke_do_select(); |
54 | assert!(instance.get_has_selection()); |
55 | |
56 | instance.invoke_do_copy(); |
57 | assert!(instance.get_has_selection()); |
58 | assert_eq!(instance.get_test_text(), "Hello World"); |
59 | instance.invoke_do_cut(); |
60 | assert!(!instance.get_has_selection()); |
61 | assert_eq!(instance.get_test_text(), ""); |
62 | |
63 | instance.invoke_do_paste(); |
64 | assert_eq!(instance.get_test_text(), "Hello World"); |
65 | instance.invoke_do_select(); |
66 | assert!(instance.get_has_selection()); |
67 | instance.invoke_do_deselect(); |
68 | assert!(!instance.get_has_selection()); |
69 | |
70 | instance.set_test_text("Hello".into()); |
71 | instance.invoke_set_selection_offsets(-3, 10); |
72 | assert_eq!(instance.get_test_anchor_pos(), 0); |
73 | assert_eq!(instance.get_test_cursor_pos(), 5); |
74 | |
75 | instance.set_test_text("🥳😎".into()); |
76 | instance.invoke_set_selection_offsets(0, 3); |
77 | assert_eq!(instance.get_test_anchor_pos(), 0); |
78 | assert_eq!(instance.get_test_cursor_pos(), 4); |
79 | |
80 | ``` |
81 | */ |
82 | |
83 | /* |
84 | ```cpp |
85 | auto handle = TestCase::create(); |
86 | const TestCase &instance = *handle; |
87 | instance.set_test_text("Hello World"); |
88 | assert(!instance.get_has_selection()); |
89 | instance.invoke_do_select(); |
90 | assert(instance.get_has_selection()); |
91 | |
92 | instance.invoke_do_copy(); |
93 | assert(instance.get_has_selection()); |
94 | assert_eq(instance.get_test_text(), "Hello World"); |
95 | instance.invoke_do_cut(); |
96 | assert(!instance.get_has_selection()); |
97 | assert_eq(instance.get_test_text(), ""); |
98 | |
99 | instance.invoke_do_paste(); |
100 | assert_eq(instance.get_test_text(), "Hello World"); |
101 | instance.invoke_do_select(); |
102 | assert(instance.get_has_selection()); |
103 | instance.invoke_do_deselect(); |
104 | assert(!instance.get_has_selection()); |
105 | |
106 | instance.set_test_text("Hello"); |
107 | instance.invoke_set_selection_offsets(-3, 10); |
108 | assert_eq(instance.get_test_anchor_pos(), 0); |
109 | assert_eq(instance.get_test_cursor_pos(), 5); |
110 | |
111 | instance.set_test_text("🥳😎"); |
112 | instance.invoke_set_selection_offsets(0, 3); |
113 | assert_eq(instance.get_test_anchor_pos(), 0); |
114 | assert_eq(instance.get_test_cursor_pos(), 4); |
115 | |
116 | ``` |
117 | */ |
118 | |
119 | /* |
120 | ```js |
121 | var instance = new slint.TestCase({}); |
122 | instance.test_text = "Hello World"; |
123 | assert(!instance.has_selection); |
124 | instance.do_select(); |
125 | assert(instance.has_selection); |
126 | |
127 | instance.do_copy(); |
128 | assert(instance.has_selection); |
129 | assert.equal(instance.test_text, "Hello World"); |
130 | instance.do_cut(); |
131 | assert(!instance.has_selection); |
132 | assert.equal(instance.test_text, ""); |
133 | |
134 | instance.do_paste(); |
135 | assert.equal(instance.test_text, "Hello World"); |
136 | instance.do_select(); |
137 | assert(instance.has_selection); |
138 | instance.do_deselect(); |
139 | assert(!instance.has_selection); |
140 | |
141 | instance.test_text = "Hello"; |
142 | instance.set_selection_offsets(-3, 10); |
143 | assert.equal(instance.test_anchor_pos, 0); |
144 | assert.equal(instance.test_cursor_pos, 5); |
145 | |
146 | instance.test_text = "🥳😎"; |
147 | instance.set_selection_offsets(0, 3); |
148 | assert.equal(instance.test_anchor_pos, 0); |
149 | assert.equal(instance.test_cursor_pos, 4); |
150 | |
151 | ``` |
152 | */ |
153 | } |
154 | |
155 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
156 | use i_slint_backend_testing as slint_testing; |
157 | slint_testing::init(); |
158 | let instance = TestCase::new().unwrap(); |
159 | instance.set_test_text("Hello World" .into()); |
160 | assert!(!instance.get_has_selection()); |
161 | instance.invoke_do_select(); |
162 | assert!(instance.get_has_selection()); |
163 | |
164 | instance.invoke_do_copy(); |
165 | assert!(instance.get_has_selection()); |
166 | assert_eq!(instance.get_test_text(), "Hello World" ); |
167 | instance.invoke_do_cut(); |
168 | assert!(!instance.get_has_selection()); |
169 | assert_eq!(instance.get_test_text(), "" ); |
170 | |
171 | instance.invoke_do_paste(); |
172 | assert_eq!(instance.get_test_text(), "Hello World" ); |
173 | instance.invoke_do_select(); |
174 | assert!(instance.get_has_selection()); |
175 | instance.invoke_do_deselect(); |
176 | assert!(!instance.get_has_selection()); |
177 | |
178 | instance.set_test_text("Hello" .into()); |
179 | instance.invoke_set_selection_offsets(-3, 10); |
180 | assert_eq!(instance.get_test_anchor_pos(), 0); |
181 | assert_eq!(instance.get_test_cursor_pos(), 5); |
182 | |
183 | instance.set_test_text("🥳😎" .into()); |
184 | instance.invoke_set_selection_offsets(0, 3); |
185 | assert_eq!(instance.get_test_anchor_pos(), 0); |
186 | assert_eq!(instance.get_test_cursor_pos(), 4); |
187 | |
188 | Ok(()) |
189 | } |