aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-10-02 18:03:29 +0000
committerDavid Robillard <d@drobilla.net>2015-10-02 18:03:29 +0000
commitaec46529233290f8274d137b795b4924f1db131a (patch)
tree837bbb7a5cedb2ddaa5e73c51acb14a480cb2480
parentd908317e729ffc2495b9fc546cff88b541eacfb2 (diff)
downloadserd-aec46529233290f8274d137b795b4924f1db131a.tar.gz
serd-aec46529233290f8274d137b795b4924f1db131a.tar.bz2
serd-aec46529233290f8274d137b795b4924f1db131a.zip
Full test coverage
git-svn-id: http://svn.drobilla.net/serd/trunk@492 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--src/reader.c95
-rw-r--r--tests/serd_test.c14
-rw-r--r--wscript12
3 files changed, 69 insertions, 52 deletions
diff --git a/src/reader.c b/src/reader.c
index ec1a6034..c3c2e538 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -1089,56 +1089,48 @@ read_blankName(SerdReader* reader)
}
static bool
-read_blank(SerdReader* reader, ReadContext ctx, bool subject, Ref* dest, bool* ate_dot)
+read_anon(SerdReader* reader, ReadContext ctx, bool subject, Ref* dest)
{
const SerdStatementFlags old_flags = *ctx.flags;
bool empty;
- switch (peek_byte(reader)) {
- case '_':
- return (*dest = read_BLANK_NODE_LABEL(reader, ate_dot));
- case '[':
- eat_byte_safe(reader, '[');
- if ((empty = peek_delim(reader, ']'))) {
- *ctx.flags |= (subject) ? SERD_EMPTY_S : SERD_EMPTY_O;
- } else {
- *ctx.flags |= (subject) ? SERD_ANON_S_BEGIN : SERD_ANON_O_BEGIN;
- if (peek_delim(reader, '=')) {
- if (!(*dest = read_blankName(reader)) ||
- !eat_delim(reader, ';')) {
- return false;
- }
+ eat_byte_safe(reader, '[');
+ if ((empty = peek_delim(reader, ']'))) {
+ *ctx.flags |= (subject) ? SERD_EMPTY_S : SERD_EMPTY_O;
+ } else {
+ *ctx.flags |= (subject) ? SERD_ANON_S_BEGIN : SERD_ANON_O_BEGIN;
+ if (peek_delim(reader, '=')) {
+ if (!(*dest = read_blankName(reader)) ||
+ !eat_delim(reader, ';')) {
+ return false;
}
}
+ }
- if (!*dest) {
- *dest = blank_id(reader);
+ if (!*dest) {
+ *dest = blank_id(reader);
+ }
+ if (ctx.subject) {
+ TRY_RET(emit_statement(reader, ctx, *dest, 0, 0));
+ }
+
+ ctx.subject = *dest;
+ if (!empty) {
+ *ctx.flags &= ~(SERD_LIST_CONT);
+ if (!subject) {
+ *ctx.flags |= SERD_ANON_CONT;
}
- if (ctx.subject) {
- TRY_RET(emit_statement(reader, ctx, *dest, 0, 0));
+ bool ate_dot_in_list = false;
+ read_predicateObjectList(reader, ctx, &ate_dot_in_list);
+ if (ate_dot_in_list) {
+ return r_err(reader, SERD_ERR_BAD_SYNTAX, "`.' inside blank\n");
}
-
- ctx.subject = *dest;
- if (!empty) {
- *ctx.flags &= ~(SERD_LIST_CONT);
- if (!subject) {
- *ctx.flags |= SERD_ANON_CONT;
- }
- bool ate_dot_in_list = false;
- read_predicateObjectList(reader, ctx, &ate_dot_in_list);
- if (ate_dot_in_list) {
- return r_err(reader, SERD_ERR_BAD_SYNTAX, "`.' inside blank\n");
- }
- read_ws_star(reader);
- if (reader->end_sink) {
- reader->end_sink(reader->handle, deref(reader, *dest));
- }
- *ctx.flags = old_flags;
+ read_ws_star(reader);
+ if (reader->end_sink) {
+ reader->end_sink(reader->handle, deref(reader, *dest));
}
- return (eat_byte_check(reader, ']') == ']');
- case '(':
- return read_collection(reader, ctx, dest);
- default: return false; // never reached
+ *ctx.flags = old_flags;
}
+ return (eat_byte_check(reader, ']') == ']');
}
// Recurses, calling statement_sink for every statement encountered.
@@ -1165,11 +1157,16 @@ read_object(SerdReader* reader, ReadContext ctx, bool* ate_dot)
case '\0':
case ')':
return false;
- case '[': case '(':
+ case '[':
emit = false;
- // fall through
+ TRY_THROW(ret = read_anon(reader, ctx, false, &o));
+ break;
+ case '(':
+ emit = false;
+ TRY_THROW(ret = read_collection(reader, ctx, &o));
+ break;
case '_':
- TRY_THROW(ret = read_blank(reader, ctx, false, &o, ate_dot));
+ TRY_THROW(ret = (o = read_BLANK_NODE_LABEL(reader, ate_dot)));
break;
case '<': case ':':
TRY_THROW(ret = read_iri(reader, &o, ate_dot));
@@ -1334,11 +1331,17 @@ read_subject(SerdReader* reader, ReadContext ctx, bool* nested)
Ref subject = 0;
bool ate_dot = false;
switch (peek_byte(reader)) {
- case '[': case '(':
+ case '[':
*nested = true;
- // nobreak
+ read_anon(reader, ctx, true, &subject);
+ break;
+ case '(':
+ *nested = true;
+ read_collection(reader, ctx, &subject);
+ break;
case '_':
- read_blank(reader, ctx, true, &subject, &ate_dot);
+ *nested = false;
+ subject = read_BLANK_NODE_LABEL(reader, &ate_dot);
break;
default:
read_iri(reader, &subject, &ate_dot);
diff --git a/tests/serd_test.c b/tests/serd_test.c
index eecbb5b0..39b5c14f 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -399,6 +399,11 @@ main(void)
// Test serd_node_new_uri_from_string
+ SerdNode nonsense = serd_node_new_uri_from_string(NULL, NULL, NULL);
+ if (nonsense.type != SERD_NOTHING) {
+ return failure("Successfully created NULL URI\n");
+ }
+
SerdURI base_uri;
SerdNode base = serd_node_new_uri_from_string(USTR("http://example.org/"),
NULL, &base_uri);
@@ -420,6 +425,10 @@ main(void)
SerdEnv* env = serd_env_new(NULL);
serd_env_set_prefix_from_strings(env, USTR("eg.2"), USTR("http://example.org/"));
+ if (!serd_env_set_base_uri(env, NULL)) {
+ return failure("Successfully set NULL base URI\n");
+ }
+
if (!serd_env_set_base_uri(env, &node)) {
return failure("Set base URI to %s\n", node.buf);
}
@@ -614,7 +623,10 @@ main(void)
return failure("Apparently read an http URI\n");
}
if (!serd_reader_read_file(reader, USTR("file:///better/not/exist"))) {
- return failure("Apprently read a non-existent file\n");
+ return failure("Apparently read a non-existent file\n");
+ }
+ if (!serd_reader_read_file(reader, USTR("file://"))) {
+ return failure("Apparently read a file with no path\n");
}
SerdStatus st = serd_reader_read_file(reader, USTR(path));
if (st) {
diff --git a/wscript b/wscript
index e44459fc..7c0458a5 100644
--- a/wscript
+++ b/wscript
@@ -466,9 +466,10 @@ def test(ctx):
commands = []
for test in tests:
- path = os.path.join('tests', tdir, test)
- commands += [ 'serdi_static -f "%s" "%s" > %s.out' % (
- os.path.join(srcdir, path), test_base(test), path) ]
+ for lax in ['', '-l']:
+ path = os.path.join('tests', tdir, test)
+ commands += [ 'serdi_static %s -f "%s" "%s" > %s.out' % (
+ lax, os.path.join(srcdir, path), test_base(test), path) ]
autowaf.run_tests(ctx, APPNAME, commands, 0, name=tdir)
@@ -487,8 +488,9 @@ def test(ctx):
# Bad tests
commands = []
for test in bad_tests:
- commands += [ 'serdi_static -q "%s" "%s" > %s.out' % (
- os.path.join(srcdir, test), test_base(test), test) ]
+ for lax in ['', '-l']:
+ commands += [ 'serdi_static %s -q "%s" "%s" > %s.out' % (
+ lax, os.path.join(srcdir, test), test_base(test), test) ]
autowaf.run_tests(ctx, APPNAME, commands, 1, name='bad')