Skip to content

Commit

Permalink
[MOD] unit tests re #21
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSales committed Aug 7, 2023
1 parent f48b81c commit 1695398
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 1 deletion.
4 changes: 3 additions & 1 deletion svrl.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ as item()*
case element(sch:name)
return if($node/@path)
then output:name-value-of($node/@path, $prolog, $rule-context, $context)
else name($rule-context)
[self::svrl:*]
else ()
case element(sch:value-of)
return output:name-value-of($node/@select, $prolog, $rule-context, $context)
[self::svrl:*]
default return ()
else
<svrl:text>{(:TODO attributes:)
Expand Down
188 changes: 188 additions & 0 deletions test/test-evaluate.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -1323,4 +1323,192 @@ declare %unit:test function _:global-variable-syntax-error()
<svrl:text>No specifier after lookup operator: ';'. @value='?'</svrl:text>
)
)
};

declare %unit:test function _:pattern-variable-syntax-error()
{
let $result :=
eval:schema(
document{<root/>},
<sch:schema>
<sch:pattern>
<sch:let name='y' value='$'/>
<sch:rule context="/">
<sch:report test="true()"></sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>,
'',
map{'dry-run':'true'}
)
return
(
unit:assert-equals(
$result/svrl:failed-assert[ends-with(@location ,'/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}let[1]/@value')]
/svrl:text,
<svrl:text>Incomplete FLWOR expression, expecting 'return'. @value='$'</svrl:text>
)
)
};

declare %unit:test function _:rule-context-syntax-error()
{
let $result :=
eval:schema(
document{<root/>},
<sch:schema>
<sch:pattern>
<sch:rule context="">
<sch:report test="true()"></sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>,
'',
map{'dry-run':'true'}
)
return
(
unit:assert-equals(
$result/svrl:failed-assert/svrl:text,
<svrl:text>Expecting expression. @context=''</svrl:text>
)
)
};

declare %unit:test function _:dry-run-all-rules-processed()
{
let $result :=
eval:schema(
document{<root/>},
<sch:schema>
<sch:pattern>
<sch:rule context="">
</sch:rule>
<sch:rule context='*'></sch:rule>
</sch:pattern>
</sch:schema>,
'',
map{'dry-run':'true'}
)
return
(
unit:assert-equals(
count($result/svrl:fired-rule),
2
)
)
};

declare %unit:ignore function _:rule-variable-syntax-error()
{
let $result :=
eval:schema(
document{<root/>},
<sch:schema>
<sch:pattern>
<sch:rule context="*">
<sch:let name='bar' value=''/>
</sch:rule>
<sch:rule context='*'></sch:rule>
</sch:pattern>
</sch:schema>,
'',
map{'dry-run':'true'}
)
return
(
unit:assert-equals(
count($result/svrl:failed-assert[ends-with(@location, '/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}rule[1]/@context')]),
1
),
unit:assert-equals(
$result/svrl:failed-assert[ends-with(@location, '/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}rule[1]/@context')]
/svrl:text,
<svrl:text>TODO</svrl:text>
)
)
};

declare %unit:test function _:report-test-syntax-error()
{
let $result :=
eval:schema(
document{<root/>},
<sch:schema>
<sch:pattern>
<sch:rule context="*">
<sch:report test='ns:*'/>
</sch:rule>
</sch:pattern>
</sch:schema>,
'',
map{'dry-run':'true'}
)
return
(
unit:assert-equals(
count($result/svrl:failed-assert[ends-with(@location, '/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}rule[1]/Q{http://purl.oclc.org/dsdl/schematron}report[1]/@test')]),
1
),
unit:assert-equals(
$result/svrl:failed-assert/svrl:text,
<svrl:text>Namespace prefix not declared: ns. @test='ns:*'</svrl:text>
)
)
};

declare %unit:test function _:name-path-syntax-error()
{
let $result :=
eval:schema(
document{<root/>},
<sch:schema>
<sch:pattern>
<sch:rule context="*">
<sch:report test="."><sch:name path='...'/></sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>,
'',
map{'dry-run':'true'}
)
return
(
unit:assert-equals(
count($result/svrl:failed-assert[ends-with(@location, '/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}rule[1]/Q{http://purl.oclc.org/dsdl/schematron}report[1]/Q{http://purl.oclc.org/dsdl/schematron}name[1]/@path')]),
1
),
unit:assert-equals(
$result/svrl:failed-assert/svrl:text,
<svrl:text>Unexpected end of query: '.'. @path='...'</svrl:text>
)
)
};

declare %unit:test function _:value-of-select-syntax-error()
{
let $result :=
eval:schema(
document{<root/>},
<sch:schema>
<sch:pattern>
<sch:rule context="*">
<sch:report test="."><sch:value-of select='...'/></sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>,
'',
map{'dry-run':'true'}
)
return
(
unit:assert-equals(
count($result/svrl:failed-assert[ends-with(@location, '/Q{http://purl.oclc.org/dsdl/schematron}pattern[1]/Q{http://purl.oclc.org/dsdl/schematron}rule[1]/Q{http://purl.oclc.org/dsdl/schematron}report[1]/Q{http://purl.oclc.org/dsdl/schematron}value-of[1]/@select')]),
1
),
unit:assert-equals(
$result/svrl:failed-assert/svrl:text,
<svrl:text>Unexpected end of query: '.'. @select='...'</svrl:text>
)
)
};

0 comments on commit 1695398

Please sign in to comment.