aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_node_syntax.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_node_syntax.c')
-rw-r--r--test/test_node_syntax.c156
1 files changed, 94 insertions, 62 deletions
diff --git a/test/test_node_syntax.c b/test/test_node_syntax.c
index 9875e656..d9b0afbb 100644
--- a/test/test_node_syntax.c
+++ b/test/test_node_syntax.c
@@ -20,13 +20,17 @@
#include <assert.h>
#include <stdbool.h>
-#include <stdio.h>
#include <string.h>
static bool
-test(const SerdSyntax syntax, SerdNode* const node, const char* const expected)
+check(SerdWorld* const world,
+ const SerdSyntax syntax,
+ SerdNode* const node,
+ const char* const expected)
{
- SerdEnv* const env = serd_env_new(SERD_STRING("http://example.org/base/"));
+ SerdEnv* const env =
+ serd_env_new(world, SERD_STRING("http://example.org/base/"));
+
char* const str = serd_node_to_syntax(node, syntax, env);
SerdNode* const copy = serd_node_from_syntax(str, syntax, env);
@@ -40,7 +44,7 @@ test(const SerdSyntax syntax, SerdNode* const node, const char* const expected)
}
static void
-test_common(const SerdSyntax syntax)
+test_common(SerdWorld* const world, const SerdSyntax syntax)
{
static const int data[] = {4, 2};
@@ -50,51 +54,66 @@ test_common(const SerdSyntax syntax)
static const SerdStringView num_type =
SERD_STRING("http://example.org/Decimal");
- assert(test(syntax, serd_new_string(SERD_STRING("node")), "\"node\""));
-
- assert(test(syntax,
- serd_new_literal(
- SERD_STRING("hallo"), SERD_HAS_LANGUAGE, SERD_STRING("de")),
- "\"hallo\"@de"));
-
- assert(test(syntax,
- serd_new_literal(SERD_STRING("X"), SERD_HAS_DATATYPE, datatype),
- "\"X\"^^<http://example.org/Datatype>"));
-
assert(
- test(syntax, serd_new_token(SERD_BLANK, SERD_STRING("blank")), "_:blank"));
-
- assert(test(syntax, serd_new_token(SERD_BLANK, SERD_STRING("b0")), "_:b0"));
-
- assert(test(
- syntax, serd_new_token(SERD_BLANK, SERD_STRING("named1")), "_:named1"));
-
- assert(test(syntax,
- serd_new_uri(SERD_STRING("http://example.org/")),
- "<http://example.org/>"));
-
- assert(test(syntax,
- serd_new_double(1.25),
- "\"1.25E0\"^^<http://www.w3.org/2001/XMLSchema#double>"));
-
- assert(test(syntax,
- serd_new_float(1.25),
- "\"1.25E0\"^^<http://www.w3.org/2001/XMLSchema#float>"));
-
- assert(test(syntax,
- serd_new_integer(1234, num_type),
- "\"1234\"^^<http://example.org/Decimal>"));
+ check(world, syntax, serd_new_string(SERD_STRING("node")), "\"node\""));
+
+ assert(check(world,
+ syntax,
+ serd_new_literal(
+ SERD_STRING("hallo"), SERD_HAS_LANGUAGE, SERD_STRING("de")),
+ "\"hallo\"@de"));
+
+ assert(check(world,
+ syntax,
+ serd_new_literal(SERD_STRING("X"), SERD_HAS_DATATYPE, datatype),
+ "\"X\"^^<http://example.org/Datatype>"));
+
+ assert(check(world,
+ syntax,
+ serd_new_token(SERD_BLANK, SERD_STRING("blank")),
+ "_:blank"));
+
+ assert(check(
+ world, syntax, serd_new_token(SERD_BLANK, SERD_STRING("b0")), "_:b0"));
+
+ assert(check(world,
+ syntax,
+ serd_new_token(SERD_BLANK, SERD_STRING("named1")),
+ "_:named1"));
+
+ assert(check(world,
+ syntax,
+ serd_new_uri(SERD_STRING("http://example.org/")),
+ "<http://example.org/>"));
+
+ assert(check(world,
+ syntax,
+ serd_new_double(1.25),
+ "\"1.25E0\"^^<http://www.w3.org/2001/XMLSchema#double>"));
+
+ assert(check(world,
+ syntax,
+ serd_new_float(1.25),
+ "\"1.25E0\"^^<http://www.w3.org/2001/XMLSchema#float>"));
+
+ assert(check(world,
+ syntax,
+ serd_new_integer(1234, num_type),
+ "\"1234\"^^<http://example.org/Decimal>"));
assert(
- test(syntax,
- serd_new_base64(data, sizeof(data), SERD_EMPTY_STRING()),
- "\"BAAAAAIAAAA=\"^^<http://www.w3.org/2001/XMLSchema#base64Binary>"));
+ check(world,
+ syntax,
+ serd_new_base64(data, sizeof(data), SERD_EMPTY_STRING()),
+ "\"BAAAAAIAAAA=\"^^<http://www.w3.org/2001/XMLSchema#base64Binary>"));
}
static void
test_ntriples(void)
{
- test_common(SERD_NTRIPLES);
+ SerdWorld* const world = serd_world_new();
+
+ test_common(world, SERD_NTRIPLES);
{
// No relative URIs in NTriples, so converting one fails without an env
@@ -103,11 +122,13 @@ test_ntriples(void)
assert(!serd_node_from_syntax("<rel/uri>", SERD_NTRIPLES, NULL));
// If a relative URI can be expanded then all's well
- SerdEnv* const env = serd_env_new(SERD_STRING("http://example.org/base/"));
- char* const str = serd_node_to_syntax(rel, SERD_NTRIPLES, env);
+ SerdEnv* const env =
+ serd_env_new(world, SERD_STRING("http://example.org/base/"));
+ char* const str = serd_node_to_syntax(rel, SERD_NTRIPLES, env);
assert(!strcmp(str, "<http://example.org/base/rel/uri>"));
SerdNode* const copy = serd_node_from_syntax(str, SERD_NTRIPLES, env);
+
assert(!strcmp(serd_node_string(copy), "http://example.org/base/rel/uri"));
serd_node_free(copy);
@@ -116,21 +137,27 @@ test_ntriples(void)
serd_node_free(rel);
}
- assert(test(SERD_NTRIPLES,
- serd_new_decimal(1.25),
- "\"1.25\"^^<http://www.w3.org/2001/XMLSchema#decimal>"));
+ assert(check(world,
+ SERD_NTRIPLES,
+ serd_new_decimal(1.25),
+ "\"1.25\"^^<http://www.w3.org/2001/XMLSchema#decimal>"));
- assert(test(SERD_NTRIPLES,
- serd_new_integer(1234, SERD_EMPTY_STRING()),
- "\"1234\"^^<http://www.w3.org/2001/XMLSchema#integer>"));
+ assert(check(world,
+ SERD_NTRIPLES,
+ serd_new_integer(1234, SERD_EMPTY_STRING()),
+ "\"1234\"^^<http://www.w3.org/2001/XMLSchema#integer>"));
- assert(test(SERD_NTRIPLES,
- serd_new_boolean(true),
- "\"true\"^^<http://www.w3.org/2001/XMLSchema#boolean>"));
+ assert(check(world,
+ SERD_NTRIPLES,
+ serd_new_boolean(true),
+ "\"true\"^^<http://www.w3.org/2001/XMLSchema#boolean>"));
- assert(test(SERD_NTRIPLES,
- serd_new_boolean(false),
- "\"false\"^^<http://www.w3.org/2001/XMLSchema#boolean>"));
+ assert(check(world,
+ SERD_NTRIPLES,
+ serd_new_boolean(false),
+ "\"false\"^^<http://www.w3.org/2001/XMLSchema#boolean>"));
+
+ serd_world_free(world);
}
static void
@@ -139,19 +166,24 @@ test_turtle(void)
static const SerdStringView xsd_integer =
SERD_STRING("http://www.w3.org/2001/XMLSchema#integer");
- test_common(SERD_TURTLE);
+ SerdWorld* const world = serd_world_new();
+
+ test_common(world, SERD_TURTLE);
+
+ check(world, SERD_TURTLE, serd_new_uri(SERD_STRING("rel/uri")), "<rel/uri>");
- test(SERD_TURTLE, serd_new_uri(SERD_STRING("rel/uri")), "<rel/uri>");
+ assert(check(world, SERD_TURTLE, serd_new_decimal(1.25), "1.25"));
- assert(test(SERD_TURTLE, serd_new_decimal(1.25), "1.25"));
+ assert(check(
+ world, SERD_TURTLE, serd_new_integer(1234, SERD_EMPTY_STRING()), "1234"));
assert(
- test(SERD_TURTLE, serd_new_integer(1234, SERD_EMPTY_STRING()), "1234"));
+ check(world, SERD_TURTLE, serd_new_integer(1234, xsd_integer), "1234"));
- assert(test(SERD_TURTLE, serd_new_integer(1234, xsd_integer), "1234"));
+ assert(check(world, SERD_TURTLE, serd_new_boolean(true), "true"));
+ assert(check(world, SERD_TURTLE, serd_new_boolean(false), "false"));
- assert(test(SERD_TURTLE, serd_new_boolean(true), "true"));
- assert(test(SERD_TURTLE, serd_new_boolean(false), "false"));
+ serd_world_free(world);
}
int