1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
3
4TestCase := Rectangle {
5 property<{a: string, b: int}> foo: {a : "444", b: 12 };
6 property<{a: string, b: int}> obj_conversion: { b: 12, a : 444, c: "nothing" };
7 property<{a: string, b: int}> obj_conversion2: { a: "hello" };
8 property<{a: string, b: int}> obj_cond: true ? { b: 12, a : "ddd" } : { a: 12, b : 444, c: "nothing" };
9 property<{a: int, b: int}> obj_cond_merge : true ? { a: 1 } : { b: 10 };
10 property<bool> obj_binop_merge : { foo: 0, x: 1 } == { bar: 0, x: 1 };
11
12 property<string> foo_a : foo.a;
13 property<int> foo_b : foo.b;
14 property<int> obj_cond_merge_b : obj_cond_merge.b;
15 callback change_foo;
16 change_foo => {
17 foo.a = obj_conversion2.a;
18 foo.b += 8 + obj_conversion2.b;
19 }
20
21 function return_object() -> { aa: { bb: int } }
22 { return { aa: { bb: { cc: 42 }.cc } }; }
23 property <bool> test: return_object().aa.bb == 42 && obj_binop_merge;
24
25}
26
27
28/*
29```rust
30let instance = TestCase::new().unwrap();
31assert_eq!(instance.get_foo_a(), slint::SharedString::from("444"));
32assert_eq!(instance.get_foo_b(), 12);
33instance.invoke_change_foo();
34assert_eq!(instance.get_foo_a(), slint::SharedString::from("hello"));
35assert_eq!(instance.get_foo_b(), 20);
36assert_eq!(instance.get_obj_cond_merge_b(), 0);
37assert!(instance.get_obj_binop_merge());
38assert!(instance.get_test());
39
40// This API to set with a tuple should maybe not be accessible?
41instance.set_foo(("yo".into(), 33));
42assert_eq!(instance.get_foo_a(), slint::SharedString::from("yo"));
43assert_eq!(instance.get_foo_b(), 33);
44
45```
46
47```cpp
48auto handle = TestCase::create();
49const TestCase &instance = *handle;
50assert_eq(instance.get_foo_a(), slint::SharedString("444"));
51assert_eq(instance.get_foo_b(), 12);
52instance.invoke_change_foo();
53assert_eq(instance.get_foo_a(), slint::SharedString("hello"));
54assert_eq(instance.get_foo_b(), 20);
55assert_eq(instance.get_obj_cond_merge_b(), 0);
56assert_eq(instance.get_obj_binop_merge(), true);
57assert(instance.get_test());
58
59// This API to set with a tuple should maybe not be accessible?
60instance.set_foo(std::make_tuple(slint::SharedString("yo"), 33));
61assert_eq(instance.get_foo_a(), slint::SharedString("yo"));
62assert_eq(instance.get_foo_b(), 33);
63```
64
65
66```js
67var instance = new slint.TestCase({});
68assert.equal(instance.foo_a, ("444"));
69assert.equal(instance.foo_b, 12);
70instance.change_foo();
71assert.equal(instance.foo_a, "hello");
72assert.equal(instance.foo_b, 20);
73assert.equal(instance.obj_cond_merge_b, 0);
74assert(instance.obj_binop_merge);
75assert(instance.test);
76
77instance.foo = { a: "yo", b: 33 };
78assert.equal(instance.foo_a, "yo");
79assert.equal(instance.foo_b, 33);
80```
81*/
82