# HG changeset patch # User Jari-Matti M?kel? # Date 1192642556 -10800 # Node ID 757bd048482c89d37217dfc205e9c5c8a9190f3b # Parent c82b36b9cadfc5694b1cf55a0e8eb99e314b16d8 Depgraph test + minor modifications. diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/graphutils/dotwriter.d --- a/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/graphutils/dotwriter.d Wed Oct 17 20:35:56 2007 +0300 @@ -8,6 +8,7 @@ import tango.io.FileConduit : FileConduit; import tango.io.Print: Print; import tango.text.convert.Layout : Layout; +import tango.io.FilePath; /** * Creates a graph rule file for the dot utility. @@ -35,6 +36,7 @@ if (cast(FileConduit)outputs[1]) { // name of the .dot file char[] fn = (cast(FileConduit)outputs[1]).toUtf8(); + fn = FilePath(fn).file; // .dot -> .svg/.png/.gif/... fn = fn[0..$-3] ~ imageFormatExts[factory.options.graph.imageFormat]; diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/sourcelisting/htmlwriter.d --- a/trunk/src/docgen/sourcelisting/htmlwriter.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/htmlwriter.d Wed Oct 17 20:35:56 2007 +0300 @@ -21,5 +21,5 @@ } void generateListing(Parser parser) { /* TODO */ } - void generateListing(InputStream input) { /* TODO */ } + void generateListing(InputStream input, char[] moduleName) { /* TODO */ } } \ No newline at end of file diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/sourcelisting/latexwriter.d --- a/trunk/src/docgen/sourcelisting/latexwriter.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/latexwriter.d Wed Oct 17 20:35:56 2007 +0300 @@ -8,8 +8,8 @@ import dil.Parser; import tango.io.protocol.Writer : Writer; import tango.io.FileConduit : FileConduit; -import tango.io.Buffer : Buffer; -import tango.io.Print: Print; +import tango.io.Print; +import tango.io.FilePath; import tango.text.convert.Layout : Layout; /** @@ -26,16 +26,15 @@ /* TODO */ } - void generateListing(InputStream input) { + void generateListing(InputStream input, char[] moduleName) { auto output2 = new Print!(char)(new Layout!(char), outputs[0]); if (cast(FileConduit)outputs[1]) { char[] fn = (cast(FileConduit)outputs[1]).toUtf8(); - output2.format("\\lstinputlisting[language=d]{{{0}}", fn); + fn = FilePath(fn).file; + output2.format("\\section{{Module {0}}\n", moduleName); + output2.format("\\lstinputlisting[language=d]{{{0}}\n", fn); } - - auto buf = new Buffer(256); - buf.output = outputs[1]; - buf.copy(input); + outputs[1].copy(input); } } diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/sourcelisting/plaintextwriter.d --- a/trunk/src/docgen/sourcelisting/plaintextwriter.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/plaintextwriter.d Wed Oct 17 20:35:56 2007 +0300 @@ -20,5 +20,5 @@ } void generateListing(Parser parser) { /* TODO */ } - void generateListing(InputStream input) { /* TODO */ } + void generateListing(InputStream input, char[] moduleName) { /* TODO */ } } \ No newline at end of file diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/sourcelisting/writer.d --- a/trunk/src/docgen/sourcelisting/writer.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/writer.d Wed Oct 17 20:35:56 2007 +0300 @@ -10,7 +10,7 @@ interface ListingWriter { void generateListing(Parser parser); - void generateListing(InputStream input); + void generateListing(InputStream input, char[] moduleName); } interface ListingWriterFactory : WriterFactory { diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/sourcelisting/writers.d --- a/trunk/src/docgen/sourcelisting/writers.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/writers.d Wed Oct 17 20:35:56 2007 +0300 @@ -16,7 +16,7 @@ } ListingWriter createListingWriter(OutputStream[] outputs) { - switch (m_options.docFormat) { + switch (options.docFormat) { case DocFormat.LaTeX: return new LaTeXWriter(this, outputs); case DocFormat.XML: diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/sourcelisting/xmlwriter.d --- a/trunk/src/docgen/sourcelisting/xmlwriter.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/sourcelisting/xmlwriter.d Wed Oct 17 20:35:56 2007 +0300 @@ -20,5 +20,5 @@ } void generateListing(Parser parser) { /* TODO */ } - void generateListing(InputStream input) { /* TODO */ } + void generateListing(InputStream input, char[] moduleName) { /* TODO */ } } \ No newline at end of file diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/templates/latexwriter.d --- a/trunk/src/docgen/templates/latexwriter.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/templates/latexwriter.d Wed Oct 17 20:35:56 2007 +0300 @@ -53,6 +53,7 @@ \setcounter{tocdepth}{1} \newcommand{\clearemptydoublepage}{\newpage{\pagestyle{empty}\cleardoublepage}} \def\thechapter{\Roman{chapter}} + \def\thesection{\arabic{chapter}.\arabic{section}} % \renewcommand{\footrulewidth}{0.4pt} \begin{document} diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/tests/graphs.d --- a/trunk/src/docgen/tests/graphs.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/tests/graphs.d Wed Oct 17 20:35:56 2007 +0300 @@ -5,9 +5,11 @@ module docgen.tests.graphs; import docgen.tests.common; +import docgen.misc.parser; import docgen.graphutils.writers; import tango.io.Stdout; import tango.io.FileConduit; +import dil.Module; void saveDefaultGraph(Vertex[] vertices, Edge[] edges, char[] fname) { auto gen = new TestDocGenerator; @@ -96,4 +98,44 @@ edges ~= a.addChild(g); saveDefaultGraph( [a,b,c,d,e,f,g], edges, "graph4.dot" ); +} + + +// parses the test modules and creates a dep graph +//@unittest +void graph5() { + auto gen = new TestDocGenerator; + gen.options.graph.HighlightCyclicVertices = true; + gen.options.graph.graphFormat = GraphFormat.Dot; + gen.options.docFormat = DocFormat.LaTeX; + auto fname = "dependencies.tex"; + auto imgFname = "depgraph.dot"; + + auto gwf = new DefaultGraphWriterFactory(gen); + auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); + auto imgFile = new FileConduit("docgen/teststuff/" ~ imgFname, FileConduit.WriteCreate); + + Module[] modules; + Edge[] edges; + Vertex[char[]] vertices; + int id = 1; + + Parser.loadModules( + [ "c" ], [ "docgen/teststuff/" ], + null, true, -1, + (char[] fqn, char[] path, Module m) { + vertices[m.moduleFQN] = new Vertex(m.moduleFQN, m.filePath, id++); + }, + (Module imported, Module importer) { + edges ~= vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); + }, + modules + ); + + auto writer = gwf.createGraphWriter( [ file, imgFile ] ); + + writer(vertices.values, edges); + + file.close(); + imgFile.close(); } \ No newline at end of file diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/tests/listing.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/docgen/tests/listing.d Wed Oct 17 20:35:56 2007 +0300 @@ -0,0 +1,51 @@ +/** + * Author: Jari-Matti Mäkelä + * License: GPL3 + */ +module docgen.tests.listing; + +import docgen.misc.parser; +import docgen.tests.common; +import docgen.sourcelisting.writers; +import dil.Module; +import tango.io.Stdout; +import tango.io.FileConduit; +import tango.text.Util; +import tango.io.protocol.Writer : Writer; + +// doc template +//@unittest +void listing1() { + auto gen = new TestDocGenerator; + gen.options.docFormat = DocFormat.LaTeX; + auto fname = "files.tex"; + + auto gwf = new DefaultListingWriterFactory(gen); + auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); + + + Module[] modules; + + Parser.loadModules( + [ "c" ], [ "docgen/teststuff/" ], + null, true, -1, + (char[] fqn, char[] path, Module m) {}, + (Module imported, Module importer) {}, + modules + ); + + foreach(mod; modules) { + auto dstFname = replace(mod.moduleFQN.dup, '.', '_'); + + auto srcFile = new FileConduit(mod.filePath); + auto dstFile = new FileConduit("docgen/teststuff/_" ~ dstFname ~ ".d", FileConduit.WriteCreate); + auto writer = gwf.createListingWriter( [ file, dstFile ] ); + + writer.generateListing(srcFile, mod.moduleFQN); + + srcFile.close(); + dstFile.close(); + } + + file.close(); +} \ No newline at end of file diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/tests/parse.d --- a/trunk/src/docgen/tests/parse.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/tests/parse.d Wed Oct 17 20:35:56 2007 +0300 @@ -24,22 +24,21 @@ //@unittest void parse1() { saveToFile("parse1.txt", (Print!(char) file){ + Module[] modules; - Module[] modules; - - Parser.loadModules( - [ "c" ], [ "docgen/teststuff/" ], - null, true, -1, - (char[] fqn, char[] path, Module m) { - file.format("{0} = {1}\n", fqn, path); - }, - (Module imported, Module importer) { - file.format("{0} <- {1}\n", - imported ? imported.moduleFQN : "null"[], - importer ? importer.moduleFQN : "null"[] - ); - }, - modules + Parser.loadModules( + [ "c" ], [ "docgen/teststuff/" ], + null, true, -1, + (char[] fqn, char[] path, Module m) { + file.format("{0} = {1}\n", fqn, path); + }, + (Module imported, Module importer) { + file.format("{0} <- {1}\n", + imported ? imported.moduleFQN : "null"[], + importer ? importer.moduleFQN : "null"[] + ); + }, + modules ); }); } @@ -47,23 +46,22 @@ // load the imports of dil //@unittest void parse2() { -saveToFile("parse2.txt", (Print!(char) file){ - -Module[] modules; - -Parser.loadModules( - [ "docgen/testsuite" ], [".", "/home/jm/d/tango/"], - null, true, -1, - (char[] fqn, char[] path, Module m) { - file.format("{0} = {1}\n", fqn, path); - }, - (Module imported, Module importer) { - file.format("{0} <- {1}\n", - imported ? imported.moduleFQN : "null"[], - importer ? importer.moduleFQN : "null"[] + saveToFile("parse2.txt", (Print!(char) file){ + Module[] modules; + + Parser.loadModules( + [ "docgen/testsuite" ], [".", "/home/jm/d/tango/"], + null, true, -1, + (char[] fqn, char[] path, Module m) { + file.format("{0} = {1}\n", fqn, path); + }, + (Module imported, Module importer) { + file.format("{0} <- {1}\n", + imported ? imported.moduleFQN : "null"[], + importer ? importer.moduleFQN : "null"[] + ); + }, + modules ); - }, - modules - ); -}); + }); } \ No newline at end of file diff -r c82b36b9cadf -r 757bd048482c trunk/src/docgen/testsuite.d --- a/trunk/src/docgen/testsuite.d Wed Oct 17 19:23:56 2007 +0300 +++ b/trunk/src/docgen/testsuite.d Wed Oct 17 20:35:56 2007 +0300 @@ -7,6 +7,7 @@ import docgen.tests.graphs; import docgen.tests.parse; import docgen.tests.doctemplate; +import docgen.tests.listing; import tango.io.Stdout; /** @@ -20,8 +21,10 @@ graph2(); graph3(); graph4(); + graph5(); parse1(); parse2(); doctemplate1(); + listing1(); Stdout("done.\n"); }