The ShEx Test extension is a very simple extension intended for testing ShEx extension frameworks. Test participates in validate and has side-effects.

Example

The Test extension has two functions:

Take 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"
  ]
}

Definition

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:

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.

Parsing

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".

For any valid Test string, the first capture group and either the second or the third will be matched.

langaugeplatform/APIpackagesource
javascript shexjs packaged src

Issues

edited by: Eric Prud'hommeaux