aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-08-12 22:28:59 -0400
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:07 -0500
commit1409f161793a289819df1f31eccb579b71f45475 (patch)
tree4076c291a397f0a0a2ea560305ee87c47810df33 /src
parent6ffe331cfc8af0735b263ab7af6f84b1b4418102 (diff)
downloadserd-1409f161793a289819df1f31eccb579b71f45475.tar.gz
serd-1409f161793a289819df1f31eccb579b71f45475.tar.bz2
serd-1409f161793a289819df1f31eccb579b71f45475.zip
Fix pretty-printing nested empty lists and add test suite
The earlier "test" was just hitting the code without actually checking the output. This new suite is a set of pretty-printed documents which serd must reproduce from a model exactly to pass. This should make it easy to add cases in the future, since each case is just a document, as it should look.
Diffstat (limited to 'src')
-rw-r--r--src/describe.c11
-rw-r--r--src/n3.c6
-rw-r--r--src/writer.c5
3 files changed, 15 insertions, 7 deletions
diff --git a/src/describe.c b/src/describe.c
index 9bd9d3ae..718eaf1c 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -204,7 +204,7 @@ write_range_statement(const SerdSink* const sink,
// First write inline list subject, which this statement will follow
if (zix_hash_insert(list_subjects, subject) != ZIX_STATUS_EXISTS) {
st = write_list(
- sink, model, list_subjects, 2, SERD_LIST_S, subject, graph);
+ sink, model, list_subjects, 2, flags | SERD_LIST_S, subject, graph);
}
}
}
@@ -226,9 +226,12 @@ write_range_statement(const SerdSink* const sink,
serd_cursor_free(iter);
} else if (object_style == LIST_O) { // Write list object like "( ... )"
- flags |= SERD_LIST_O;
- if (!(st = serd_sink_write_statement(sink, flags, statement))) {
- st = write_list(sink, model, list_subjects, depth + 1, 0, object, graph);
+ if (!(st =
+ serd_sink_write_statement(sink, flags | SERD_LIST_O, statement))) {
+ flags = flags & ~((unsigned)SERD_LIST_S);
+
+ st =
+ write_list(sink, model, list_subjects, depth + 1, flags, object, graph);
}
} else {
diff --git a/src/n3.c b/src/n3.c
index ff142976..3b12dfec 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -866,11 +866,11 @@ read_collection(SerdReader* const reader,
return SERD_ERR_OVERFLOW;
}
- if (ctx.subject) {
- // subject predicate _:head
+ if (ctx.subject) { // Reading a collection object
*ctx.flags |= (end ? 0 : SERD_LIST_O);
TRY(st, emit_statement(reader, ctx, *dest));
- } else {
+ *ctx.flags &= ~((unsigned)SERD_LIST_O);
+ } else { // Reading a collection subject
*ctx.flags |= (end ? 0 : SERD_LIST_S);
}
diff --git a/src/writer.c b/src/writer.c
index 5f9fdaab..452d3679 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -1064,6 +1064,11 @@ write_list_statement(SerdWriter* const writer,
SerdStatus st = SERD_SUCCESS;
bool is_end = false;
+ if (serd_node_equals(predicate, writer->world->rdf_first) &&
+ serd_node_equals(object, writer->world->rdf_nil)) {
+ return esink("()", 2, writer);
+ }
+
TRY(st, write_list_obj(writer, flags, predicate, object, &is_end));
if (is_end) {
pop_context(writer);