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