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