diff options
-rw-r--r-- | include/serd/node.h | 6 | ||||
-rw-r--r-- | src/node.c | 8 | ||||
-rw-r--r-- | test/test_node.c | 21 |
3 files changed, 35 insertions, 0 deletions
diff --git a/include/serd/node.h b/include/serd/node.h index 5a3990b0..73569b44 100644 --- a/include/serd/node.h +++ b/include/serd/node.h @@ -167,6 +167,12 @@ SERD_API SerdNode* SERD_ALLOCATED serd_new_file_uri(SerdStringView path, SerdStringView hostname); /** + Create a new canonical xsd:boolean node. +*/ +SERD_API SerdNode* SERD_ALLOCATED +serd_new_boolean(bool b); + +/** Create a new canonical xsd:decimal literal. The resulting node will always contain a '.', start with a digit, and end @@ -45,6 +45,7 @@ typedef struct StaticNode { {sizeof(NS_XSD #name) - 1, 0, SERD_URI}, NS_XSD #name}; DEFINE_XSD_NODE(base64Binary) +DEFINE_XSD_NODE(boolean) DEFINE_XSD_NODE(decimal) DEFINE_XSD_NODE(integer) @@ -458,6 +459,13 @@ serd_digits(const double abs) } SerdNode* +serd_new_boolean(bool b) +{ + return serd_new_typed_literal(b ? serd_string("true") : serd_string("false"), + serd_node_string_view(&serd_xsd_boolean.node)); +} + +SerdNode* serd_new_decimal(const double d, const unsigned frac_digits, const SerdNode* const datatype) diff --git a/test/test_node.c b/test/test_node.c index fc9f1151..b7d43972 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -132,6 +132,26 @@ test_integer_to_node(void) } static void +test_boolean(void) +{ + SerdNode* const true_node = serd_new_boolean(true); + assert(!strcmp(serd_node_string(true_node), "true")); + + const SerdNode* const true_datatype = serd_node_datatype(true_node); + assert(true_datatype); + assert(!strcmp(serd_node_string(true_datatype), NS_XSD "boolean")); + serd_node_free(true_node); + + SerdNode* const false_node = serd_new_boolean(false); + assert(!strcmp(serd_node_string(false_node), "false")); + + const SerdNode* const false_datatype = serd_node_datatype(false_node); + assert(false_datatype); + assert(!strcmp(serd_node_string(false_datatype), NS_XSD "boolean")); + serd_node_free(false_node); +} + +static void test_blob_to_node(void) { assert(!serd_new_blob(&SERD_URI_NULL, 0, false, NULL)); @@ -303,6 +323,7 @@ main(void) test_double_to_node(); test_integer_to_node(); test_blob_to_node(); + test_boolean(); test_node_equals(); test_node_from_string(); test_node_from_substring(); |