aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-01-13 16:13:46 +0100
committerDavid Robillard <d@drobilla.net>2021-03-08 23:23:05 -0500
commit6bcd18ae60482790b645a345f718e7099250f261 (patch)
tree154fa41e8540ff03d43c9a1fa69568e0af5483d2 /test
parent8f84a055c88c2c271abe9cf86e998a3e5d0a4ced (diff)
downloadserd-6bcd18ae60482790b645a345f718e7099250f261.tar.gz
serd-6bcd18ae60482790b645a345f718e7099250f261.tar.bz2
serd-6bcd18ae60482790b645a345f718e7099250f261.zip
Simplify literal construction API
Diffstat (limited to 'test')
-rw-r--r--test/test_node.c62
-rw-r--r--test/test_reader_writer.c5
2 files changed, 41 insertions, 26 deletions
diff --git a/test/test_node.c b/test/test_node.c
index 93a408d6..8a93f215 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -174,10 +174,12 @@ test_node_equals(void)
{
static const uint8_t replacement_char_str[] = {0xEF, 0xBF, 0xBD, 0};
- SerdNode* const lhs =
- serd_new_string(SERD_STRING_VIEW((const char*)replacement_char_str, 3));
+ static const SerdStringView replacement_char = {
+ (const char*)replacement_char_str, 3};
+
+ SerdNode* lhs = serd_new_string(replacement_char);
+ SerdNode* rhs = serd_new_string(SERD_STATIC_STRING("123"));
- SerdNode* const rhs = serd_new_string(SERD_STATIC_STRING("123"));
assert(!serd_node_equals(lhs, rhs));
SerdNode* const qnode = serd_new_curie(SERD_STATIC_STRING("foo:bar"));
@@ -220,40 +222,54 @@ test_simple_node(void)
static void
test_literal(void)
{
- SerdNode* hello2 = serd_new_literal(
- SERD_STATIC_STRING("hello\""), SERD_EMPTY_STRING(), SERD_EMPTY_STRING());
+ SerdNode* hello2 = serd_new_string(SERD_STATIC_STRING("hello\""));
assert(serd_node_length(hello2) == 6 &&
serd_node_flags(hello2) == SERD_HAS_QUOTE &&
!strcmp(serd_node_string(hello2), "hello\""));
+
+ SerdNode* hello3 =
+ serd_new_plain_literal(SERD_STATIC_STRING("hello\""), SERD_EMPTY_STRING());
+
+ assert(serd_node_equals(hello2, hello3));
+
+ SerdNode* hello4 =
+ serd_new_typed_literal(SERD_STATIC_STRING("hello\""), SERD_EMPTY_STRING());
+
+ 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_STATIC_STRING("hello_l\""),
- SERD_EMPTY_STRING(),
- SERD_STATIC_STRING("en"));
+ const char* lang_lit_str = "\"Hello\"@en";
+ SerdNode* sliced_lang_lit =
+ serd_new_plain_literal(SERD_STRING_VIEW(lang_lit_str + 1, 5),
+ SERD_STRING_VIEW(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"));
- serd_node_free(hello_l);
+ serd_node_free(sliced_lang_lit);
- SerdNode* hello_dt =
- serd_new_literal(SERD_STATIC_STRING("hello_dt\""),
- SERD_STATIC_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_STRING_VIEW(type_lit_str + 1, 5),
+ SERD_STRING_VIEW(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"));
- serd_node_free(hello_dt);
+ assert(!strcmp(serd_node_string(datatype), "http://example.org/Greeting"));
+ serd_node_free(sliced_type_lit);
+
+ SerdNode* const plain_lit =
+ serd_new_plain_literal(SERD_STATIC_STRING("Plain"), SERD_EMPTY_STRING());
+ assert(!strcmp(serd_node_string(plain_lit), "Plain"));
+ serd_node_free(plain_lit);
}
static void
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index b39ea761..cb3371b6 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -199,12 +199,11 @@ test_writer(const char* const path)
assert(serd_sink_write(iface, 0, junk[i][0], junk[i][1], junk[i][2], NULL));
}
- static const SerdStringView empty = SERD_EMPTY_STRING();
static const SerdStringView urn_Type = SERD_STATIC_STRING("urn:Type");
static const SerdStringView en = SERD_STATIC_STRING("en");
- SerdNode* const t = serd_new_literal(buf_view, urn_Type, empty);
- SerdNode* const l = serd_new_literal(buf_view, empty, en);
+ SerdNode* const t = serd_new_typed_literal(buf_view, urn_Type);
+ SerdNode* const l = serd_new_plain_literal(buf_view, en);
const SerdNode* good[][3] = {{s, p, o}, {s, p, t}, {s, p, l}};
for (size_t i = 0; i < sizeof(good) / (sizeof(SerdNode*) * 3); ++i) {