aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-04-29 18:29:03 +0200
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit5c02da92038072f28408854e862fc2d4edf765d4 (patch)
tree34577415801279981b626b18c1dc69dc79afea7f /test/test_node.c
parent672e90382da08efa8f593fdc9081e31d0e548fa0 (diff)
downloadserd-5c02da92038072f28408854e862fc2d4edf765d4.tar.gz
serd-5c02da92038072f28408854e862fc2d4edf765d4.tar.bz2
serd-5c02da92038072f28408854e862fc2d4edf765d4.zip
Simplify node construction API
Diffstat (limited to 'test/test_node.c')
-rw-r--r--test/test_node.c62
1 files changed, 40 insertions, 22 deletions
diff --git a/test/test_node.c b/test/test_node.c
index 1d4d1107..68bdf784 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -6,6 +6,7 @@
#include "serd/memory.h"
#include "serd/node.h"
#include "serd/string.h"
+#include "serd/string_view.h"
#include "serd/uri.h"
#include <assert.h>
@@ -146,19 +147,22 @@ test_blob_to_node(void)
static void
test_node_equals(void)
{
- const uint8_t replacement_char_str[] = {0xEF, 0xBF, 0xBD, 0};
- SerdNode* lhs =
- serd_new_string(SERD_LITERAL, (const char*)replacement_char_str);
- SerdNode* rhs = serd_new_string(SERD_LITERAL, "123");
+ static const uint8_t replacement_char_str[] = {0xEF, 0xBF, 0xBD, 0};
+
+ SerdNode* const lhs =
+ serd_new_string(serd_substring((const char*)replacement_char_str, 3));
+
+ assert(serd_node_equals(lhs, lhs));
+
+ SerdNode* const rhs = serd_new_string(serd_string("123"));
assert(!serd_node_equals(lhs, rhs));
- SerdNode* qnode = serd_new_string(SERD_CURIE, "foo:bar");
+ SerdNode* const qnode = serd_new_curie(serd_string("foo:bar"));
assert(!serd_node_equals(lhs, qnode));
- assert(serd_node_equals(lhs, lhs));
+ serd_node_free(qnode);
assert(!serd_node_copy(NULL));
- serd_node_free(qnode);
serd_node_free(lhs);
serd_node_free(rhs);
}
@@ -166,15 +170,15 @@ test_node_equals(void)
static void
test_node_from_string(void)
{
- SerdNode* const hello = serd_new_string(SERD_LITERAL, "hello\"");
+ SerdNode* const hello = serd_new_string(serd_string("hello\""));
assert(serd_node_length(hello) == 6);
assert(serd_node_flags(hello) == SERD_HAS_QUOTE);
- assert(!strcmp(serd_node_string(hello), "hello\""));
+ assert(!strncmp(serd_node_string(hello), "hello\"", 6));
assert(!strcmp(serd_node_string_view(hello).data, "hello\""));
assert(serd_node_string_view(hello).length == 6);
serd_node_free(hello);
- SerdNode* const uri = serd_new_string(SERD_URI, "http://example.org/");
+ SerdNode* const uri = serd_new_uri(serd_string("http://example.org/"));
assert(serd_node_length(uri) == 19);
assert(!strcmp(serd_node_string(uri), "http://example.org/"));
assert(serd_node_uri_view(uri).authority.length == 11);
@@ -185,14 +189,11 @@ test_node_from_string(void)
static void
test_node_from_substring(void)
{
- SerdNode* a_b = serd_new_substring(SERD_LITERAL, "a\"bc", 3);
- assert(serd_node_length(a_b) == 3 && serd_node_flags(a_b) == SERD_HAS_QUOTE &&
- !strncmp(serd_node_string(a_b), "a\"b", 3));
-
- serd_node_free(a_b);
- a_b = serd_new_substring(SERD_LITERAL, "a\"bc", 10);
- assert(serd_node_length(a_b) == 4 && serd_node_flags(a_b) == SERD_HAS_QUOTE &&
- !strncmp(serd_node_string(a_b), "a\"bc", 4));
+ SerdNode* const a_b = serd_new_string(serd_substring("a\"bc", 3));
+ assert(serd_node_length(a_b) == 3);
+ assert(serd_node_flags(a_b) == SERD_HAS_QUOTE);
+ assert(strlen(serd_node_string(a_b)) == 3);
+ assert(!strncmp(serd_node_string(a_b), "a\"b", 3));
serd_node_free(a_b);
}
@@ -209,14 +210,18 @@ check_copy_equals(const SerdNode* const node)
static void
test_literal(void)
{
- SerdNode* hello2 = serd_new_literal("hello\"", NULL, NULL);
+ SerdNode* hello2 = serd_new_literal(
+ serd_string("hello\""), serd_empty_string(), serd_empty_string());
+
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");
+ SerdNode* hello_l = serd_new_literal(
+ serd_string("hello_l\""), serd_empty_string(), serd_string("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));
@@ -227,8 +232,10 @@ test_literal(void)
check_copy_equals(hello_l);
serd_node_free(hello_l);
- SerdNode* hello_dt =
- serd_new_literal("hello_dt\"", "http://example.org/Thing", NULL);
+ SerdNode* hello_dt = serd_new_literal(serd_string("hello_dt\""),
+ serd_string("http://example.org/Thing"),
+ serd_empty_string());
+
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));
@@ -241,6 +248,16 @@ test_literal(void)
serd_node_free(hello_dt);
}
+static void
+test_blank(void)
+{
+ SerdNode* blank = serd_new_blank(serd_string("b0"));
+ assert(serd_node_length(blank) == 2);
+ assert(serd_node_flags(blank) == 0);
+ assert(!strcmp(serd_node_string(blank), "b0"));
+ serd_node_free(blank);
+}
+
int
main(void)
{
@@ -252,6 +269,7 @@ main(void)
test_node_from_string();
test_node_from_substring();
test_literal();
+ test_blank();
printf("Success\n");
return 0;