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 | export struct Player := { |
5 | name: string, |
6 | score: int, |
7 | energy_level: float, |
8 | } |
9 | |
10 | export struct Unused { |
11 | foo: int, |
12 | } |
13 | |
14 | export struct With-Dash_And-underscore { |
15 | foo-bar: int, |
16 | } |
17 | |
18 | TestCase := Rectangle { |
19 | property<Player> player_1: {name : "Player1" , score: 12, energy_level: 80% }; |
20 | property<Player> player_2: {name : "Player2" , score: 24, energy_level: 40% }; |
21 | |
22 | property<[Player]> players: [player_1, player_2]; |
23 | property<[Player]> player_list: [ |
24 | {name : "Simon" , score: 1, energy_level: 50% }, |
25 | {name : "Olivier" , score: 10 }, |
26 | {name : "NoScore" , } |
27 | ]; |
28 | |
29 | property player_2_alias <=> player_2; |
30 | property<int> player_2_score: player_2_alias.score; |
31 | |
32 | in-out property <With-Dash_And-underscore> underscore; |
33 | |
34 | property <bool> test: player_2_score == 24; |
35 | |
36 | } |
37 | |
38 | /* |
39 | ```rust |
40 | let instance = TestCase::new().unwrap(); |
41 | |
42 | assert_eq!(instance.get_player_1().score, 12); |
43 | assert_eq!(instance.get_player_1(), Player{ name: "Player1".into(), score: 12, energy_level: 0.8 }); |
44 | assert_eq!(instance.get_player_2(), Player{ name: "Player2".into(), score: 24, energy_level: 0.4 }); |
45 | let super_player = Player{ name: "Super Player".into(), score: 99, energy_level: 0.4 }; |
46 | instance.set_player_2(super_player.clone()); |
47 | assert_eq!(instance.get_player_2(), super_player); |
48 | |
49 | assert_eq!(instance.get_player_2_score(), 99); |
50 | |
51 | |
52 | let _ = Unused { foo: 42 }; |
53 | let underscore = With_Dash_And_underscore { foo_bar: 8 }; |
54 | instance.set_underscore(underscore); |
55 | ``` |
56 | |
57 | ```cpp |
58 | auto handle = TestCase::create(); |
59 | const TestCase &instance = *handle; |
60 | |
61 | assert_eq(instance.get_player_1().score, 12.); |
62 | auto [ name, score, energy_level ] = instance.get_player_2(); |
63 | assert_eq(name, "Player2"); |
64 | assert_eq(score, 24); |
65 | auto super_player = Player{ "Super Player", 99, 0.44 }; |
66 | instance.set_player_2(super_player); |
67 | assert_eq(instance.get_player_2().name, "Super Player"); |
68 | |
69 | assert_eq(instance.get_player_2_score(), 99); |
70 | |
71 | Unused _unused { .foo = 42 }; |
72 | (void)_unused; |
73 | |
74 | With_Dash_And_underscore underscore {.foo_bar = 8 }; |
75 | instance.set_underscore(underscore); |
76 | ``` |
77 | |
78 | ```js |
79 | var instance = new slint.TestCase(); |
80 | assert.equal(instance.player_1.score, 12.); |
81 | let player2 = instance.player_2 |
82 | assert.equal(player2.name, "Player2"); |
83 | let super_player = { name: "Super Player", score: 99, energy_level: 0.4 }; |
84 | instance.player_2 = super_player; |
85 | assert.equal(instance.player_2.name, "Super Player"); |
86 | assert.equal(instance.player_2_score, 99); |
87 | assert.equal(instance.player_2.energy_level, 0.4); |
88 | ``` |
89 | |
90 | */ |
91 | |