aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-10-21 20:57:33 +0200
committerDavid Robillard <d@drobilla.net>2022-01-13 23:04:05 -0500
commit89be71eabefcc55a3d0a56d7bed7124c4fdafbd8 (patch)
tree6c2b019b462999d1178441943d1cf90c4bd7b17c /test
parentaca4640882aab7da0193ee2f5767ecd6d9506b0c (diff)
downloadserd-89be71eabefcc55a3d0a56d7bed7124c4fdafbd8.tar.gz
serd-89be71eabefcc55a3d0a56d7bed7124c4fdafbd8.tar.bz2
serd-89be71eabefcc55a3d0a56d7bed7124c4fdafbd8.zip
Simplify streaming API and improve pretty printing
This removes the obligation from the caller to correctly maintain flags to describe the current anonymous context, instead making the writer handle this itself as much as possible. Flags remain for the cases the writer can not infer from context: the start of anonymous subject and object nodes.
Diffstat (limited to 'test')
-rw-r--r--test/good/base.ttl1
-rw-r--r--test/good/pretty.trig98
-rw-r--r--test/good/qualify-out.ttl1
-rw-r--r--test/test_writer.c12
4 files changed, 104 insertions, 8 deletions
diff --git a/test/good/base.ttl b/test/good/base.ttl
index 4c437937..755c1d09 100644
--- a/test/good/base.ttl
+++ b/test/good/base.ttl
@@ -1,3 +1,2 @@
<foo>
a <Bar> .
-
diff --git a/test/good/pretty.trig b/test/good/pretty.trig
new file mode 100644
index 00000000..140769ce
--- /dev/null
+++ b/test/good/pretty.trig
@@ -0,0 +1,98 @@
+@prefix : <http://example.org/> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+
+:a
+ :b :c ,
+ :d ,
+ :e ;
+ :f :g ,
+ :h .
+
+(
+ 1
+)
+ :isA :List .
+
+[]
+ :isA :Blank .
+
+(
+ 2
+)
+ :sameAs (
+ 2
+ ) .
+
+[]
+ :sameAs [] .
+
+(
+ 1
+ 2
+)
+ a :List ;
+ rdf:value 3 .
+
+(
+ (
+ 3
+ )
+ (
+ 4
+ )
+)
+ a :NestedList ;
+ :sum 7 .
+
+[
+ a :BlankSubject
+]
+ a rdf:Resource .
+
+[
+ a :BlankSubject
+] .
+
+[]
+ :blank [
+ :nestedEmptyBlank [] ;
+ :nestedNonEmptyBlanks [
+ rdf:value 1
+ ] , [
+ rdf:value 2
+ ]
+ ] ;
+ :lists (
+ 3
+ 4
+ ) , (
+ 5
+ 6
+ ) , (
+ [
+ rdf:value 7
+ ]
+ [
+ rdf:value 8
+ ]
+ ) .
+
+:s
+ a :Thing ;
+ :predicate1 :object1 ,
+ [
+ a :SubThing ;
+ :predicate2 :object2
+ ] , [
+ a :OtherSubThing ;
+ :p3 :o3
+ ] ;
+ :p4 :o4 .
+
+eg:graph {
+ :a
+ :b :c ;
+ :d [
+ :e :f
+ ] .
+}
diff --git a/test/good/qualify-out.ttl b/test/good/qualify-out.ttl
index 97f67a53..42e4091a 100644
--- a/test/good/qualify-out.ttl
+++ b/test/good/qualify-out.ttl
@@ -2,4 +2,3 @@
eg:s
eg:p eg:o .
-
diff --git a/test/test_writer.c b/test/test_writer.c
index d7c4eac8..0611a40d 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -103,7 +103,7 @@ test_write_long_literal(void)
static const char* const expected =
"<http://example.org/s>\n"
- "\t<http://example.org/p> \"\"\"hello \"\"\\\"world\"\"\\\"!\"\"\" .\n\n";
+ "\t<http://example.org/p> \"\"\"hello \"\"\\\"world\"\"\\\"!\"\"\" .\n";
assert(!strcmp((char*)out, expected));
serd_free(out);
@@ -141,10 +141,9 @@ test_writer_stack_overflow(void)
const SerdNode* const p =
serd_nodes_uri(nodes, SERD_STRING("http://example.org/p"));
- const SerdNode* o =
- serd_nodes_blank(nodes, SERD_STRING("http://example.org/o"));
+ const SerdNode* o = serd_nodes_blank(nodes, SERD_STRING("blank"));
- SerdStatus st = serd_sink_write(sink, SERD_ANON_O_BEGIN, s, p, o, NULL);
+ SerdStatus st = serd_sink_write(sink, SERD_ANON_O, s, p, o, NULL);
assert(!st);
// Repeatedly write nested anonymous objects until the writer stack overflows
@@ -154,8 +153,9 @@ test_writer_stack_overflow(void)
const SerdNode* next_o = serd_nodes_blank(nodes, SERD_STRING(buf));
- st = serd_sink_write(sink, SERD_ANON_O_BEGIN, o, p, next_o, NULL);
- o = next_o;
+ st = serd_sink_write(sink, SERD_ANON_O, o, p, next_o, NULL);
+
+ o = next_o;
if (st) {
assert(st == SERD_ERR_OVERFLOW);