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.c77
1 files changed, 42 insertions, 35 deletions
diff --git a/test/test_node_syntax.c b/test/test_node_syntax.c
index a8e0a163..47b67c9f 100644
--- a/test/test_node_syntax.c
+++ b/test/test_node_syntax.c
@@ -29,7 +29,8 @@ test_failed_alloc(void)
{
SerdFailingAllocator allocator = serd_failing_allocator();
- SerdNode* const node = serd_new_string(&allocator.base, SERD_STRING("node"));
+ SerdNode* const node =
+ serd_new_token(&allocator.base, SERD_LITERAL, SERD_STRING("node"));
// Successfully convert a node to count the number of allocations
@@ -54,8 +55,8 @@ test_failed_alloc(void)
assert(!s || !c);
- serd_free(&allocator.base, s);
serd_node_free(&allocator.base, c);
+ serd_free(&allocator.base, s);
}
serd_node_free(&allocator.base, copy);
@@ -64,10 +65,10 @@ test_failed_alloc(void)
}
static bool
-check(SerdWorld* const world,
- const SerdSyntax syntax,
- SerdNode* const node,
- const char* const expected)
+check(SerdWorld* const world,
+ const SerdSyntax syntax,
+ const SerdNode* const node,
+ const char* const expected)
{
SerdEnv* const env =
serd_env_new(world, SERD_STRING("http://example.org/base/"));
@@ -79,7 +80,6 @@ check(SerdWorld* const world,
serd_node_free(serd_world_allocator(world), copy);
serd_free(serd_world_allocator(world), str);
- serd_node_free(NULL, node);
serd_env_free(env);
return success;
}
@@ -92,69 +92,74 @@ test_common(SerdWorld* const world, const SerdSyntax syntax)
static const SerdStringView datatype =
SERD_STRING("http://example.org/Datatype");
+ SerdNodes* const nodes = serd_nodes_new(NULL);
+
assert(check(
- world, syntax, serd_new_string(NULL, SERD_STRING("node")), "\"node\""));
+ world, syntax, serd_nodes_string(nodes, SERD_STRING("node")), "\"node\""));
assert(
check(world,
syntax,
- serd_new_literal(
- NULL, SERD_STRING("hallo"), SERD_HAS_LANGUAGE, SERD_STRING("de")),
+ serd_nodes_literal(
+ nodes, SERD_STRING("hallo"), SERD_HAS_LANGUAGE, SERD_STRING("de")),
"\"hallo\"@de"));
- assert(
- check(world,
- syntax,
- serd_new_literal(NULL, SERD_STRING("X"), SERD_HAS_DATATYPE, datatype),
- "\"X\"^^<http://example.org/Datatype>"));
+ assert(check(
+ world,
+ syntax,
+ serd_nodes_literal(nodes, SERD_STRING("X"), SERD_HAS_DATATYPE, datatype),
+ "\"X\"^^<http://example.org/Datatype>"));
assert(check(world,
syntax,
- serd_new_token(NULL, SERD_BLANK, SERD_STRING("blank")),
+ serd_nodes_token(nodes, SERD_BLANK, SERD_STRING("blank")),
"_:blank"));
assert(check(world,
syntax,
- serd_new_token(NULL, SERD_BLANK, SERD_STRING("b0")),
+ serd_nodes_token(nodes, SERD_BLANK, SERD_STRING("b0")),
"_:b0"));
assert(check(world,
syntax,
- serd_new_token(NULL, SERD_BLANK, SERD_STRING("named1")),
+ serd_nodes_token(nodes, SERD_BLANK, SERD_STRING("named1")),
"_:named1"));
assert(check(world,
syntax,
- serd_new_uri(NULL, SERD_STRING("http://example.org/")),
+ serd_nodes_uri(nodes, SERD_STRING("http://example.org/")),
"<http://example.org/>"));
assert(check(world,
syntax,
- serd_new_value(NULL, serd_double(1.25)),
+ serd_nodes_value(nodes, serd_double(1.25)),
"\"1.25E0\"^^<http://www.w3.org/2001/XMLSchema#double>"));
assert(check(world,
syntax,
- serd_new_value(NULL, serd_float(1.25f)),
+ serd_nodes_value(nodes, serd_float(1.25f)),
"\"1.25E0\"^^<http://www.w3.org/2001/XMLSchema#float>"));
assert(
check(world,
syntax,
- serd_new_base64(NULL, data, sizeof(data)),
+ serd_nodes_base64(nodes, data, sizeof(data)),
"\"BAAAAAIAAAA=\"^^<http://www.w3.org/2001/XMLSchema#base64Binary>"));
+
+ serd_nodes_free(nodes);
}
static void
test_ntriples(void)
{
SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_nodes_new(NULL);
test_common(world, SERD_NTRIPLES);
{
// No relative URIs in NTriples, so converting one fails without an env
- SerdNode* const rel = serd_new_uri(NULL, SERD_STRING("rel/uri"));
+ const SerdNode* const rel = serd_nodes_uri(nodes, SERD_STRING("rel/uri"));
assert(!serd_node_to_syntax(NULL, rel, SERD_NTRIPLES, NULL));
assert(!serd_node_from_syntax(NULL, "<rel/uri>", SERD_NTRIPLES, NULL));
@@ -171,29 +176,29 @@ test_ntriples(void)
serd_node_free(serd_world_allocator(world), copy);
serd_env_free(env);
serd_free(serd_world_allocator(world), str);
- serd_node_free(NULL, rel);
}
assert(check(world,
SERD_NTRIPLES,
- serd_new_decimal(NULL, 1.25),
+ serd_nodes_decimal(nodes, 1.25),
"\"1.25\"^^<http://www.w3.org/2001/XMLSchema#decimal>"));
assert(check(world,
SERD_NTRIPLES,
- serd_new_integer(NULL, 1234),
+ serd_nodes_integer(nodes, 1234),
"\"1234\"^^<http://www.w3.org/2001/XMLSchema#integer>"));
assert(check(world,
SERD_NTRIPLES,
- serd_new_value(NULL, serd_bool(true)),
+ serd_nodes_value(nodes, serd_bool(true)),
"\"true\"^^<http://www.w3.org/2001/XMLSchema#boolean>"));
assert(check(world,
SERD_NTRIPLES,
- serd_new_value(NULL, serd_bool(false)),
+ serd_nodes_value(nodes, serd_bool(false)),
"\"false\"^^<http://www.w3.org/2001/XMLSchema#boolean>"));
+ serd_nodes_free(nodes);
serd_world_free(world);
}
@@ -201,22 +206,24 @@ static void
test_turtle(void)
{
SerdWorld* const world = serd_world_new(NULL);
+ SerdNodes* const nodes = serd_world_nodes(world);
test_common(world, SERD_TURTLE);
check(world,
SERD_TURTLE,
- serd_new_uri(NULL, SERD_STRING("rel/uri")),
+ serd_nodes_uri(nodes, SERD_STRING("rel/uri")),
"<rel/uri>");
- assert(check(world, SERD_TURTLE, serd_new_decimal(NULL, 1.25), "1.25"));
- assert(check(world, SERD_TURTLE, serd_new_integer(NULL, 1234), "1234"));
+ assert(check(world, SERD_TURTLE, serd_nodes_decimal(nodes, 1.25), "1.25"));
- assert(
- check(world, SERD_TURTLE, serd_new_value(NULL, serd_bool(true)), "true"));
+ assert(check(world, SERD_TURTLE, serd_nodes_integer(nodes, 1234), "1234"));
- assert(
- check(world, SERD_TURTLE, serd_new_value(NULL, serd_bool(false)), "false"));
+ assert(check(
+ world, SERD_TURTLE, serd_nodes_value(nodes, serd_bool(true)), "true"));
+
+ assert(check(
+ world, SERD_TURTLE, serd_nodes_value(nodes, serd_bool(false)), "false"));
serd_world_free(world);
}