Move graph:dep-lookup into Package Subgraphs subsection

* src/graph.xsl (graph:dep-lookup): Moved into subsection with
  introductory paragraph.
master
Mike Gerwitz 2016-07-05 15:36:41 -04:00
parent 551e489c5f
commit bcf1e0457f
2 changed files with 149 additions and 112 deletions

View File

@ -51,38 +51,6 @@
use the node QNames for type checks.}
-->
<!--
Retrieve dependenices for @var{$symbol} on the @var{$graph},
using the lookup function @var{$lookup} to resolve external
subgraphs.
@var{$lookup} will be used only if the symbol cannot be
found in @var{$graph},
in which case the result of @var{$lookup} will used used in a
recursive call as the new @var{$graph}.
From a graph perspective,
the dependencies are edges on the @var{$symbol} vertex.
-->
<function name="graph:dep-lookup" as="element( preproc:sym-dep )?">
<param name="symbol" as="element( preproc:sym )" />
<param name="graph" as="element( preproc:sym-deps )" />
<param name="lookup" />
<variable name="deps" as="element( preproc:sym-dep )?"
select="$graph/preproc:sym-dep
[ @name = $symbol/@name ]" />
<sequence select="if ( exists( $deps ) ) then
$deps
else if ( $lookup ) then
graph:dep-lookup( $symbol,
f:apply( $lookup, $symbol ),
$lookup )
else
()" />
</function>
<!--
Produce a new graph that is the transpose of
@var{$graph}@mdash{}that is,
@ -190,4 +158,60 @@
</preproc:sym-deps>
</function>
<!--
@menu
* Package Subgraphs:: Managing package dependencies
@end menu
-->
<!--
@node Package Subgraphs
@subsection Package Subgraphs
Each package has its own independent dependency graph.
These vertices may have @dfn{virtual edges} to other packages'
graphs@mdash{}edges that will be formed once combined the
referenced graph;
these edges are indicated with @code{preproc:sym-ref/@@src}.
Graph operations are usually performed on single packages,
but it is occionally necessary to traverse packages to recurisvely
resolve dependencies.
@ref{graph:dep-lookup} makes this easy:
TODO: Generic graph functions.
-->
<!--
Retrieve dependenices for @var{$symbol} on the @var{$graph},
using the lookup function @var{$lookup} to resolve external
subgraphs.
@var{$lookup} will be used only if the symbol cannot be found in
@var{$graph},
in which case the result of @var{$lookup} will used used in a
recursive call as the new @var{$graph}.
From a graph perspective,
the dependencies are edges on the @var{$symbol} vertex.
-->
<function name="graph:dep-lookup" as="element( preproc:sym-dep )?">
<param name="symbol" as="element( preproc:sym )" />
<param name="graph" as="element( preproc:sym-deps )" />
<param name="lookup" />
<variable name="deps" as="element( preproc:sym-dep )?"
select="$graph/preproc:sym-dep
[ @name = $symbol/@name ]" />
<sequence select="if ( exists( $deps ) ) then
$deps
else if ( $lookup ) then
graph:dep-lookup( $symbol,
f:apply( $lookup, $symbol ),
$lookup )
else
()" />
</function>
</stylesheet>

View File

@ -28,86 +28,6 @@
xmlns:foo="http://www.lovullo.com/_junk"
stylesheet="graph-test.xsl">
<scenario label="graph:dep-lookup">
<scenario label="given a symbol">
<scenario label="in the same package">
<scenario label="where dependencies exist">
<call function="graph:dep-lookup">
<param name="symbol"
select="$foo:document/preproc:symtable
/preproc:sym[ @name='local' ]" />
<param name="graph"
select="$foo:document/preproc:sym-deps" />
<param name="lookup" select="()" />
</call>
<expect label="returns local dependencies"
test="$x:result is
$foo:document/preproc:sym-deps/preproc:sym-dep[
@name='local' ]" />
</scenario>
<scenario label="with external @src but local deps">
<call function="graph:dep-lookup">
<param name="symbol"
select="$foo:document/preproc:symtable
/preproc:sym[ @name='external-but-not' ]" />
<param name="graph"
select="$foo:document/preproc:sym-deps" />
<param name="lookup" select="()" />
</call>
<expect label="returns local dependencies"
test="$x:result is
$foo:document/preproc:sym-deps/preproc:sym-dep[
@name='external-but-not' ]" />
</scenario>
<scenario label="where dependencies are missing">
<call function="graph:dep-lookup">
<param name="symbol"
select="$foo:document/preproc:symtable
/preproc:sym[ @name='missing-deps' ]" />
<param name="graph"
select="$foo:document/preproc:sym-deps" />
<param name="lookup" select="()" />
</call>
<expect label="return empty sequence"
test="empty( $x:result )" />
</scenario>
</scenario>
<scenario label="in a separate package">
<variable name="foo:expected-lookup" as="element()">
<foo:lookup-ok />
</variable>
<scenario label="where dependencies exist">
<call function="graph:dep-lookup">
<param name="symbol"
select="$foo:document/preproc:symtable
/preproc:sym[ @name='external' ]" />
<param name="graph"
select="$foo:document/preproc:sym-deps" />
<param name="lookup"
select="foo:lookup( $foo:expected-lookup )" />
</call>
<expect label="returns external dependenices"
test="exists( $x:result/foo:lookup-ok )" />
</scenario>
</scenario>
</scenario>
</scenario>
<scenario label="graph:reverse on a disconnected DAG">
<call function="graph:reverse">
@ -216,5 +136,98 @@
<expect label="merges vertices and edges of unique vertices"
select="$foo:graph-vtwo-vthree" />
</scenario>
<scenario label="given single graph with duplicate vectors">
<call function="graph:union">
<param name="graphs"
select="$foo:graph-with-dupes" />
</call>
<expect label="mergs duplicates"
select="$foo:graph-deduped" />
</scenario>
</scenario>
<scenario label="graph:dep-lookup">
<scenario label="given a symbol">
<scenario label="in the same package">
<scenario label="where dependencies exist">
<call function="graph:dep-lookup">
<param name="symbol"
select="$foo:document/preproc:symtable
/preproc:sym[ @name='local' ]" />
<param name="graph"
select="$foo:document/preproc:sym-deps" />
<param name="lookup" select="()" />
</call>
<expect label="returns local dependencies"
test="$x:result is
$foo:document/preproc:sym-deps/preproc:sym-dep[
@name='local' ]" />
</scenario>
<scenario label="with external @src but local deps">
<call function="graph:dep-lookup">
<param name="symbol"
select="$foo:document/preproc:symtable
/preproc:sym[ @name='external-but-not' ]" />
<param name="graph"
select="$foo:document/preproc:sym-deps" />
<param name="lookup" select="()" />
</call>
<expect label="returns local dependencies"
test="$x:result is
$foo:document/preproc:sym-deps/preproc:sym-dep[
@name='external-but-not' ]" />
</scenario>
<scenario label="where dependencies are missing">
<call function="graph:dep-lookup">
<param name="symbol"
select="$foo:document/preproc:symtable
/preproc:sym[ @name='missing-deps' ]" />
<param name="graph"
select="$foo:document/preproc:sym-deps" />
<param name="lookup" select="()" />
</call>
<expect label="return empty sequence"
test="empty( $x:result )" />
</scenario>
</scenario>
<scenario label="in a separate package">
<variable name="foo:expected-lookup" as="element()">
<foo:lookup-ok />
</variable>
<scenario label="where dependencies exist">
<call function="graph:dep-lookup">
<param name="symbol"
select="$foo:document/preproc:symtable
/preproc:sym[ @name='external' ]" />
<param name="graph"
select="$foo:document/preproc:sym-deps" />
<param name="lookup"
select="foo:lookup( $foo:expected-lookup )" />
</call>
<expect label="returns external dependenices"
test="exists( $x:result/foo:lookup-ok )" />
</scenario>
</scenario>
</scenario>
</scenario>
</description>