The ShEx Test
extension is a very simple extension intended for testing ShEx extension frameworks.
Test
participates in validate and has side-effects.
The Test
extension has two functions:
print(msg)
- emit some mesagefail(msg)
- fail validationTake a sample input schema with ShEx Test directives and input data:
PREFIX ex: <http://ex.example/#> PREFIX foaf: <http://xmlns.com/foaf/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX test: <http://shex.io/extensions/Test/> %test:{ %} start = <IssueShape> <IssueShape> { ex:reportedBy @<UserShape> %test:{ fail("some message") %}, } <UserShape> { foaf:name xsd:string %test:{ print(o) %} }
PREFIX ex: <http://ex.example/#> PREFIX foaf: <http://xmlns.com/foaf/> <Issue1> ex:reportedBy <User2> . <User2> foaf:name "Bob" .
In the ShEx Demo we see a failure:
<Issue1> matches <IssueShape>:
PASS { ex:reportedBy @<UserShape> %<http://shexspec.github.io/extensions/Test/>{ fail("some message") %} matched by <Issue1> ex:reportedBy <User2> . PASS { Errors: ☹ eval of {"some message"} rejected [[ <http://xmlns.com/foaf/name> <http://www.w3.org/2001/XMLSchema#string> %<http://shexspec.github.io/extensions/Test/>{ print(o) %} matched by <User2> <http://xmlns.com/foaf/name> "Bob". ]] Matches: foaf:name xsd:string %<http://shexspec.github.io/extensions/Test/>{ print(o) %} matched by <User2> foaf:name "Bob" . } }No remaining triples.
Examining the output (look for or link in validation messages) we see:
{ "prints": [ "Bob" ] }
Test
has a defined behavior when attached to a triple constraint.
Other behaviors of Test
are unspecified.
There are two function in the Test
extension:
print(msg)
- emit some mesagefail(msg)
- fail validation
Each takes an argument, which is one of these four particles: s
, p
or o
, or a literal delimited with "
s and potentially containing "
s and \
s escaped by preceding \
s.
s
, p
and o
correspond to the subject, predicate and object of the matching triple.s
corresponds to focus node; the rest not defined.
Test
directives can be parsed with the regular expression /^ *(fail|print) *\( *(?:("(?:[^\\"]|\\\\|\\")*")|([spo])) *\) *$/
.
The first capture group will be either "fail" or "print".
The second will capture quoted strings, including their quotation marks.
The third will captures the particles "s", "p", "o".
Test
string, the first capture group and either the second or the third will be matched.
langauge | platform/API | package | source |
---|---|---|---|
javascript | shexjs | packaged | src |
Test
is not a practical extension (apart perhaps from debugging).
It has side effects as well as participating in validation.
The output when there is a failure is undefined.
Some implementations, as the example above, may include the output even if validation failed.
For these systems, print
provides a print-debugging.