diff options
author | David Robillard <d@drobilla.net> | 2021-07-22 15:26:22 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-14 19:37:51 -0500 |
commit | ca3a7049506cd1ba91326a36fc02a7319657728c (patch) | |
tree | 7289c877d9dc6286ab1826fab45e8a1612e8bc20 /test | |
parent | 21f17ad27b3e805003e50b0f5fcbe606bfef0f3b (diff) | |
download | serd-ca3a7049506cd1ba91326a36fc02a7319657728c.tar.gz serd-ca3a7049506cd1ba91326a36fc02a7319657728c.tar.bz2 serd-ca3a7049506cd1ba91326a36fc02a7319657728c.zip |
Preserve long or short quoting from input documents
Diffstat (limited to 'test')
-rw-r--r-- | test/test_env.c | 6 | ||||
-rw-r--r-- | test/test_node.c | 109 | ||||
-rw-r--r-- | test/test_node_syntax.c | 5 | ||||
-rw-r--r-- | test/test_nodes.c | 4 | ||||
-rw-r--r-- | test/test_reader_writer.c | 4 | ||||
-rw-r--r-- | test/test_string.c | 13 | ||||
-rw-r--r-- | test/test_writer.c | 8 |
7 files changed, 74 insertions, 75 deletions
diff --git a/test/test_env.c b/test/test_env.c index 41e2060b..1b924ae9 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -164,8 +164,10 @@ test_expand_bad_uri_datatype(void) { static const SerdStringView type = SERD_STRING("Type"); - SerdNode* const typed = serd_new_typed_literal(SERD_STRING("data"), type); - SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + SerdNode* const typed = + serd_new_literal(SERD_STRING("data"), SERD_HAS_DATATYPE, type); + + SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); assert(!serd_env_expand_node(env, typed)); diff --git a/test/test_node.c b/test/test_node.c index 72bd44e1..ef17afe9 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -83,8 +83,8 @@ check_get_boolean(const char* string, const char* datatype_uri, const bool expected) { - SerdNode* const node = - serd_new_typed_literal(SERD_STRING(string), SERD_STRING(datatype_uri)); + SerdNode* const node = serd_new_literal( + SERD_STRING(string), SERD_HAS_DATATYPE, SERD_STRING(datatype_uri)); assert(node); assert(serd_get_boolean(node) == expected); @@ -170,8 +170,8 @@ check_get_double(const char* string, const char* datatype_uri, const double expected) { - SerdNode* const node = - serd_new_typed_literal(SERD_STRING(string), SERD_STRING(datatype_uri)); + SerdNode* const node = serd_new_literal( + SERD_STRING(string), SERD_HAS_DATATYPE, SERD_STRING(datatype_uri)); assert(node); @@ -199,8 +199,8 @@ test_get_double(void) assert(isnan(serd_get_double(nan))); serd_node_free(nan); - SerdNode* const invalid = - serd_new_typed_literal(SERD_STRING("!invalid"), SERD_STRING(NS_XSD "long")); + SerdNode* const invalid = serd_new_literal( + SERD_STRING("!invalid"), SERD_HAS_DATATYPE, SERD_STRING(NS_XSD "long")); assert(isnan(serd_get_double(invalid))); serd_node_free(invalid); @@ -243,8 +243,8 @@ check_get_float(const char* string, const char* datatype_uri, const float expected) { - SerdNode* const node = - serd_new_typed_literal(SERD_STRING(string), SERD_STRING(datatype_uri)); + SerdNode* const node = serd_new_literal( + SERD_STRING(string), SERD_HAS_DATATYPE, SERD_STRING(datatype_uri)); assert(node); @@ -270,8 +270,8 @@ test_get_float(void) assert(isnan(serd_get_float(nan))); serd_node_free(nan); - SerdNode* const invalid = - serd_new_typed_literal(SERD_STRING("!invalid"), SERD_STRING(NS_XSD "long")); + SerdNode* const invalid = serd_new_literal( + SERD_STRING("!invalid"), SERD_HAS_DATATYPE, SERD_STRING(NS_XSD "long")); assert(isnan(serd_get_double(invalid))); @@ -308,8 +308,8 @@ check_get_integer(const char* string, const char* datatype_uri, const int64_t expected) { - SerdNode* const node = - serd_new_typed_literal(SERD_STRING(string), SERD_STRING(datatype_uri)); + SerdNode* const node = serd_new_literal( + SERD_STRING(string), SERD_HAS_DATATYPE, SERD_STRING(datatype_uri)); assert(node); assert(serd_get_integer(node) == expected); @@ -372,8 +372,8 @@ check_get_base64(const char* string, const char* datatype_uri, const char* expected) { - SerdNode* const node = - serd_new_typed_literal(SERD_STRING(string), SERD_STRING(datatype_uri)); + SerdNode* const node = serd_new_literal( + SERD_STRING(string), SERD_HAS_DATATYPE, SERD_STRING(datatype_uri)); assert(node); @@ -398,8 +398,8 @@ test_get_base64(void) check_get_base64("Zm9vYg==", NS_XSD "base64Binary", "foob"); check_get_base64(" \f\n\r\t\vZm9v \f\n\r\t\v", NS_XSD "base64Binary", "foo"); - SerdNode* const node = serd_new_typed_literal( - SERD_STRING("Zm9v"), SERD_STRING(NS_XSD "base64Binary")); + SerdNode* const node = serd_new_literal( + SERD_STRING("Zm9v"), SERD_HAS_DATATYPE, SERD_STRING(NS_XSD "base64Binary")); char small[2] = {0}; const SerdWriteResult r = serd_get_base64(node, sizeof(small), small); @@ -433,7 +433,7 @@ test_node_from_syntax(void) { SerdNode* const hello = serd_new_string(SERD_STRING("hello\"")); assert(serd_node_length(hello) == 6); - assert(serd_node_flags(hello) == SERD_HAS_QUOTE); + assert(!serd_node_flags(hello)); assert(!strncmp(serd_node_string(hello), "hello\"", 6)); serd_node_free(hello); } @@ -443,7 +443,7 @@ test_node_from_substring(void) { 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(!serd_node_flags(a_b)); assert(strlen(serd_node_string(a_b)) == 3); assert(!strncmp(serd_node_string(a_b), "a\"b", 3)); serd_node_free(a_b); @@ -468,46 +468,54 @@ check_copy_equals(const SerdNode* const node) static void test_literal(void) { - SerdNode* hello2 = serd_new_string(SERD_STRING("hello\"")); + static const SerdStringView hello_str = SERD_STRING("hello"); + static const SerdStringView empty_str = SERD_EMPTY_STRING(); - assert(serd_node_length(hello2) == 6 && - serd_node_flags(hello2) == SERD_HAS_QUOTE && - !strcmp(serd_node_string(hello2), "hello\"")); + assert(!serd_new_literal( + hello_str, SERD_HAS_DATATYPE | SERD_HAS_LANGUAGE, SERD_STRING("whatever"))); - check_copy_equals(hello2); + assert(!serd_new_literal(hello_str, SERD_HAS_DATATYPE, empty_str)); + assert(!serd_new_literal(hello_str, SERD_HAS_LANGUAGE, empty_str)); + + assert(!serd_new_literal(hello_str, SERD_HAS_DATATYPE, SERD_STRING("Type"))); + assert(!serd_new_literal(hello_str, SERD_HAS_DATATYPE, SERD_STRING("de"))); - SerdNode* hello3 = - serd_new_plain_literal(SERD_STRING("hello\""), SERD_EMPTY_STRING()); + assert(!serd_new_literal(hello_str, SERD_HAS_LANGUAGE, SERD_STRING("3n"))); + assert(!serd_new_literal(hello_str, SERD_HAS_LANGUAGE, SERD_STRING("d3"))); + assert(!serd_new_literal(hello_str, SERD_HAS_LANGUAGE, SERD_STRING("d3"))); + assert(!serd_new_literal(hello_str, SERD_HAS_LANGUAGE, SERD_STRING("en-!"))); - assert(serd_node_equals(hello2, hello3)); + SerdNode* hello2 = serd_new_string(SERD_STRING("hello\"")); - SerdNode* hello4 = - serd_new_typed_literal(SERD_STRING("hello\""), SERD_EMPTY_STRING()); + assert(serd_node_length(hello2) == 6 && + !strcmp(serd_node_string(hello2), "hello\"")); - assert(!serd_new_typed_literal(SERD_STRING("plain"), - SERD_STRING(NS_RDF "langString"))); + check_copy_equals(hello2); - assert(serd_node_equals(hello4, hello2)); + assert(!serd_new_literal( + SERD_STRING("plain"), SERD_HAS_DATATYPE, SERD_STRING(NS_RDF "langString"))); - serd_node_free(hello4); - serd_node_free(hello3); serd_node_free(hello2); - 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)); + const char* lang_lit_str = "\"Hello\"@en-ca"; + SerdNode* sliced_lang_lit = + serd_new_literal(SERD_SUBSTRING(lang_lit_str + 1, 5), + SERD_HAS_LANGUAGE, + SERD_SUBSTRING(lang_lit_str + 8, 5)); assert(!strcmp(serd_node_string(sliced_lang_lit), "Hello")); const SerdNode* const lang = serd_node_language(sliced_lang_lit); assert(lang); - assert(!strcmp(serd_node_string(lang), "en")); + assert(!strcmp(serd_node_string(lang), "en-ca")); check_copy_equals(sliced_lang_lit); serd_node_free(sliced_lang_lit); - 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)); + const char* type_lit_str = "\"Hallo\"^^<http://example.org/Greeting>"; + SerdNode* sliced_type_lit = + serd_new_literal(SERD_SUBSTRING(type_lit_str + 1, 5), + SERD_HAS_DATATYPE, + SERD_SUBSTRING(type_lit_str + 10, 27)); assert(!strcmp(serd_node_string(sliced_type_lit), "Hallo")); @@ -515,11 +523,6 @@ test_literal(void) assert(datatype); 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_STRING("Plain"), SERD_EMPTY_STRING()); - assert(!strcmp(serd_node_string(plain_lit), "Plain")); - serd_node_free(plain_lit); } static void @@ -538,17 +541,17 @@ test_compare(void) SerdNode* xsd_short = serd_new_uri(SERD_STRING("http://www.w3.org/2001/XMLSchema#short")); - SerdNode* angst = - serd_new_plain_literal(SERD_STRING("angst"), SERD_EMPTY_STRING()); + SerdNode* angst = serd_new_string(SERD_STRING("angst")); - SerdNode* angst_de = - serd_new_plain_literal(SERD_STRING("angst"), SERD_STRING("de")); + SerdNode* angst_de = serd_new_literal( + SERD_STRING("angst"), SERD_HAS_LANGUAGE, SERD_STRING("de")); - SerdNode* angst_en = - serd_new_plain_literal(SERD_STRING("angst"), SERD_STRING("en")); + assert(angst_de); + SerdNode* angst_en = serd_new_literal( + SERD_STRING("angst"), SERD_HAS_LANGUAGE, SERD_STRING("en")); - SerdNode* hallo = - serd_new_plain_literal(SERD_STRING("Hallo"), SERD_STRING("de")); + SerdNode* hallo = serd_new_literal( + SERD_STRING("Hallo"), SERD_HAS_LANGUAGE, SERD_STRING("de")); SerdNode* hello = serd_new_string(SERD_STRING("Hello")); SerdNode* universe = serd_new_string(SERD_STRING("Universe")); diff --git a/test/test_node_syntax.c b/test/test_node_syntax.c index bb394c43..26b57ff1 100644 --- a/test/test_node_syntax.c +++ b/test/test_node_syntax.c @@ -53,11 +53,12 @@ test_common(const SerdSyntax syntax) assert(test(syntax, serd_new_string(SERD_STRING("node")), "\"node\"")); assert(test(syntax, - serd_new_plain_literal(SERD_STRING("hallo"), SERD_STRING("de")), + serd_new_literal( + SERD_STRING("hallo"), SERD_HAS_LANGUAGE, SERD_STRING("de")), "\"hallo\"@de")); assert(test(syntax, - serd_new_typed_literal(SERD_STRING("X"), datatype), + serd_new_literal(SERD_STRING("X"), SERD_HAS_DATATYPE, datatype), "\"X\"^^<http://example.org/Datatype>")); assert(test(syntax, serd_new_blank(SERD_STRING("blank")), "_:blank")); diff --git a/test/test_nodes.c b/test/test_nodes.c index 7e67eb30..74c99c11 100644 --- a/test/test_nodes.c +++ b/test/test_nodes.c @@ -88,7 +88,7 @@ test_plain_literal(void) SerdNodes* const nodes = serd_nodes_new(); const SerdNode* const node = - serd_nodes_plain_literal(nodes, string, language); + serd_nodes_literal(nodes, string, SERD_HAS_LANGUAGE, language); assert(node); assert(serd_node_type(node) == SERD_LITERAL); @@ -113,7 +113,7 @@ test_typed_literal(void) SerdNodes* const nodes = serd_nodes_new(); const SerdNode* const node = - serd_nodes_typed_literal(nodes, string, datatype); + serd_nodes_literal(nodes, string, SERD_HAS_DATATYPE, datatype); assert(node); assert(serd_node_type(node) == SERD_LITERAL); diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 0124784c..cab33ff5 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -81,10 +81,10 @@ test_writer(const char* const path) const SerdNode* const o = serd_nodes_string(nodes, SERD_STRING("o")); const SerdNode* const t = - serd_nodes_typed_literal(nodes, SERD_STRING("t"), urn_Type); + serd_nodes_literal(nodes, SERD_STRING("t"), SERD_HAS_DATATYPE, urn_Type); const SerdNode* const l = - serd_nodes_plain_literal(nodes, SERD_STRING("l"), en); + serd_nodes_literal(nodes, SERD_STRING("l"), SERD_HAS_LANGUAGE, en); const SerdNode* good[][3] = {{s, p, o}, {s, p, t}, {s, p, l}}; diff --git a/test/test_string.c b/test/test_string.c index 2f805015..1181de01 100644 --- a/test/test_string.c +++ b/test/test_string.c @@ -24,22 +24,10 @@ #endif #include <assert.h> -#include <stdint.h> #include <stdio.h> #include <string.h> static void -test_strlen(void) -{ - const uint8_t str[] = {'"', '5', 0xE2, 0x82, 0xAC, '"', '\n', 0}; - - SerdNodeFlags flags = 0; - size_t n_bytes = serd_strlen((const char*)str, &flags); - assert(n_bytes == 7 && flags == (SERD_HAS_QUOTE | SERD_HAS_NEWLINE)); - assert(serd_strlen((const char*)str, NULL) == 7); -} - -static void test_strerror(void) { const char* msg = serd_strerror(SERD_SUCCESS); @@ -78,7 +66,6 @@ main(int argc, char** argv) { (void)argc; - test_strlen(); test_strerror(); test_canonical_path(argv[0]); diff --git a/test/test_writer.c b/test/test_writer.c index c9a77354..fd650ecd 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -64,11 +64,17 @@ test_write_long_literal(void) const SerdNode* s = serd_nodes_uri(nodes, SERD_STRING("http://example.org/s")); + const SerdNode* p = serd_nodes_uri(nodes, SERD_STRING("http://example.org/p")); + const SerdNode* o = - serd_nodes_string(nodes, SERD_STRING("hello \"\"\"world\"\"\"!")); + serd_nodes_literal(nodes, + SERD_STRING("hello \"\"\"world\"\"\"!"), + SERD_IS_LONG, + SERD_EMPTY_STRING()); + assert(serd_node_flags(o) & SERD_IS_LONG); assert(!serd_sink_write(serd_writer_sink(writer), 0, s, p, o, NULL)); serd_writer_free(writer); |