1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/expr"# ] |
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 := Rectangle { |
6 | property<int> a; |
7 | property<int> t1: 4 + 3 * 2 + 2 - 50 - 2; |
8 | property<int> t2: 500 / 2 * 30 - 1; |
9 | property<int> t3: a - (3 + ++2 * (a + 2)); |
10 | property<int> t4: 3 + - +5 - 8 - -9 * --- 120; |
11 | |
12 | property <length> len: 50px / 2; |
13 | |
14 | callback foo; |
15 | foo => { |
16 | a += +8; |
17 | a *= 10; |
18 | a /= 2; |
19 | a -= 3; |
20 | |
21 | len += 1px; |
22 | len /= 2; |
23 | len -= 3px; |
24 | len *= 3; |
25 | } |
26 | } |
27 | /* |
28 | ```cpp |
29 | auto handle = TestCase::create(); |
30 | const TestCase &instance = *handle; |
31 | assert_eq(instance.get_t1(), 4 + 3 * 2 + 2 - 50 - 2); |
32 | assert_eq(instance.get_t2(), 500 / 2 * 30 - 1); |
33 | instance.set_a(42); |
34 | assert_eq(instance.get_t3(), 42 - (3 + 2 * (42 + 2))); |
35 | assert_eq(instance.get_t4(), 3 + - 5 - 8 - -9 * - - - 120); |
36 | instance.invoke_foo(); |
37 | assert_eq(instance.get_a(), (((42 + 8) * 10) / 2) - 3); |
38 | |
39 | assert_eq(instance.get_len(), ((25.+1.)/2. - 3.) * 3.); |
40 | ``` |
41 | |
42 | |
43 | ```rust |
44 | let instance = TestCase::new().unwrap(); |
45 | assert_eq!(instance.get_t1(), 4 + 3 * 2 + 2 - 50 - 2); |
46 | assert_eq!(instance.get_t2(), 500 / 2 * 30 - 1); |
47 | instance.set_a(42); |
48 | assert_eq!(instance.get_t3(), 42 - (3 + 2 * (42 + 2))); |
49 | assert_eq!(instance.get_t4(), 3 + - 5 - 8 - -9 * --- 120); |
50 | instance.invoke_foo(); |
51 | assert_eq!(instance.get_a(), (((42 + 8) * 10) / 2) - 3); |
52 | |
53 | assert_eq!(instance.get_len(), ((25.+1.)/2. - 3.) * 3.); |
54 | ``` |
55 | |
56 | ```js |
57 | var instance = new slint.TestCase({}); |
58 | assert.equal(instance.t1, 4 + 3 * 2 + 2 - 50 - 2); |
59 | assert.equal(instance.t2, 500 / 2 * 30 - 1); |
60 | instance.a = 42; |
61 | assert.equal(instance.t3, 42 - (3 + 2 * (42 + 2))); |
62 | assert.equal(instance.t4, 3 + - 5 - 8 - -9 * - - - 120); |
63 | instance.foo(); |
64 | assert.equal(instance.a, (((42 + 8) * 10) / 2) - 3); |
65 | |
66 | assert.equal(instance.len, ((25.+1.)/2. - 3.) * 3.); |
67 | ``` |
68 | */ |
69 | } |
70 | |
71 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
72 | use i_slint_backend_testing as slint_testing; |
73 | slint_testing::init(); |
74 | let instance = TestCase::new().unwrap(); |
75 | assert_eq!(instance.get_t1(), 4 + 3 * 2 + 2 - 50 - 2); |
76 | assert_eq!(instance.get_t2(), 500 / 2 * 30 - 1); |
77 | instance.set_a(42); |
78 | assert_eq!(instance.get_t3(), 42 - (3 + 2 * (42 + 2))); |
79 | assert_eq!(instance.get_t4(), 3 + - 5 - 8 - -9 * --- 120); |
80 | instance.invoke_foo(); |
81 | assert_eq!(instance.get_a(), (((42 + 8) * 10) / 2) - 3); |
82 | |
83 | assert_eq!(instance.get_len(), ((25.+1.)/2. - 3.) * 3.); |
84 | Ok(()) |
85 | } |