1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/types"#]
2// Copyright © SixtyFPS GmbH <info@slint.dev>
3// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
4
5export component TestCase {
6 in property<string> hello: "hello";
7 in property<string> number: "42.56";
8 in property<string> invalid: "132a";
9 in property<string> negative: "-1200000.1";
10 in property<string> empty;
11
12 in-out property<float> number_as_float: number.to_float();
13 in-out property<float> negative_as_float: negative.to_float();
14 in-out property<bool> test_is_float: !hello.is_float() && number.is_float() &&
15 !invalid.is_float() && negative.is_float();
16
17 out property<bool> test: test_is_float && 42.56001 - number_as_float < 0.001 && "123".to-float() == 123
18 && "".to-float() == 0 && hello.to-float() == 0 && 0 == invalid.to-float() && empty.to-float() == 0;
19}
20
21
22/*
23
24```cpp
25auto fuzzy_compare = [](float a, float b) { return std::abs(a - b) < 0.00000001; };
26auto handle = TestCase::create();
27const TestCase &instance = *handle;
28assert(instance.get_test_is_float());
29assert(fuzzy_compare(instance.get_number_as_float(), 42.56));
30assert(fuzzy_compare(instance.get_negative_as_float(), -1200000.1));
31assert(instance.get_test());
32```
33
34```rust
35let instance = TestCase::new().unwrap();
36assert!(instance.get_test_is_float());
37assert_eq!(instance.get_number_as_float(), 42.56);
38assert_eq!(instance.get_negative_as_float(), -1200000.1);
39assert!(instance.get_test());
40```
41
42```js
43function n(a) { return Math.round(a*10000) }
44var instance = new slint.TestCase({});
45assert(instance.test_is_float);
46assert.equal(n(instance.number_as_float), n(42.56));
47assert.equal(n(instance.negative_as_float/1000), n(-1200000.1/1000));
48assert(instance.test);
49```
50
51*/
52}
53
54#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
55 use i_slint_backend_testing as slint_testing;
56 slint_testing::init();
57 let instance = TestCase::new().unwrap();
58 assert!(instance.get_test_is_float());
59 assert_eq!(instance.get_number_as_float(), 42.56);
60 assert_eq!(instance.get_negative_as_float(), -1200000.1);
61 assert!(instance.get_test());
62 Ok(())
63}