| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | global G := { |
| 5 | property <string> hello: "hello" ; |
| 6 | function meh(w: string) -> string { |
| 7 | return hello + " " + w; |
| 8 | } |
| 9 | } |
| 10 | |
| 11 | SubCompo := Rectangle { |
| 12 | public pure function hello() -> color { red } |
| 13 | } |
| 14 | |
| 15 | export global PubGlob := { |
| 16 | public function beh(a: int, b: int) -> int { a + b + 10 } |
| 17 | } |
| 18 | |
| 19 | TestCase := Rectangle { |
| 20 | |
| 21 | property <int> c: 100000; |
| 22 | private property <int> one: 1 + Math.round((x / 1px) - (y / 1px)); |
| 23 | |
| 24 | function foo() {} |
| 25 | function the_function(a: int, b: int) -> int { foo(); a + b + c + one } |
| 26 | |
| 27 | if true : Rectangle { |
| 28 | background: the_function(1, 2) > 3 ? blue: sc.hello(); |
| 29 | } |
| 30 | |
| 31 | sc := SubCompo { |
| 32 | |
| 33 | } |
| 34 | |
| 35 | public function pub(a: int, b: int) -> int { a + b + c } |
| 36 | |
| 37 | public function set_c(p: int) { c = p } |
| 38 | |
| 39 | |
| 40 | property <bool> test: the_function(4500, 20) == 104521 && G.meh("world" ) == "hello world" && sc.hello() == Colors.red; |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | ```rust |
| 45 | let instance = TestCase::new().unwrap(); |
| 46 | assert!(instance.get_test()); |
| 47 | assert_eq!(instance.invoke_pub(20, 2), 100022); |
| 48 | assert_eq!(instance.global::<PubGlob<'_>>().invoke_beh(2, 2), 14); |
| 49 | ``` |
| 50 | |
| 51 | ```cpp |
| 52 | auto handle = TestCase::create(); |
| 53 | const TestCase &instance = *handle; |
| 54 | assert(instance.get_test()); |
| 55 | assert_eq(instance.invoke_pub(20, 2), 100022); |
| 56 | assert_eq(instance.global<PubGlob>().invoke_beh(2, 2), 14); |
| 57 | ``` |
| 58 | |
| 59 | |
| 60 | ```js |
| 61 | var instance = new slint.TestCase(); |
| 62 | assert(instance.test); |
| 63 | assert.equal(instance.pub(20, 2), 100022); |
| 64 | assert.equal(instance.PubGlob.beh(2, 2), 14); |
| 65 | ``` |
| 66 | */ |
| 67 | |