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 | global 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 | |
12 | ExtraComp := Rectangle { |
13 | property<int> five: Glo.sum(3, 2); |
14 | property<int> six: Glo.mul(3, 2); |
15 | } |
16 | |
17 | |
18 | TestCase := 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 |
35 | let instance = TestCase::new().unwrap(); |
36 | instance.on_sum(|a, b| a + b); |
37 | instance.on_mul(|a, b| a * b); |
38 | assert_eq!(instance.get_five(), 5); |
39 | assert_eq!(instance.get_six(), 6); |
40 | assert_eq!(instance.get_profit(), 1000); |
41 | ``` |
42 | |
43 | ```cpp |
44 | auto handle = TestCase::create(); |
45 | const TestCase &instance = *handle; |
46 | instance.on_sum([](int a, int b) { return a + b; }); |
47 | instance.on_mul([](int a, int b) { return a * b; }); |
48 | assert_eq(instance.get_five(), 5); |
49 | assert_eq(instance.get_six(), 6); |
50 | assert_eq(instance.get_profit(), 1000); |
51 | ``` |
52 | |
53 | ```js |
54 | let instance = new slint.TestCase({ |
55 | sum: function(a, b) { return a + b; }, |
56 | mul: function(a, b) { return a * b; } |
57 | }); |
58 | assert.equal(instance.five, 5); |
59 | assert.equal(instance.six, 6); |
60 | assert.equal(instance.profit, 1000); |
61 | ``` |
62 | |
63 | */ |
64 | |