diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_env.c | 191 |
1 files changed, 161 insertions, 30 deletions
diff --git a/test/test_env.c b/test/test_env.c index 445e9f28..18fda1a6 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -115,59 +115,183 @@ test_set_prefix(void) } static void -test_expand(void) +test_expand_untyped_literal(void) +{ + SerdNode* const untyped = serd_new_string(SERD_STATIC_STRING("data")); + SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + + SerdNode* const untyped_out = serd_env_expand(env, untyped); + assert(serd_node_equals(untyped_out, untyped)); + serd_node_free(untyped_out); + + serd_env_free(env); + serd_node_free(untyped); +} + +static void +test_expand_uri_datatype(void) { - static const SerdStringView eg = SERD_STATIC_STRING(NS_EG); static const SerdStringView type = SERD_STATIC_STRING("Type"); + static const SerdStringView base = SERD_STATIC_STRING("http://example.org/b/"); - SerdNode* const name = serd_new_string(SERD_STATIC_STRING("eg.1")); - SerdNode* const blank = serd_new_blank(SERD_STATIC_STRING("b1")); - SerdNode* const rel = serd_new_uri(SERD_STATIC_STRING("rel")); - SerdNode* const c1 = serd_new_curie(SERD_STATIC_STRING("eg.1:foo")); - SerdNode* const c1_full = - serd_new_uri(SERD_STATIC_STRING("http://example.org/foo")); - SerdNode* const c2 = serd_new_curie(SERD_STATIC_STRING("hm:what")); SerdNode* const typed = serd_new_typed_literal(SERD_STATIC_STRING("data"), type); + SerdEnv* const env = serd_env_new(base); - assert(!serd_env_set_prefix(env, serd_node_string_view(name), eg)); + SerdNode* const typed_out = serd_env_expand(env, typed); + assert(typed_out); + assert(!strcmp(serd_node_string(typed_out), "data")); - assert(!serd_env_expand(env, name)); - assert(!serd_env_expand(env, blank)); + const SerdNode* const datatype = serd_node_datatype(typed_out); + assert(datatype); + assert(!strcmp(serd_node_string(datatype), "http://example.org/b/Type")); + serd_node_free(typed_out); - // Expand CURIE - SerdNode* const c1_out = serd_env_expand(env, c1); - assert(serd_node_equals(c1_out, c1_full)); - serd_node_free(c1_out); + serd_env_free(env); + serd_node_free(typed); +} - // Expand relative URI - SerdNode* const rel_out = serd_env_expand(env, rel); - assert(!strcmp(serd_node_string(rel_out), "http://example.org/b/rel")); - serd_node_free(rel_out); +static void +test_expand_bad_uri_datatype(void) +{ + static const SerdStringView type = SERD_STATIC_STRING("Type"); + + SerdNode* const typed = + serd_new_typed_literal(SERD_STATIC_STRING("data"), type); + + SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + + assert(!serd_env_expand(env, typed)); + + serd_env_free(env); + serd_node_free(typed); +} + +static void +test_expand_curie_datatype(void) +{ +// FIXME +#if 0 + static const SerdStringView name = SERD_STATIC_STRING("eg"); + static const SerdStringView eg = SERD_STATIC_STRING(NS_EG); + static const SerdStringView type = SERD_STATIC_STRING("eg:Type"); + + SerdNode* const typed = + serd_new_typed_literal(SERD_STATIC_STRING("data"), type); + + SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + + assert(!serd_env_set_prefix(env, name, eg)); - // Expand literal with URI datatype SerdNode* const typed_out = serd_env_expand(env, typed); assert(typed_out); assert(!strcmp(serd_node_string(typed_out), "data")); const SerdNode* const datatype = serd_node_datatype(typed_out); assert(datatype); - assert(!strcmp(serd_node_string(datatype), "http://example.org/b/Type")); + assert(!strcmp(serd_node_string(datatype), "http://example.org/Type")); serd_node_free(typed_out); - assert(!serd_env_expand(env, c2)); + serd_env_free(env); + serd_node_free(typed); +#endif +} + +static void +test_expand_bad_curie_datatype(void) +{ + // FIXME +#if 0 + static const SerdStringView type = SERD_STATIC_STRING("eg:Type"); + + SerdNode* const typed = + serd_new_typed_literal(SERD_STATIC_STRING("data"), type); + + SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + + assert(!serd_env_expand(env, typed)); serd_env_free(env); serd_node_free(typed); - serd_node_free(c2); - serd_node_free(c1_full); - serd_node_free(c1); +#endif +} + +static void +test_expand_uri(void) +{ + static const SerdStringView base = + SERD_STATIC_STRING("http://example.org/b/"); + + SerdNode* const rel = serd_new_uri(SERD_STATIC_STRING("rel")); + SerdEnv* const env = serd_env_new(base); + SerdNode* const rel_out = serd_env_expand(env, rel); + + assert(!strcmp(serd_node_string(rel_out), "http://example.org/b/rel")); + serd_node_free(rel_out); + + serd_env_free(env); serd_node_free(rel); +} + +static void +test_expand_bad_uri(void) +{ + SerdNode* const bad_uri = serd_new_uri(SERD_STATIC_STRING("rel")); + SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + + assert(!serd_env_expand(env, bad_uri)); + + serd_env_free(env); + serd_node_free(bad_uri); +} + +static void +test_expand_curie(void) +{ + static const SerdStringView name = SERD_STATIC_STRING("eg.1"); + static const SerdStringView eg = SERD_STATIC_STRING(NS_EG); + + SerdNode* const curie = serd_new_curie(SERD_STATIC_STRING("eg.1:foo")); + SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + + assert(!serd_env_set_prefix(env, name, eg)); + + SerdNode* const curie_out = serd_env_expand(env, curie); + assert(curie_out); + assert(!strcmp(serd_node_string(curie_out), "http://example.org/foo")); + serd_node_free(curie_out); + + serd_env_free(env); + serd_node_free(curie); +} + +static void +test_expand_bad_curie(void) +{ + SerdNode* const curie = serd_new_curie(SERD_STATIC_STRING("eg.1:foo")); + SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + + assert(!serd_env_expand(env, curie)); + + serd_env_free(env); + serd_node_free(curie); +} + +static void +test_expand_blank(void) +{ + SerdNode* const blank = serd_new_blank(SERD_STATIC_STRING("b1")); + SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING()); + + SerdNode* const blank_out = serd_env_expand(env, blank); + assert(serd_node_equals(blank_out, blank)); + serd_node_free(blank_out); + + serd_env_free(env); serd_node_free(blank); - serd_node_free(name); } static void @@ -188,8 +312,6 @@ test_qualify(void) assert(!serd_env_set_prefix(env, serd_node_string_view(name), eg)); - assert(!serd_env_expand(env, name)); - SerdNode* const u1_out = serd_env_qualify(env, u1); assert(serd_node_equals(u1_out, c1)); serd_node_free(u1_out); @@ -246,7 +368,16 @@ main(void) test_null(); test_base_uri(); test_set_prefix(); - test_expand(); + test_expand_untyped_literal(); + test_expand_uri_datatype(); + test_expand_bad_uri_datatype(); + test_expand_curie_datatype(); + test_expand_bad_curie_datatype(); + test_expand_uri(); + test_expand_bad_uri(); + test_expand_curie(); + test_expand_bad_curie(); + test_expand_blank(); test_qualify(); test_equals(); return 0; |