Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/rdf4cpp/Literal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ struct Literal : Node {
*/
template<datatypes::LiteralDatatype T>
[[nodiscard]] Literal cast(storage::DynNodeStoragePtr node_storage = keep_node_storage) const {
return this->cast(IRI{T::datatype_id, node_storage}, node_storage);
auto const ns = select_node_storage(node_storage);
return this->cast(IRI{T::datatype_id, ns}, ns);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion tests/nodes/tests_Literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ TEST_CASE("Literal - check fixed id") {
TEST_CASE("Literal - casting") {
using namespace datatypes::xsd;

auto const lit1 = Literal::make_typed_from_value<datatypes::xsd::Int>(123);
SUBCASE("any -> non-fixed") {
auto const lit1 = Literal::make_simple("1/2");
auto const lit2 = lit1.template cast<datatypes::owl::Rational>();

CHECK_EQ(lit2.datatype(), IRI{datatypes::owl::Rational::identifier});
CHECK_EQ(lit2.template value<datatypes::owl::Rational>(), datatypes::owl::Rational::cpp_type{1, 2});
}

SUBCASE("id cast") {
auto const lit1 = Literal::make_typed_from_value<String>("hello");
Expand Down Expand Up @@ -444,6 +450,7 @@ TEST_CASE("Literal - casting") {
}

SUBCASE("subtypes") {
auto const lit1 = Literal::make_typed_from_value<datatypes::xsd::Int>(123);
CHECK_EQ(lit1.template cast<Integer>().datatype(), IRI{Integer::identifier});
CHECK_EQ(lit1.template cast<Float>().datatype(), IRI{Float::identifier});

Expand Down
Loading