diff options
author | David Robillard <d@drobilla.net> | 2021-07-22 15:26:22 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | 5e4538756d601e6a941c5290777af95ea8848e1a (patch) | |
tree | 9868e188a48a528e9908fcf695147f75790c3a56 /test/test_node.c | |
parent | 64024d0fa6a6dc048b2b846738846da597025f56 (diff) | |
download | serd-5e4538756d601e6a941c5290777af95ea8848e1a.tar.gz serd-5e4538756d601e6a941c5290777af95ea8848e1a.tar.bz2 serd-5e4538756d601e6a941c5290777af95ea8848e1a.zip |
[WIP] Preserve long or short quoting from input documents
Diffstat (limited to 'test/test_node.c')
-rw-r--r-- | test/test_node.c | 120 |
1 files changed, 63 insertions, 57 deletions
diff --git a/test/test_node.c b/test/test_node.c index 7d37cfe5..7bdc83ec 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -75,8 +75,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); @@ -162,8 +162,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); @@ -191,8 +191,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); @@ -235,8 +235,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); @@ -262,8 +262,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))); @@ -300,8 +300,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); @@ -364,8 +364,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); @@ -390,8 +390,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); @@ -429,7 +429,7 @@ test_node_from_string(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)); assert(!strcmp(serd_node_string_view(hello).data, "hello\"")); assert(serd_node_string_view(hello).length == 6); @@ -448,7 +448,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); @@ -467,46 +467,54 @@ check_copy_equals(const SerdNode* const node) static void test_literal(void) { - SerdNode* hello2 = serd_new_string(serd_string("hello\"")); + const SerdStringView hello_str = serd_string("hello"); + 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")); @@ -514,11 +522,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 @@ -537,17 +540,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")); @@ -555,11 +558,14 @@ test_compare(void) SerdNode* blank = serd_new_blank(serd_string("b1")); SerdNode* uri = serd_new_uri(serd_string("http://example.org/")); - SerdNode* aardvark = serd_new_typed_literal( - serd_string("alex"), serd_string("http://example.org/Aardvark")); + SerdNode* aardvark = + serd_new_literal(serd_string("alex"), + SERD_HAS_DATATYPE, + serd_string("http://example.org/Aardvark")); - SerdNode* badger = serd_new_typed_literal( - serd_string("bobby"), serd_string("http://example.org/Badger")); + SerdNode* badger = serd_new_literal(serd_string("bobby"), + SERD_HAS_DATATYPE, + serd_string("http://example.org/Badger")); // Types are ordered according to their SerdNodeType (more or less arbitrary) assert(serd_node_compare(hello, uri) < 0); |