slint/tests/cases/expr/string_template.60
2021-07-02 15:55:54 +02:00

58 lines
1.9 KiB
Text

/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2021 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2021 Simon Hausmann <simon.hausmann@sixtyfps.io>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */
TestCase := Rectangle {
property<int> a:12;
property<string> s1: "hello\{a}\{a}";
property<string> s2: "\{10}hello\{5.1}";
property<string> s3: "x";
property<{ a: string }> obj: { a: "a" };
property<string> s4: "\{obj.a}xxx";
callback foo;
foo => {
s3 = "\{s3}\{a+0}\{"\{s3}\{a+0}"}";
obj.a = "\{obj.a}\{"yo"}";
}
}
/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert_eq(instance.get_s1(), sixtyfps::SharedString("hello1212"));
assert_eq(instance.get_s2(), sixtyfps::SharedString("10hello5.1"));
instance.set_a(42);
assert_eq(instance.get_s1(), sixtyfps::SharedString("hello4242"));
instance.invoke_foo();
assert_eq(instance.get_s3(), sixtyfps::SharedString("x42x42"));
assert_eq(instance.get_s4(), sixtyfps::SharedString("ayoxxx"));
```
```rust
let instance = TestCase::new();
assert_eq!(instance.get_s1(), sixtyfps::SharedString::from("hello1212"));
assert_eq!(instance.get_s2(), sixtyfps::SharedString::from("10hello5.1"));
instance.set_a(42);
assert_eq!(instance.get_s1(), sixtyfps::SharedString::from("hello4242"));
instance.invoke_foo();
assert_eq!(instance.get_s3(), sixtyfps::SharedString::from("x42x42"));
assert_eq!(instance.get_s4(), sixtyfps::SharedString::from("ayoxxx"));
```
```js
var instance = new sixtyfps.TestCase({});
assert.equal(instance.s1, "hello1212");
assert.equal(instance.s2, "10hello5.1");
instance.a = 42;
assert.equal(instance.s1, "hello4242");
instance.foo();
assert.equal(instance.s3, "x42x42");
assert.equal(instance.s4, "ayoxxx");
```
*/