From 672e90382da08efa8f593fdc9081e31d0e548fa0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 14 Aug 2020 16:05:10 +0200 Subject: Merge datatype/language into node This moves closer to the sord API, and is more convenient in most cases. --- test/test_node.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test/test_node.c') diff --git a/test/test_node.c b/test/test_node.c index 11351e31..1d4d1107 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -196,6 +196,51 @@ test_node_from_substring(void) serd_node_free(a_b); } +static void +check_copy_equals(const SerdNode* const node) +{ + SerdNode* const copy = serd_node_copy(node); + + assert(serd_node_equals(node, copy)); + + serd_node_free(copy); +} + +static void +test_literal(void) +{ + SerdNode* hello2 = serd_new_literal("hello\"", NULL, NULL); + assert(serd_node_length(hello2) == 6 && + serd_node_flags(hello2) == SERD_HAS_QUOTE && + !strcmp(serd_node_string(hello2), "hello\"")); + check_copy_equals(hello2); + serd_node_free(hello2); + + SerdNode* hello_l = serd_new_literal("hello_l\"", NULL, "en"); + assert(serd_node_length(hello_l) == 8); + assert(!strcmp(serd_node_string(hello_l), "hello_l\"")); + assert(serd_node_flags(hello_l) == (SERD_HAS_QUOTE | SERD_HAS_LANGUAGE)); + + const SerdNode* const lang = serd_node_language(hello_l); + assert(lang); + assert(!strcmp(serd_node_string(lang), "en")); + check_copy_equals(hello_l); + serd_node_free(hello_l); + + SerdNode* hello_dt = + serd_new_literal("hello_dt\"", "http://example.org/Thing", NULL); + assert(serd_node_length(hello_dt) == 9); + assert(!strcmp(serd_node_string(hello_dt), "hello_dt\"")); + assert(serd_node_flags(hello_dt) == (SERD_HAS_QUOTE | SERD_HAS_DATATYPE)); + + const SerdNode* const datatype = serd_node_datatype(hello_dt); + assert(datatype); + assert(!strcmp(serd_node_string(datatype), "http://example.org/Thing")); + + check_copy_equals(hello_dt); + serd_node_free(hello_dt); +} + int main(void) { @@ -206,6 +251,7 @@ main(void) test_node_equals(); test_node_from_string(); test_node_from_substring(); + test_literal(); printf("Success\n"); return 0; -- cgit v1.2.1