diff options
-rw-r--r-- | src/graph.xsl | 88 | ||||
-rw-r--r-- | test/graph.xspec | 173 |
2 files changed, 149 insertions, 112 deletions
diff --git a/src/graph.xsl b/src/graph.xsl index 387d183..0a80861 100644 --- a/src/graph.xsl +++ b/src/graph.xsl @@ -52,38 +52,6 @@ --> <!-- - 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, the graph @var{$graph} with the direction of all of its edges @@ -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> diff --git a/test/graph.xspec b/test/graph.xspec index c5e3216..7c823f0 100644 --- a/test/graph.xspec +++ b/test/graph.xspec @@ -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> |