aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-01-13 16:13:46 +0100
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit413b4d1f58bdf1d6aed785ae9b076c7b7b9a7350 (patch)
tree454cf92d9668431cbdcff8889e7597fcf162bf41 /test/test_node.c
parentcd89a74a2f7bf8c3efc3ecf1597cf39d6295db00 (diff)
downloadserd-413b4d1f58bdf1d6aed785ae9b076c7b7b9a7350.tar.gz
serd-413b4d1f58bdf1d6aed785ae9b076c7b7b9a7350.tar.bz2
serd-413b4d1f58bdf1d6aed785ae9b076c7b7b9a7350.zip
Simplify literal construction API
Diffstat (limited to 'test/test_node.c')
-rw-r--r--test/test_node.c66
1 files changed, 42 insertions, 24 deletions
diff --git a/test/test_node.c b/test/test_node.c
index 3cdff51a..fc9f1151 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -26,6 +26,7 @@
#endif
#define NS_XSD "http://www.w3.org/2001/XMLSchema#"
+#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
static void
test_strtod(double dbl, double max_delta)
@@ -169,12 +170,13 @@ test_node_equals(void)
{
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));
+ static const SerdStringView replacement_char = {
+ (const char*)replacement_char_str, 3};
- assert(serd_node_equals(lhs, lhs));
+ SerdNode* lhs = serd_new_string(replacement_char);
+ SerdNode* rhs = serd_new_string(serd_string("123"));
- SerdNode* const rhs = serd_new_string(serd_string("123"));
+ assert(serd_node_equals(lhs, lhs));
assert(!serd_node_equals(lhs, rhs));
SerdNode* const qnode = serd_new_curie(serd_string("foo:bar"));
@@ -230,42 +232,58 @@ check_copy_equals(const SerdNode* const node)
static void
test_literal(void)
{
- SerdNode* hello2 = serd_new_literal(
- serd_string("hello\""), serd_empty_string(), serd_empty_string());
+ SerdNode* hello2 = serd_new_string(serd_string("hello\""));
assert(serd_node_length(hello2) == 6 &&
serd_node_flags(hello2) == SERD_HAS_QUOTE &&
!strcmp(serd_node_string(hello2), "hello\""));
+
check_copy_equals(hello2);
+
+ SerdNode* hello3 =
+ serd_new_plain_literal(serd_string("hello\""), serd_empty_string());
+
+ assert(serd_node_equals(hello2, hello3));
+
+ SerdNode* hello4 =
+ serd_new_typed_literal(serd_string("hello\""), serd_empty_string());
+
+ assert(!serd_new_typed_literal(serd_string("plain"),
+ serd_string(NS_RDF "langString")));
+
+ assert(serd_node_equals(hello4, hello2));
+
+ serd_node_free(hello4);
+ serd_node_free(hello3);
serd_node_free(hello2);
- SerdNode* hello_l = serd_new_literal(
- serd_string("hello_l\""), serd_empty_string(), serd_string("en"));
+ const char* lang_lit_str = "\"Hello\"@en";
+ SerdNode* sliced_lang_lit = serd_new_plain_literal(
+ serd_substring(lang_lit_str + 1, 5), serd_substring(lang_lit_str + 8, 2));
- 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));
+ assert(!strcmp(serd_node_string(sliced_lang_lit), "Hello"));
- const SerdNode* const lang = serd_node_language(hello_l);
+ const SerdNode* const lang = serd_node_language(sliced_lang_lit);
assert(lang);
assert(!strcmp(serd_node_string(lang), "en"));
- check_copy_equals(hello_l);
- serd_node_free(hello_l);
+ check_copy_equals(sliced_lang_lit);
+ serd_node_free(sliced_lang_lit);
- SerdNode* hello_dt = serd_new_literal(serd_string("hello_dt\""),
- serd_string("http://example.org/Thing"),
- serd_empty_string());
+ const char* type_lit_str = "\"Hallo\"^^<http://example.org/Greeting>";
+ SerdNode* sliced_type_lit = serd_new_typed_literal(
+ serd_substring(type_lit_str + 1, 5), serd_substring(type_lit_str + 10, 27));
- 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));
+ assert(!strcmp(serd_node_string(sliced_type_lit), "Hallo"));
- const SerdNode* const datatype = serd_node_datatype(hello_dt);
+ const SerdNode* const datatype = serd_node_datatype(sliced_type_lit);
assert(datatype);
- assert(!strcmp(serd_node_string(datatype), "http://example.org/Thing"));
+ assert(!strcmp(serd_node_string(datatype), "http://example.org/Greeting"));
+ serd_node_free(sliced_type_lit);
- check_copy_equals(hello_dt);
- serd_node_free(hello_dt);
+ SerdNode* const plain_lit =
+ serd_new_plain_literal(serd_string("Plain"), serd_empty_string());
+ assert(!strcmp(serd_node_string(plain_lit), "Plain"));
+ serd_node_free(plain_lit);
}
static void