diff options
author | David Robillard <d@drobilla.net> | 2018-02-04 15:33:36 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 16:27:02 -0500 |
commit | c644f404054e6d68f3bb645cf93b8ad1501b8938 (patch) | |
tree | 6291623c37dd9ef6be062113bf6ac5afa8115171 /test/test_env.c | |
parent | b0d4ae792c88cc55f9cc9a579530a1a13a158fda (diff) | |
download | serd-c644f404054e6d68f3bb645cf93b8ad1501b8938.tar.gz serd-c644f404054e6d68f3bb645cf93b8ad1501b8938.tar.bz2 serd-c644f404054e6d68f3bb645cf93b8ad1501b8938.zip |
Make nodes opaque
Diffstat (limited to 'test/test_env.c')
-rw-r--r-- | test/test_env.c | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/test/test_env.c b/test/test_env.c index 8ef95f1a..198c7e9b 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -24,64 +24,68 @@ count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri) static void test_env(void) { - SerdNode u = serd_node_from_string(SERD_URI, "http://example.org/foo"); - SerdNode b = serd_node_from_string(SERD_CURIE, "invalid"); - SerdNode c = serd_node_from_string(SERD_CURIE, "eg.2:b"); - SerdEnv* env = serd_env_new(NULL); + SerdNode* u = serd_new_string(SERD_URI, "http://example.org/foo"); + SerdNode* b = serd_new_string(SERD_CURIE, "invalid"); + SerdNode* c = serd_new_string(SERD_CURIE, "eg.2:b"); + SerdNode* s = serd_new_string(SERD_LITERAL, "hello"); + SerdEnv* env = serd_env_new(NULL); serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/"); - assert(!serd_env_set_base_uri(env, NULL)); - assert(serd_env_set_base_uri(env, &SERD_NODE_NULL)); - assert(serd_node_equals(serd_env_base_uri(env, NULL), &SERD_NODE_NULL)); + assert(!serd_env_new(s)); - SerdStringView prefix; - SerdStringView suffix; - assert(!serd_env_qualify(NULL, &u, &u, &suffix)); - assert(serd_env_expand(NULL, &c, &prefix, &suffix)); - assert(serd_env_expand(env, &b, &prefix, &suffix)); + const SerdNode* prefix_node = NULL; + SerdStringView prefix = serd_empty_string(); + SerdStringView suffix = serd_empty_string(); - SerdNode nxnode = serd_env_expand_node(NULL, &c); - assert(serd_node_equals(&nxnode, &SERD_NODE_NULL)); + assert(!serd_env_qualify(NULL, u, &prefix_node, &suffix)); - SerdNode xnode = serd_env_expand_node(env, &SERD_NODE_NULL); - assert(serd_node_equals(&xnode, &SERD_NODE_NULL)); + assert(serd_env_expand(env, NULL, &prefix, &suffix) == SERD_BAD_CURIE); - SerdNode xu = serd_env_expand_node(env, &u); - assert(!strcmp(xu.buf, "http://example.org/foo")); - serd_node_free(&xu); + assert(!serd_env_expand_node(NULL, u)); + assert(!serd_env_expand_node(env, b)); + assert(!serd_env_expand_node(env, s)); - SerdNode badpre = serd_node_from_string(SERD_CURIE, "hm:what"); - SerdNode xbadpre = serd_env_expand_node(env, &badpre); - assert(serd_node_equals(&xbadpre, &SERD_NODE_NULL)); + assert(!serd_env_set_base_uri(env, NULL)); - SerdNode xc = serd_env_expand_node(env, &c); - assert(!strcmp(xc.buf, "http://example.org/b")); - serd_node_free(&xc); + SerdNode* xu = serd_env_expand_node(env, u); + assert(!strcmp(serd_node_string(xu), "http://example.org/foo")); + serd_node_free(xu); - assert(serd_env_set_prefix(env, &SERD_NODE_NULL, &SERD_NODE_NULL)); + SerdNode* badpre = serd_new_string(SERD_CURIE, "hm:what"); + SerdNode* xbadpre = serd_env_expand_node(env, badpre); + assert(!xbadpre); - const SerdNode lit = serd_node_from_string(SERD_LITERAL, "hello"); - assert(serd_env_set_prefix(env, &b, &lit)); + SerdNode* xc = serd_env_expand_node(env, c); + assert(!strcmp(serd_node_string(xc), "http://example.org/b")); + serd_node_free(xc); - assert(!serd_env_new(&lit)); + SerdNode* lit = serd_new_string(SERD_LITERAL, "hello"); + assert(serd_env_set_prefix(env, b, lit)); - const SerdNode blank = serd_node_from_string(SERD_BLANK, "b1"); - const SerdNode xblank = serd_env_expand_node(env, &blank); - assert(serd_node_equals(&xblank, &SERD_NODE_NULL)); + SerdNode* blank = serd_new_string(SERD_BLANK, "b1"); + assert(!serd_env_expand_node(env, blank)); + serd_node_free(blank); int n_prefixes = 0; serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/"); serd_env_foreach(env, count_prefixes, &n_prefixes); assert(n_prefixes == 1); - SerdNode shorter_uri = serd_node_from_string(SERD_URI, "urn:foo"); - SerdNode prefix_name; - assert(!serd_env_qualify(env, &shorter_uri, &prefix_name, &suffix)); + SerdNode* shorter_uri = serd_new_string(SERD_URI, "urn:foo"); + assert(!serd_env_qualify(env, shorter_uri, &prefix_node, &suffix)); - assert(!serd_env_set_base_uri(env, &u)); - assert(serd_node_equals(serd_env_base_uri(env, NULL), &u)); + assert(!serd_env_set_base_uri(env, u)); + assert(serd_node_equals(serd_env_base_uri(env, NULL), u)); assert(!serd_env_set_base_uri(env, NULL)); - assert(!serd_env_base_uri(env, NULL)->buf); + assert(!serd_env_base_uri(env, NULL)); + + serd_node_free(shorter_uri); + 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_env_free(env); } |