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