diff options
Diffstat (limited to 'test/test_env.c')
-rw-r--r-- | test/test_env.c | 85 |
1 files changed, 45 insertions, 40 deletions
diff --git a/test/test_env.c b/test/test_env.c index 31446f69..4f947246 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -26,25 +26,30 @@ count_prefixes(void* handle, const SerdEvent* event) static void test_env(void) { - SerdNode* u = serd_new_uri(serd_string("http://example.org/foo")); - SerdNode* b = serd_new_curie(serd_string("invalid")); - SerdNode* e = serd_new_uri(serd_empty_string()); - SerdNode* c = serd_new_curie(serd_string("eg.2:b")); - SerdNode* s = serd_new_string(serd_string("hello")); - SerdEnv* env = serd_env_new(serd_empty_string()); + const SerdStringView prefix = serd_string("eg.2"); + const SerdStringView eg = serd_string("http://example.org/"); - const SerdNode* prefix_node = NULL; - SerdStringView prefix = serd_empty_string(); - SerdStringView suffix = serd_empty_string(); + SerdNode* hello = serd_new_string(serd_string("hello\"")); + SerdNode* rel = serd_new_uri(serd_string("rel")); + SerdNode* foo_u = serd_new_uri(serd_string("http://example.org/foo")); + SerdNode* foo_c = serd_new_curie(serd_string("eg.2:foo")); + SerdNode* b = serd_new_curie(serd_string("invalid")); - assert(!serd_env_qualify(NULL, u, &prefix_node, &suffix)); + SerdEnv* env = serd_env_new(serd_empty_string()); - assert(serd_env_expand(env, NULL, &prefix, &suffix) == SERD_BAD_CURIE); + serd_env_set_prefix(env, prefix, eg); + + assert(!serd_env_base_uri(NULL)); + assert(!serd_env_expand(NULL, NULL)); + assert(!serd_env_expand(NULL, foo_c)); + assert(!serd_env_expand(env, NULL)); + assert(!serd_env_qualify(NULL, NULL)); + assert(!serd_env_qualify(env, NULL)); + assert(!serd_env_qualify(NULL, foo_u)); assert(!serd_env_base_uri(env)); assert(!serd_env_set_base_uri(env, serd_empty_string())); assert(!serd_env_base_uri(env)); - assert(!serd_env_base_uri(env)); serd_env_set_prefix( env, serd_string("eg.2"), serd_string("http://example.org/")); @@ -52,61 +57,61 @@ test_env(void) assert(serd_env_set_prefix(env, serd_string("eg.3"), serd_string("rel")) == SERD_BAD_ARG); - assert(!serd_env_expand_node(NULL, u)); - assert(!serd_env_expand_node(env, b)); - assert(!serd_env_expand_node(env, s)); - assert(!serd_env_expand_node(env, e)); + SerdNode* xnode = serd_env_expand(env, hello); + assert(!xnode); + + assert(!serd_env_expand(env, b)); + assert(!serd_env_expand(env, hello)); assert(!serd_env_set_base_uri(env, serd_empty_string())); - SerdNode* xu = serd_env_expand_node(env, u); + SerdNode* xu = serd_env_expand(env, foo_c); assert(!strcmp(serd_node_string(xu), "http://example.org/foo")); serd_node_free(xu); SerdNode* badpre = serd_new_curie(serd_string("hm:what")); - SerdNode* xbadpre = serd_env_expand_node(env, badpre); + SerdNode* xbadpre = serd_env_expand(env, badpre); assert(!xbadpre); + serd_node_free(badpre); - SerdNode* xc = serd_env_expand_node(env, c); - assert(!strcmp(serd_node_string(xc), "http://example.org/b")); + SerdNode* xc = serd_env_expand(env, foo_c); + assert(serd_node_equals(xc, foo_u)); serd_node_free(xc); SerdNode* blank = serd_new_blank(serd_string("b1")); - assert(!serd_env_expand_node(env, blank)); + assert(!serd_env_expand(env, blank)); serd_node_free(blank); size_t n_prefixes = 0; SerdSink* const count_prefixes_sink = serd_sink_new(&n_prefixes, count_prefixes, NULL); - serd_env_set_prefix( - env, serd_string("eg.2"), serd_string("http://example.org/")); + serd_env_set_prefix(env, prefix, eg); serd_env_write_prefixes(env, count_prefixes_sink); assert(n_prefixes == 1); - SerdNode* shorter_uri = serd_new_uri(serd_string("urn:foo")); - assert(!serd_env_qualify(env, shorter_uri, &prefix_node, &suffix)); + SerdNode* qualified = serd_env_qualify(env, foo_u); + assert(serd_node_equals(qualified, foo_c)); + serd_node_free(qualified); - assert(!serd_env_set_base_uri(env, serd_node_string_view(u))); - assert(serd_node_equals(serd_env_base_uri(env), u)); + SerdNode* unqualifiable = serd_new_uri(serd_string("http://drobilla.net/")); + assert(!serd_env_qualify(env, unqualifiable)); + serd_node_free(unqualifiable); - SerdNode* xe = serd_env_expand_node(env, e); - assert(xe); - assert(!strcmp(serd_node_string(xe), "http://example.org/foo")); - serd_node_free(xe); + assert(!serd_env_expand(env, rel)); + serd_env_set_base_uri(env, serd_string("http://example.org/base/")); - assert(!serd_env_set_base_uri(env, serd_empty_string())); - assert(!serd_env_base_uri(env)); + SerdNode* xrel = serd_env_expand(env, rel); + assert(xrel); + assert(!strcmp(serd_node_string(xrel), "http://example.org/base/rel")); + serd_node_free(xrel); serd_sink_free(count_prefixes_sink); - serd_node_free(shorter_uri); - serd_node_free(badpre); - serd_node_free(s); - serd_node_free(c); - serd_node_free(e); serd_node_free(b); - serd_node_free(u); - + serd_node_free(foo_c); + serd_node_free(foo_u); + serd_node_free(rel); + serd_node_free(hello); serd_env_free(env); } |