diff options
author | David Robillard <d@drobilla.net> | 2018-12-20 13:02:24 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:07 -0500 |
commit | d1ba721d37af61f2b529faaa16bd20ba1e161b06 (patch) | |
tree | 2930f07857d5416eb193fe8afbcc4adecdc2e7ea /test/test_node.c | |
parent | 08a3b8a18093d1623309f5f406865f51e7bff39a (diff) | |
download | serd-d1ba721d37af61f2b529faaa16bd20ba1e161b06.tar.gz serd-d1ba721d37af61f2b529faaa16bd20ba1e161b06.tar.bz2 serd-d1ba721d37af61f2b529faaa16bd20ba1e161b06.zip |
Add serd_node_compare()
Diffstat (limited to 'test/test_node.c')
-rw-r--r-- | test/test_node.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/test_node.c b/test/test_node.c index ab0ceca8..3db0a46f 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -531,6 +531,65 @@ test_blank(void) serd_node_free(blank); } +static void +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_de = + serd_new_plain_literal(serd_string("angst"), serd_string("de")); + + SerdNode* angst_en = + serd_new_plain_literal(serd_string("angst"), serd_string("en")); + + SerdNode* hallo = + serd_new_plain_literal(serd_string("Hallo"), serd_string("de")); + + SerdNode* hello = serd_new_string(serd_string("Hello")); + SerdNode* universe = serd_new_string(serd_string("Universe")); + SerdNode* integer = serd_new_integer(4, NULL); + SerdNode* short_int = serd_new_integer(4, xsd_short); + 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* badger = serd_new_typed_literal( + serd_string("bobby"), serd_string("http://example.org/Badger")); + + // Types are ordered according to their SerdNodeType (more or less arbitrary) + assert(serd_node_compare(hello, uri) < 0); + assert(serd_node_compare(uri, blank) < 0); + + // If the types are the same, then strings are compared + assert(serd_node_compare(hello, universe) < 0); + + // If literal strings are the same, languages or datatypes are compared + assert(serd_node_compare(angst, angst_de) < 0); + assert(serd_node_compare(angst_de, angst_en) < 0); + assert(serd_node_compare(integer, short_int) < 0); + assert(serd_node_compare(aardvark, badger) < 0); + + serd_node_free(uri); + serd_node_free(blank); + serd_node_free(short_int); + serd_node_free(integer); + serd_node_free(badger); + serd_node_free(aardvark); + serd_node_free(universe); + serd_node_free(hello); + serd_node_free(hallo); + serd_node_free(angst_en); + serd_node_free(angst_de); + serd_node_free(angst); + serd_node_free(xsd_short); +} + int main(void) { @@ -550,6 +609,7 @@ main(void) test_node_from_substring(); test_literal(); test_blank(); + test_compare(); printf("Success\n"); return 0; |