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
29auto handle = TestCase::create();
30const TestCase &instance = *handle;
31assert_eq(instance.get_t1(), 4 + 3 * 2 + 2 - 50 - 2);
32assert_eq(instance.get_t2(), 500 / 2 * 30 - 1);
33instance.set_a(42);
34assert_eq(instance.get_t3(), 42 - (3 + 2 * (42 + 2)));
35assert_eq(instance.get_t4(), 3 + - 5 - 8 - -9 * - - - 120);
36instance.invoke_foo();
37assert_eq(instance.get_a(), (((42 + 8) * 10) / 2) - 3);
38
39assert_eq(instance.get_len(), ((25.+1.)/2. - 3.) * 3.);
40```
41
42
43```rust
44let instance = TestCase::new().unwrap();
45assert_eq!(instance.get_t1(), 4 + 3 * 2 + 2 - 50 - 2);
46assert_eq!(instance.get_t2(), 500 / 2 * 30 - 1);
47instance.set_a(42);
48assert_eq!(instance.get_t3(), 42 - (3 + 2 * (42 + 2)));
49assert_eq!(instance.get_t4(), 3 + - 5 - 8 - -9 * --- 120);
50instance.invoke_foo();
51assert_eq!(instance.get_a(), (((42 + 8) * 10) / 2) - 3);
52
53assert_eq!(instance.get_len(), ((25.+1.)/2. - 3.) * 3.);
54```
55
56```js
57var instance = new slint.TestCase({});
58assert.equal(instance.t1, 4 + 3 * 2 + 2 - 50 - 2);
59assert.equal(instance.t2, 500 / 2 * 30 - 1);
60instance.a = 42;
61assert.equal(instance.t3, 42 - (3 + 2 * (42 + 2)));
62assert.equal(instance.t4, 3 + - 5 - 8 - -9 * - - - 120);
63instance.foo();
64assert.equal(instance.a, (((42 + 8) * 10) / 2) - 3);
65
66assert.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}