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
4global Glo := {
5 property <int> hello: 42;
6 pure callback sum(int, int) -> int;
7 pure callback mul(int, int) -> int;
8 pure callback calculate_profit() -> int;
9 calculate_profit() => { return 1000; }
10}
11
12ExtraComp := Rectangle {
13 property<int> five: Glo.sum(3, 2);
14 property<int> six: Glo.mul(3, 2);
15}
16
17
18TestCase := Window {
19 pure callback sum <=> Glo.sum;
20 pure callback mul <=> Glo.mul;
21
22 x := ExtraComp {}
23 property<int> five: x.five;
24 property<int> six: x.six;
25
26 property<int> profit: Glo.calculate-profit();
27
28 //mul(α, β) => { return α * β; }
29 property<bool> test: five == 0 && profit == 1000; // because the callback is not set
30
31}
32
33/*
34```rust
35let instance = TestCase::new().unwrap();
36instance.on_sum(|a, b| a + b);
37instance.on_mul(|a, b| a * b);
38assert_eq!(instance.get_five(), 5);
39assert_eq!(instance.get_six(), 6);
40assert_eq!(instance.get_profit(), 1000);
41```
42
43```cpp
44auto handle = TestCase::create();
45const TestCase &instance = *handle;
46instance.on_sum([](int a, int b) { return a + b; });
47instance.on_mul([](int a, int b) { return a * b; });
48assert_eq(instance.get_five(), 5);
49assert_eq(instance.get_six(), 6);
50assert_eq(instance.get_profit(), 1000);
51```
52
53```js
54let instance = new slint.TestCase({
55 sum: function(a, b) { return a + b; },
56 mul: function(a, b) { return a * b; }
57});
58assert.equal(instance.five, 5);
59assert.equal(instance.six, 6);
60assert.equal(instance.profit, 1000);
61```
62
63*/
64