Add C++ Value Array construction/extraction

This commit is contained in:
Simon Hausmann 2021-03-17 16:52:30 +01:00
parent e20dd384f5
commit 79612d7354
3 changed files with 61 additions and 7 deletions

View file

@ -85,4 +85,20 @@ SCENARIO("Value API")
REQUIRE(bool_opt.has_value());
REQUIRE(bool_opt.value() == true);
}
SECTION("Construct an array")
{
REQUIRE(!value.to_array().has_value());
sixtyfps::SharedVector<Value> array { Value(42.0), Value(true) };
value = Value(array);
REQUIRE(value.type() == Value::Type::Array);
auto array_opt = value.to_array();
REQUIRE(array_opt.has_value());
auto extracted_array = array_opt.value();
REQUIRE(extracted_array.size() == 2);
REQUIRE(extracted_array[0].to_number().value() == 42);
REQUIRE(extracted_array[1].to_bool().value());
}
}