diff options
author | David Robillard <d@drobilla.net> | 2018-06-13 21:32:11 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-27 13:13:58 +0100 |
commit | 9baa0127ea016c3ee409a64563b960cff135bbdb (patch) | |
tree | 6e06baf34fe52cdd02eaae3ee31c8f90eb0ef483 /tests | |
parent | bcd9ce4800688e3b53cc198d26e2e44627a2ec7a (diff) | |
download | serd-9baa0127ea016c3ee409a64563b960cff135bbdb.tar.gz serd-9baa0127ea016c3ee409a64563b960cff135bbdb.tar.bz2 serd-9baa0127ea016c3ee409a64563b960cff135bbdb.zip |
Simplify SerdEnv API
Diffstat (limited to 'tests')
-rw-r--r-- | tests/env_test.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/tests/env_test.c b/tests/env_test.c index 07e3700e..e507bfc9 100644 --- a/tests/env_test.c +++ b/tests/env_test.c @@ -37,40 +37,42 @@ test_env(void) SerdWorld* world = serd_world_new(); SerdNode* hello = serd_new_string("hello\""); - SerdNode* u = serd_new_uri("http://example.org/foo"); + SerdNode* eg = serd_new_uri("http://example.org/"); + SerdNode* foo_u = serd_new_uri("http://example.org/foo"); + SerdNode* foo_c = serd_new_curie("eg.2:foo"); SerdNode* b = serd_new_curie("invalid"); - SerdNode* c = serd_new_curie("eg.2:b"); - SerdNode* s = serd_new_string("hello"); + SerdNode* pre = serd_new_curie("eg.2"); SerdEnv* env = serd_env_new(NULL); - serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/"); + serd_env_set_prefix(env, pre, eg); assert(!serd_env_base_uri(env)); assert(serd_env_set_base_uri(env, NULL)); assert(!serd_env_base_uri(env)); assert(serd_env_set_base_uri(env, hello)); assert(!serd_env_base_uri(env)); - serd_node_free(hello); - SerdStringView prefix; - SerdStringView suffix; - assert(serd_env_expand(env, b, &prefix, &suffix)); + SerdNode* xnode = serd_env_expand(env, hello); + assert(!xnode); - assert(!serd_env_expand_node(env, b)); - assert(!serd_env_expand_node(env, s)); + assert(!serd_env_expand(env, b)); + assert(!serd_env_expand(env, hello)); - assert(serd_env_set_base_uri(NULL, u)); + assert(serd_env_set_base_uri(NULL, eg)); assert(serd_env_set_base_uri(env, NULL)); - SerdNode* xu = serd_env_expand_node(env, u); + serd_node_free(hello); + + 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("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); assert(serd_env_set_prefix(env, NULL, NULL)); @@ -79,24 +81,27 @@ test_env(void) assert(serd_env_set_prefix(env, b, lit)); SerdNode* blank = serd_new_blank("b1"); - assert(!serd_env_expand_node(env, blank)); + assert(!serd_env_expand(env, blank)); serd_node_free(blank); int n_prefixes = 0; - serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/"); + serd_env_set_prefix(env, pre, eg); serd_env_foreach(env, count_prefixes, &n_prefixes); assert(n_prefixes == 1); - SerdNode* shorter_uri = serd_new_uri("urn:foo"); - const SerdNode* prefix_name = NULL; - assert(!serd_env_qualify(env, shorter_uri, &prefix_name, &suffix)); + SerdNode* shorter_uri = serd_new_uri("urn:foo"); + assert(!serd_env_qualify(env, shorter_uri)); serd_node_free(shorter_uri); + + SerdNode* qualified = serd_env_qualify(env, foo_u); + assert(serd_node_equals(qualified, foo_c)); + serd_node_free(qualified); + serd_node_free(foo_c); + serd_node_free(foo_u); serd_node_free(lit); - serd_node_free(badpre); - serd_node_free(s); - serd_node_free(c); serd_node_free(b); - serd_node_free(u); + serd_node_free(pre); + serd_node_free(eg); serd_env_free(env); serd_world_free(world); |