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 | |
4 | TestCase := 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 |
30 | let instance = TestCase::new().unwrap(); |
31 | assert_eq!(instance.get_foo_a(), slint::SharedString::from("444")); |
32 | assert_eq!(instance.get_foo_b(), 12); |
33 | instance.invoke_change_foo(); |
34 | assert_eq!(instance.get_foo_a(), slint::SharedString::from("hello")); |
35 | assert_eq!(instance.get_foo_b(), 20); |
36 | assert_eq!(instance.get_obj_cond_merge_b(), 0); |
37 | assert!(instance.get_obj_binop_merge()); |
38 | assert!(instance.get_test()); |
39 | |
40 | // This API to set with a tuple should maybe not be accessible? |
41 | instance.set_foo(("yo".into(), 33)); |
42 | assert_eq!(instance.get_foo_a(), slint::SharedString::from("yo")); |
43 | assert_eq!(instance.get_foo_b(), 33); |
44 | |
45 | ``` |
46 | |
47 | ```cpp |
48 | auto handle = TestCase::create(); |
49 | const TestCase &instance = *handle; |
50 | assert_eq(instance.get_foo_a(), slint::SharedString("444")); |
51 | assert_eq(instance.get_foo_b(), 12); |
52 | instance.invoke_change_foo(); |
53 | assert_eq(instance.get_foo_a(), slint::SharedString("hello")); |
54 | assert_eq(instance.get_foo_b(), 20); |
55 | assert_eq(instance.get_obj_cond_merge_b(), 0); |
56 | assert_eq(instance.get_obj_binop_merge(), true); |
57 | assert(instance.get_test()); |
58 | |
59 | // This API to set with a tuple should maybe not be accessible? |
60 | instance.set_foo(std::make_tuple(slint::SharedString("yo"), 33)); |
61 | assert_eq(instance.get_foo_a(), slint::SharedString("yo")); |
62 | assert_eq(instance.get_foo_b(), 33); |
63 | ``` |
64 | |
65 | |
66 | ```js |
67 | var instance = new slint.TestCase({}); |
68 | assert.equal(instance.foo_a, ("444")); |
69 | assert.equal(instance.foo_b, 12); |
70 | instance.change_foo(); |
71 | assert.equal(instance.foo_a, "hello"); |
72 | assert.equal(instance.foo_b, 20); |
73 | assert.equal(instance.obj_cond_merge_b, 0); |
74 | assert(instance.obj_binop_merge); |
75 | assert(instance.test); |
76 | |
77 | instance.foo = { a: "yo", b: 33 }; |
78 | assert.equal(instance.foo_a, "yo"); |
79 | assert.equal(instance.foo_b, 33); |
80 | ``` |
81 | */ |
82 | |