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