mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
C++ Interpreter: add API to get/set global value
This commit is contained in:
parent
c5d2ac2dd3
commit
81688906f7
4 changed files with 140 additions and 1 deletions
|
@ -491,3 +491,49 @@ SCENARIO("Send key events")
|
|||
sixtyfps::testing::send_keyboard_string_sequence(&*instance, "Hello keys!", {});
|
||||
REQUIRE(*instance->get_property("result")->to_string() == "Hello keys!");
|
||||
}
|
||||
|
||||
|
||||
SCENARIO("Global properties")
|
||||
{
|
||||
using namespace sixtyfps::interpreter;
|
||||
using namespace sixtyfps;
|
||||
|
||||
ComponentCompiler compiler;
|
||||
|
||||
auto result = compiler.build_from_source(
|
||||
R"(
|
||||
export global The-Global := {
|
||||
property <string> the-property: "€€€";
|
||||
}
|
||||
export Dummy := Rectangle { }
|
||||
)", "");
|
||||
REQUIRE(result.has_value());
|
||||
auto instance = result->create();
|
||||
|
||||
SECTION("Invalid read")
|
||||
{
|
||||
REQUIRE(!instance->get_global_property("the - global", "the-property").has_value());
|
||||
REQUIRE(!instance->get_global_property("The-Global", "the property").has_value());
|
||||
}
|
||||
SECTION("Invalid set")
|
||||
{
|
||||
REQUIRE(!instance->set_global_property("the - global", "the-property", 5.));
|
||||
REQUIRE(!instance->set_global_property("The-Global", "the property", 5.));
|
||||
REQUIRE(!instance->set_global_property("The-Global", "the-property", 5.));
|
||||
}
|
||||
SECTION("get property")
|
||||
{
|
||||
auto value = instance->get_global_property("The_Global", "the-property");
|
||||
REQUIRE(value.has_value());
|
||||
REQUIRE(value->to_string().has_value());
|
||||
REQUIRE(value->to_string().value() == "€€€");
|
||||
}
|
||||
SECTION("set property")
|
||||
{
|
||||
REQUIRE(instance->set_global_property("The-Global", "the-property", SharedString("§§§")));
|
||||
auto value = instance->get_global_property("The-Global", "the_property");
|
||||
REQUIRE(value.has_value());
|
||||
REQUIRE(value->to_string().has_value());
|
||||
REQUIRE(value->to_string().value() == "§§§");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue