From 5d43cb36087292a397992aa1b59326fc355d5247 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 18 Dec 2019 19:09:49 -0500 Subject: Add support for parsing variables This adds a reader flag and serdi option for extending a syntax with support for SPARQL-like variables, for storing things like patterns or simple queries. --- test/bad/bad-var.ttl | 2 + test/bad/manifest.ttl | 6 +++ test/meson.build | 8 +++ test/pattern/bad-pattern-graph.nq | 1 + test/pattern/bad-pattern-object.nq | 1 + test/pattern/bad-pattern-object.nt | 1 + test/pattern/bad-pattern-object.ttl | 2 + test/pattern/bad-pattern-predicate.nq | 1 + test/pattern/bad-pattern-predicate.nt | 1 + test/pattern/bad-pattern-predicate.ttl | 2 + test/pattern/bad-pattern-subject.nq | 1 + test/pattern/bad-pattern-subject.nt | 1 + test/pattern/bad-pattern-subject.ttl | 2 + test/pattern/manifest.ttl | 89 ++++++++++++++++++++++++++++++++++ test/pattern/test-graph-pattern.nq | 1 + test/pattern/test-pattern.nt | 6 +++ test/pattern/test-pattern.ttl | 10 ++++ test/test_overflow.c | 27 ++++++----- 18 files changed, 150 insertions(+), 12 deletions(-) create mode 100644 test/bad/bad-var.ttl create mode 100644 test/pattern/bad-pattern-graph.nq create mode 100644 test/pattern/bad-pattern-object.nq create mode 100644 test/pattern/bad-pattern-object.nt create mode 100644 test/pattern/bad-pattern-object.ttl create mode 100644 test/pattern/bad-pattern-predicate.nq create mode 100644 test/pattern/bad-pattern-predicate.nt create mode 100644 test/pattern/bad-pattern-predicate.ttl create mode 100644 test/pattern/bad-pattern-subject.nq create mode 100644 test/pattern/bad-pattern-subject.nt create mode 100644 test/pattern/bad-pattern-subject.ttl create mode 100644 test/pattern/manifest.ttl create mode 100644 test/pattern/test-graph-pattern.nq create mode 100644 test/pattern/test-pattern.nt create mode 100644 test/pattern/test-pattern.ttl (limited to 'test') diff --git a/test/bad/bad-var.ttl b/test/bad/bad-var.ttl new file mode 100644 index 00000000..29b5b008 --- /dev/null +++ b/test/bad/bad-var.ttl @@ -0,0 +1,2 @@ +?s + . diff --git a/test/bad/manifest.ttl b/test/bad/manifest.ttl index 96a0b593..466a4435 100644 --- a/test/bad/manifest.ttl +++ b/test/bad/manifest.ttl @@ -70,6 +70,7 @@ <#bad-string> <#bad-subject> <#bad-uri-escape> + <#bad-var> <#bad-verb> <#invalid-char-in-local> <#invalid-char-in-prefix> @@ -394,6 +395,11 @@ mf:name "bad-uri-escape" ; mf:action . +<#bad-var> + rdf:type rdft:TestTurtleNegativeSyntax ; + mf:name "bad-var" ; + mf:action . + <#bad-verb> rdf:type rdft:TestTurtleNegativeSyntax ; mf:name "bad-verb" ; diff --git a/test/meson.build b/test/meson.build index 5063277b..222ec1bc 100644 --- a/test/meson.build +++ b/test/meson.build @@ -219,6 +219,14 @@ if get_option('utils') suite: ['rdf', 'serd'], timeout: 240) + manifest = files('pattern' / 'manifest.ttl') + base_uri = serd_base + 'pattern' + '/' + test('pattern', run_test_suite, + args: script_args + [manifest, base_uri, '--', '-x'], + env: test_env, + suite: ['rdf', 'serd'], + timeout: 240) + ### The lax suite is special because it is run twice... lax_manifest = files('lax/manifest.ttl') lax_base_uri = serd_base + name + '/' diff --git a/test/pattern/bad-pattern-graph.nq b/test/pattern/bad-pattern-graph.nq new file mode 100644 index 00000000..9c77ac9a --- /dev/null +++ b/test/pattern/bad-pattern-graph.nq @@ -0,0 +1 @@ + ?gµ . diff --git a/test/pattern/bad-pattern-object.nq b/test/pattern/bad-pattern-object.nq new file mode 100644 index 00000000..7f22b520 --- /dev/null +++ b/test/pattern/bad-pattern-object.nq @@ -0,0 +1 @@ + ?oµ . diff --git a/test/pattern/bad-pattern-object.nt b/test/pattern/bad-pattern-object.nt new file mode 100644 index 00000000..aef057e4 --- /dev/null +++ b/test/pattern/bad-pattern-object.nt @@ -0,0 +1 @@ + ?oµ . diff --git a/test/pattern/bad-pattern-object.ttl b/test/pattern/bad-pattern-object.ttl new file mode 100644 index 00000000..cc2eee77 --- /dev/null +++ b/test/pattern/bad-pattern-object.ttl @@ -0,0 +1,2 @@ + + ?oµ . diff --git a/test/pattern/bad-pattern-predicate.nq b/test/pattern/bad-pattern-predicate.nq new file mode 100644 index 00000000..cfe466c9 --- /dev/null +++ b/test/pattern/bad-pattern-predicate.nq @@ -0,0 +1 @@ + ?pµ . diff --git a/test/pattern/bad-pattern-predicate.nt b/test/pattern/bad-pattern-predicate.nt new file mode 100644 index 00000000..a7e0c994 --- /dev/null +++ b/test/pattern/bad-pattern-predicate.nt @@ -0,0 +1 @@ + ?pµ . diff --git a/test/pattern/bad-pattern-predicate.ttl b/test/pattern/bad-pattern-predicate.ttl new file mode 100644 index 00000000..cc2bd6b1 --- /dev/null +++ b/test/pattern/bad-pattern-predicate.ttl @@ -0,0 +1,2 @@ + + ?pµ . diff --git a/test/pattern/bad-pattern-subject.nq b/test/pattern/bad-pattern-subject.nq new file mode 100644 index 00000000..341c437f --- /dev/null +++ b/test/pattern/bad-pattern-subject.nq @@ -0,0 +1 @@ +?sµ . diff --git a/test/pattern/bad-pattern-subject.nt b/test/pattern/bad-pattern-subject.nt new file mode 100644 index 00000000..5bbb29ff --- /dev/null +++ b/test/pattern/bad-pattern-subject.nt @@ -0,0 +1 @@ +?sµ . diff --git a/test/pattern/bad-pattern-subject.ttl b/test/pattern/bad-pattern-subject.ttl new file mode 100644 index 00000000..5f3dbfdd --- /dev/null +++ b/test/pattern/bad-pattern-subject.ttl @@ -0,0 +1,2 @@ +?sµ + . diff --git a/test/pattern/manifest.ttl b/test/pattern/manifest.ttl new file mode 100644 index 00000000..a7f238bc --- /dev/null +++ b/test/pattern/manifest.ttl @@ -0,0 +1,89 @@ +@prefix mf: . +@prefix rdf: . +@prefix rdfs: . +@prefix rdft: . + +<> + rdf:type mf:Manifest ; + rdfs:comment "Serd pattern syntax test cases" ; + mf:entries ( + <#bad-pattern-graph-nq> + <#bad-pattern-object-nq> + <#bad-pattern-object-nt> + <#bad-pattern-object-ttl> + <#bad-pattern-predicate-nq> + <#bad-pattern-predicate-nt> + <#bad-pattern-predicate-ttl> + <#bad-pattern-subject-nq> + <#bad-pattern-subject-nt> + <#bad-pattern-subject-ttl> + <#test-graph-pattern> + <#test-pattern-nt> + <#test-pattern-ttl> + ) . + +<#bad-pattern-graph-nq> + rdf:type rdft:TestNQuadsNegativeSyntax ; + mf:name "bad-pattern-graph-nq" ; + mf:action . + +<#bad-pattern-object-nq> + rdf:type rdft:TestNQuadsNegativeSyntax ; + mf:name "bad-pattern-object-nq" ; + mf:action . + +<#bad-pattern-object-nt> + rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "bad-pattern-object-nt" ; + mf:action . + +<#bad-pattern-object-ttl> + rdf:type rdft:TestTurtleNegativeSyntax ; + mf:name "bad-pattern-object-ttl" ; + mf:action . + +<#bad-pattern-predicate-nq> + rdf:type rdft:TestNQuadsNegativeSyntax ; + mf:name "bad-pattern-predicate-nq" ; + mf:action . + +<#bad-pattern-predicate-nt> + rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "bad-pattern-predicate-nt" ; + mf:action . + +<#bad-pattern-predicate-ttl> + rdf:type rdft:TestTurtleNegativeSyntax ; + mf:name "bad-pattern-predicate-ttl" ; + mf:action . + +<#bad-pattern-subject-nq> + rdf:type rdft:TestNQuadsNegativeSyntax ; + mf:name "bad-pattern-subject-nq" ; + mf:action . + +<#bad-pattern-subject-nt> + rdf:type rdft:TestNTriplesNegativeSyntax ; + mf:name "bad-pattern-subject-nt" ; + mf:action . + +<#bad-pattern-subject-ttl> + rdf:type rdft:TestTurtleNegativeSyntax ; + mf:name "bad-pattern-subject-ttl" ; + mf:action . + +<#test-graph-pattern> + rdf:type rdft:TestNQuadsPositiveSyntax ; + mf:name "test-graph-pattern" ; + mf:action . + +<#test-pattern-nt> + rdf:type rdft:TestNTriplesPositiveSyntax ; + mf:name "test-pattern-nt" ; + mf:action . + +<#test-pattern-ttl> + rdf:type rdft:TestTurtleEval ; + mf:name "test-pattern" ; + mf:action ; + mf:result . diff --git a/test/pattern/test-graph-pattern.nq b/test/pattern/test-graph-pattern.nq new file mode 100644 index 00000000..453e9516 --- /dev/null +++ b/test/pattern/test-graph-pattern.nq @@ -0,0 +1 @@ + ?g . diff --git a/test/pattern/test-pattern.nt b/test/pattern/test-pattern.nt new file mode 100644 index 00000000..ddfe6d3c --- /dev/null +++ b/test/pattern/test-pattern.nt @@ -0,0 +1,6 @@ +?s . + ?p . + ?o . + _:b1 . +_:b1 ?2p . +_:b1 ?_o . diff --git a/test/pattern/test-pattern.ttl b/test/pattern/test-pattern.ttl new file mode 100644 index 00000000..3742e5ed --- /dev/null +++ b/test/pattern/test-pattern.ttl @@ -0,0 +1,10 @@ +?s + . + + + ?p ; + ?o ; + [ + ?2p ; + ?_o + ] . diff --git a/test/test_overflow.c b/test/test_overflow.c index 6d5c6d0c..335cd5c7 100644 --- a/test/test_overflow.c +++ b/test/test_overflow.c @@ -25,15 +25,16 @@ static const size_t min_stack_size = 4 * sizeof(size_t) + 256u; static const size_t max_stack_size = 1024u; static SerdStatus -test_size(SerdWorld* const world, - const char* const str, - const SerdSyntax syntax, - const size_t stack_size) +test_size(SerdWorld* const world, + const char* const str, + const SerdSyntax syntax, + const SerdReaderFlags flags, + const size_t stack_size) { SerdSink* sink = serd_sink_new(NULL, NULL, NULL); SerdByteSource* byte_source = serd_byte_source_new_string(str, NULL); SerdReader* const reader = - serd_reader_new(world, syntax, 0u, sink, stack_size); + serd_reader_new(world, syntax, flags, sink, stack_size); assert(reader); @@ -47,17 +48,18 @@ test_size(SerdWorld* const world, } static void -test_all_sizes(SerdWorld* const world, - const char* const str, - const SerdSyntax syntax) +test_all_sizes(SerdWorld* const world, + const char* const str, + const SerdSyntax syntax, + const SerdReaderFlags flags) { // Ensure reading with the maximum stack size succeeds - SerdStatus st = test_size(world, str, syntax, max_stack_size); + SerdStatus st = test_size(world, str, syntax, flags, max_stack_size); assert(!st); // Test with an increasingly smaller stack for (size_t size = max_stack_size; size > min_stack_size; --size) { - if ((st = test_size(world, str, syntax, size))) { + if ((st = test_size(world, str, syntax, flags, size))) { assert(st == SERD_ERR_OVERFLOW); } } @@ -76,7 +78,7 @@ test_ntriples_overflow(void) SerdWorld* const world = serd_world_new(); for (const char* const* t = test_strings; *t; ++t) { - test_all_sizes(world, *t, SERD_NTRIPLES); + test_all_sizes(world, *t, SERD_NTRIPLES, 0u); } serd_world_free(world); @@ -98,6 +100,7 @@ test_turtle_overflow(void) " _:blank .", " true .", " \"\"@en .", + "?subject ?predicate ?object .", "(((((((((42))))))))) .", "@prefix eg: .", "@base .", @@ -165,7 +168,7 @@ test_turtle_overflow(void) SerdWorld* const world = serd_world_new(); for (const char* const* t = test_strings; *t; ++t) { - test_all_sizes(world, *t, SERD_TURTLE); + test_all_sizes(world, *t, SERD_TURTLE, SERD_READ_VARIABLES); } serd_world_free(world); -- cgit v1.2.1