From 94eeeadeb5be3d9c9266bed5d3c32c6ff29695b4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 20 Dec 2018 13:02:24 -0500 Subject: Add serd_node_compare() --- test/test_node.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'test') diff --git a/test/test_node.c b/test/test_node.c index 466655ef..72bd44e1 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -532,6 +532,56 @@ 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_integer = serd_new_integer(4, xsd_short); + SerdNode* blank = serd_new_blank(SERD_STRING("b1")); + SerdNode* uri = serd_new_uri(SERD_STRING("http://example.org/")); + + // 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_integer) < 0); + + serd_node_free(uri); + serd_node_free(blank); + serd_node_free(short_integer); + serd_node_free(integer); + 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) { @@ -552,6 +602,7 @@ main(void) test_simple_node(); test_literal(); test_blank(); + test_compare(); printf("Success\n"); return 0; -- cgit v1.2.1