Skip to content

Commit

Permalink
[MOD] progress on #21
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSales committed Aug 5, 2023
1 parent 887e03a commit 904e8f5
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 25 deletions.
31 changes: 18 additions & 13 deletions context.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ as map(*)

return
map:merge(
($options,
map{
'phase' : $active-phase,
'patterns' : $active-patterns,
'ns-decls' : $namespaces,
'globals' : $globals,
'instance' : $instance,
'diagnostics' : $schema/sch:diagnostics/sch:diagnostic,
'properties' : $schema/sch:properties/sch:property,
'functions' : $schema/xqy:function
})
(
$options,
map{
'phase' : $active-phase,
'patterns' : $active-patterns,
'ns-decls' : $namespaces,
'globals' : $globals,
'instance' : $instance,
'diagnostics' : $schema/sch:diagnostics/sch:diagnostic,
'properties' : $schema/sch:properties/sch:property,
'functions' : $schema/xqy:function
}
)
)
};

Expand Down Expand Up @@ -251,6 +253,7 @@ as map(*)
: @param query the query to evaluate
: @param ns-elems namespace declarations
: @param bindings map of global variable bindings
: @param options map of options
:)
declare function c:evaluate-global-variable(
$variable as element(sch:let),
Expand All @@ -267,7 +270,8 @@ as map(*)
then utils:eval(
$query => utils:escape(),
map:merge(($bindings, map{'':$instance})),
map:merge($options, map{'pass':'true'})
map:merge($options, map{'pass':'true'}),
$variable/@value
)
else $variable/*
let $bindings := map:merge(
Expand Down Expand Up @@ -302,7 +306,8 @@ as map(*)
let $uris := utils:eval(
utils:make-query-prolog($context) || $documents => utils:escape(),
map:merge(($context?globals, map{'':$context?instance})),
map{'pass':'true'} (:report exception details:)
map{'pass':'true'}, (:report exception details:)
$documents
)
return map:put(
$context,
Expand Down
10 changes: 7 additions & 3 deletions evaluate.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ declare function eval:schema(
{output:namespace-decls-as-svrl($schema/sch:ns)}
{for $phase in ($schema/sch:phase/@id/data(), '')
let $context as map(*) := context:get-context($instance, $schema, $phase, $options)
return eval:phase($context)}
return
($context?globals?*[self::svrl:*[@err:*]],
eval:phase($context))}
</svrl:schematron-output>
else
eval:schema($instance, $schema, $phase)
Expand Down Expand Up @@ -153,7 +155,8 @@ as element()*
let $rule-context := utils:eval(
$query => utils:escape(),
map:merge((map{'':$context?instance}, $context?globals)),
map{'pass':'true', 'dry-run':$context?dry-run}
map{'pass':'true', 'dry-run':$context?dry-run},
$rule/@context
)
return
if($rule-context)
Expand Down Expand Up @@ -212,7 +215,8 @@ declare function eval:assertion(
let $result := utils:eval(
$prolog || $assertion/@test => utils:escape(),
map:merge((map{'':$rule-context}, $context?globals)),
map{'pass':'true', 'dry-run':$context?dry-run}
map{'pass':'true', 'dry-run':$context?dry-run},
$assertion/@test
)
return
typeswitch($assertion)
Expand Down
6 changes: 4 additions & 2 deletions svrl.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ declare function output:assertion-message-content(
then utils:eval(
$prolog || $node/@path,
map:merge((map{'':$rule-context}, $context?globals)),
map{'pass':'true'}
map{'pass':'true'},
$node/@path
)
else name($rule-context)
case element(sch:value-of)
return utils:eval(
$prolog || $node/@select,
map:merge((map{'':$rule-context}, $context?globals)),
map{'pass':'true'}
map{'pass':'true'},
$node/@select
)
=> string()
case element(sch:emph)
Expand Down
1 change: 1 addition & 0 deletions test/test-compile.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,7 @@ declare %unit:test function _:global-variable-bindings()
document{<foo bar='some value'><blort/></foo>},
'',
(),
map{},
map{}
)
return (
Expand Down
12 changes: 8 additions & 4 deletions test/test-context.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ declare %unit:test function _:get-context-patterns()
let $patterns := c:get-context(
<foo/>,
$schema,
'phase1'
'phase1',
map{}
)?patterns

return unit:assert-equals(
Expand All @@ -296,7 +297,8 @@ declare %unit:test function _:get-context-active-phase()
let $phase := c:get-context(
<foo/>,
$schema,
'phase1'
'phase1',
map{}
)?phase

return unit:assert-equals(
Expand All @@ -322,7 +324,8 @@ declare %unit:test function _:get-context-namespaces()
let $ns-decls := c:get-context(
<foo/>,
$schema,
''
'',
map{}
)?ns-decls

return unit:assert-equals(
Expand Down Expand Up @@ -350,7 +353,8 @@ declare %unit:test function _:get-context-globals()
let $globals := c:get-context(
<foo/>,
$schema,
'phase1'
'phase1',
map{}
)?globals

return unit:assert-equals(
Expand Down
24 changes: 24 additions & 0 deletions test/test-evaluate.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -1299,4 +1299,28 @@ declare %unit:test function _:map-rule-variable()
unit:assert(empty($result/svrl:failed-assert)),
unit:assert(empty($result/svrl:successful-report))
)
};

declare %unit:test function _:global-variable-syntax-error()
{
let $result := eval:schema(
document{<root/>},
doc('global-variable-syntax-error.sch')/*,
'',
map{'dry-run':'true'}
)
return (
unit:assert-equals(
$result/svrl:failed-assert/@location/data(),
"/Q{http://purl.oclc.org/dsdl/schematron}schema[1]/Q{http://purl.oclc.org/dsdl/schematron}let[1]/@value"
),
unit:assert-equals(
$result/svrl:failed-assert/@err:code/data(),
"err:XPST0003"
),
unit:assert-equals(
$result/svrl:failed-assert/svrl:text,
<svrl:text>No specifier after lookup operator: ';'.</svrl:text>
)
)
};
20 changes: 17 additions & 3 deletions utils.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,28 @@ declare function utils:check-duplicate-variable-names($decls as element(sch:let)
) else()
};

(:~ Wrapper around xquery:eval() :)
(:~ Wrapper around xquery:eval()
: @param $query string of the query to evaluate
: @param bindings map of bindings
: @param options map of options
: @param node the schema node being evaluated
:)
declare function utils:eval(
$query as xs:string,
$bindings as map(*),
$options as map(*)
$options as map(*),
$node as node()
) as item()*
{
if($options?dry-run eq 'true')
then ()
then
try{
xquery:parse($query, map{'pass':'true'})
}
catch * {
<svrl:failed-assert err:code='{$err:code}' location='{$node/path()}'
test='xquery:parse(.)'>
<svrl:text>{$err:description}</svrl:text></svrl:failed-assert>
}
else xquery:eval($query, $bindings, map{'pass':'true'})
};

0 comments on commit 904e8f5

Please sign in to comment.