Mercurial > projects > dil
annotate trunk/src/docgen/tests/graphs.d @ 729:ec8dd7b8bf0c
Updated graph type.
author | Jari-Matti M?kel? <jmjm@iki.fi> |
---|---|
date | Sun, 03 Feb 2008 19:43:53 +0200 |
parents | cb8edb09108a |
children | 231c9a44ba8e |
rev | line source |
---|---|
441 | 1 /** |
2 * Author: Jari-Matti Mäkelä | |
3 * License: GPL3 | |
4 */ | |
5 module docgen.tests.graphs; | |
6 | |
446 | 7 import docgen.tests.common; |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
8 import docgen.misc.parser; |
441 | 9 import docgen.graphutils.writers; |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
10 import docgen.page.writers; |
441 | 11 import tango.io.FileConduit; |
717
cb8edb09108a
Updated docgen (mostly) to new tango.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
12 import dil.semantic.Module; |
441 | 13 |
729 | 14 alias DepGraph.Edge Edge; |
15 alias DepGraph.Vertex Vertex; | |
16 | |
17 void saveDefaultGraph(DepGraph depGraph, char[] fname) { | |
446 | 18 auto gen = new TestDocGenerator; |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
19 gen.options.graph.highlightCyclicVertices = true; |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
20 gen.options.graph.imageFormat = ImageFormat.SVG; |
446 | 21 //gen.options.graph.graphFormat = GraphFormat.ModuleNames; |
22 //gen.options.graph.graphFormat = GraphFormat.ModulePaths; | |
23 gen.options.graph.depth = 5; | |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
24 auto ddf = new DefaultPageWriterFactory(gen); |
446 | 25 auto gwf = new DefaultGraphWriterFactory(gen); |
441 | 26 auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); |
27 auto file2 = new FileConduit("docgen/teststuff/" ~ fname ~ "-2", FileConduit.WriteCreate); | |
717
cb8edb09108a
Updated docgen (mostly) to new tango.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
28 |
454
dbdc9fa5d479
depgraph fixes, better design for multiple doctargets.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
453
diff
changeset
|
29 auto writer = gwf.createGraphWriter( |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
30 ddf.createPageWriter( [ file2 ], DocFormat.LaTeX), |
454
dbdc9fa5d479
depgraph fixes, better design for multiple doctargets.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
453
diff
changeset
|
31 GraphFormat.Dot |
dbdc9fa5d479
depgraph fixes, better design for multiple doctargets.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
453
diff
changeset
|
32 ); |
441 | 33 |
729 | 34 writer.generateDepGraph(depGraph, file); |
441 | 35 |
36 file.close(); | |
37 file2.close(); | |
38 } | |
39 | |
40 // no edges | |
41 //@unittest | |
42 void graph1() { | |
729 | 43 auto g = new DepGraph; |
44 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); | |
45 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); | |
46 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); | |
441 | 47 |
729 | 48 saveDefaultGraph(g, "graph1.dot"); |
441 | 49 } |
50 | |
51 | |
52 // simple tree structure | |
53 //@unittest | |
54 void graph2() { | |
729 | 55 auto g = new DepGraph; |
56 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); | |
57 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); | |
58 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); | |
59 g.add(new Vertex("mod_d", "path.to.mod_d", 4)); | |
441 | 60 |
729 | 61 g.connect(1, 0); |
62 g.connect(2, 0); | |
63 g.connect(3, 2); | |
441 | 64 |
729 | 65 saveDefaultGraph(g, "graph2.dot"); |
441 | 66 } |
67 | |
68 // circular imports | |
69 //@unittest | |
70 void graph3() { | |
729 | 71 auto g = new DepGraph; |
72 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); | |
73 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); | |
74 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); | |
75 g.add(new Vertex("mod_d", "path.to.mod_d", 4)); | |
441 | 76 |
729 | 77 g.connect(1, 0); |
78 g.connect(2, 1); | |
79 g.connect(0, 2); | |
80 | |
81 saveDefaultGraph(g, "graph3.dot"); | |
441 | 82 } |
83 | |
84 // more complex graph | |
85 //@unittest | |
86 void graph4() { | |
729 | 87 auto g = new DepGraph; |
88 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); | |
89 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); | |
90 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); | |
91 g.add(new Vertex("mod_d", "path.to.mod_d", 4)); | |
92 g.add(new Vertex("mod_e", "path.to.mod_e", 5)); | |
93 g.add(new Vertex("mod_f", "path.to.mod_f", 6)); | |
94 g.add(new Vertex("mod_g", "path.to.mod_g", 7)); | |
441 | 95 |
729 | 96 g.connect(1, 0); |
97 g.connect(2, 1); | |
98 g.connect(0, 2); | |
99 g.connect(0, 3); | |
100 g.connect(0, 4); | |
101 g.connect(3, 1); | |
102 g.connect(4, 1); | |
103 g.connect(0, 6); | |
104 g.connect(5, 1); | |
105 g.connect(5, 6); | |
106 g.connect(6, 0); | |
441 | 107 |
729 | 108 saveDefaultGraph(g, "graph4.dot"); |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
109 } |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
110 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
111 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
112 // parses the test modules and creates a dep graph |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
113 //@unittest |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
114 void graph5() { |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
115 auto gen = new TestDocGenerator; |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
116 gen.options.graph.highlightCyclicVertices = true; |
454
dbdc9fa5d479
depgraph fixes, better design for multiple doctargets.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
453
diff
changeset
|
117 gen.options.graph.imageFormat = ImageFormat.PDF; |
dbdc9fa5d479
depgraph fixes, better design for multiple doctargets.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
453
diff
changeset
|
118 gen.options.outputFormats = [ DocFormat.LaTeX ]; |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
119 auto fname = "dependencies.tex"; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
120 auto imgFname = "depgraph.dot"; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
121 |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
122 auto ddf = new DefaultPageWriterFactory(gen); |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
123 auto gwf = new DefaultGraphWriterFactory(gen); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
124 auto file = new FileConduit("docgen/teststuff/" ~ fname, FileConduit.WriteCreate); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
125 auto imgFile = new FileConduit("docgen/teststuff/" ~ imgFname, FileConduit.WriteCreate); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
126 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
127 Module[] modules; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
128 Edge[] edges; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
129 Vertex[char[]] vertices; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
130 int id = 1; |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
131 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
132 Parser.loadModules( |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
133 [ "c" ], [ "docgen/teststuff/" ], |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
134 null, true, -1, |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
135 (char[] fqn, char[] path, Module m) { |
729 | 136 vertices[m.moduleFQN] = new DepGraph.Vertex(m.moduleFQN, m.filePath, id++); |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
137 }, |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
138 (Module imported, Module importer, bool isPublic) { |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
139 auto edge = vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); |
729 | 140 edge.isPublic = isPublic; |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
141 edges ~= edge; |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
142 }, |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
143 modules |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
144 ); |
451
3f44c38bf870
Page templates, more flexible writer interfaces, small fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
449
diff
changeset
|
145 |
454
dbdc9fa5d479
depgraph fixes, better design for multiple doctargets.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
453
diff
changeset
|
146 auto writer = gwf.createGraphWriter( |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
147 ddf.createPageWriter( [ file ], DocFormat.LaTeX ), |
454
dbdc9fa5d479
depgraph fixes, better design for multiple doctargets.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
453
diff
changeset
|
148 GraphFormat.Dot |
dbdc9fa5d479
depgraph fixes, better design for multiple doctargets.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
453
diff
changeset
|
149 ); |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
150 |
729 | 151 auto graph = new DepGraph; |
152 graph.edges = edges; | |
153 graph.vertices = vertices.values; | |
154 | |
155 writer.generateDepGraph(graph, imgFile); | |
449
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
156 |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
157 file.close(); |
757bd048482c
Depgraph test + minor modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
158 imgFile.close(); |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
451
diff
changeset
|
159 } |