Mercurial > projects > dil
comparison 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 |
comparison
equal
deleted
inserted
replaced
728:41cad5ca4863 | 729:ec8dd7b8bf0c |
---|---|
9 import docgen.graphutils.writers; | 9 import docgen.graphutils.writers; |
10 import docgen.page.writers; | 10 import docgen.page.writers; |
11 import tango.io.FileConduit; | 11 import tango.io.FileConduit; |
12 import dil.semantic.Module; | 12 import dil.semantic.Module; |
13 | 13 |
14 void saveDefaultGraph(Vertex[] vertices, Edge[] edges, char[] fname) { | 14 alias DepGraph.Edge Edge; |
15 alias DepGraph.Vertex Vertex; | |
16 | |
17 void saveDefaultGraph(DepGraph depGraph, char[] fname) { | |
15 auto gen = new TestDocGenerator; | 18 auto gen = new TestDocGenerator; |
16 gen.options.graph.highlightCyclicVertices = true; | 19 gen.options.graph.highlightCyclicVertices = true; |
17 gen.options.graph.imageFormat = ImageFormat.SVG; | 20 gen.options.graph.imageFormat = ImageFormat.SVG; |
18 //gen.options.graph.graphFormat = GraphFormat.ModuleNames; | 21 //gen.options.graph.graphFormat = GraphFormat.ModuleNames; |
19 //gen.options.graph.graphFormat = GraphFormat.ModulePaths; | 22 //gen.options.graph.graphFormat = GraphFormat.ModulePaths; |
26 auto writer = gwf.createGraphWriter( | 29 auto writer = gwf.createGraphWriter( |
27 ddf.createPageWriter( [ file2 ], DocFormat.LaTeX), | 30 ddf.createPageWriter( [ file2 ], DocFormat.LaTeX), |
28 GraphFormat.Dot | 31 GraphFormat.Dot |
29 ); | 32 ); |
30 | 33 |
31 writer.generateDepGraph(vertices, edges, file); | 34 writer.generateDepGraph(depGraph, file); |
32 | 35 |
33 file.close(); | 36 file.close(); |
34 file2.close(); | 37 file2.close(); |
35 } | 38 } |
36 | 39 |
37 // no edges | 40 // no edges |
38 //@unittest | 41 //@unittest |
39 void graph1() { | 42 void graph1() { |
40 auto a = new Vertex("mod_a", "path.to.mod_a", 1); | 43 auto g = new DepGraph; |
41 auto b = new Vertex("mod_b", "path.to.mod_b", 2); | 44 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); |
42 auto c = new Vertex("mod_c", "path.to.mod_c", 3); | 45 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); |
46 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); | |
43 | 47 |
44 saveDefaultGraph( [a,b,c], null, "graph1.dot" ); | 48 saveDefaultGraph(g, "graph1.dot"); |
45 } | 49 } |
46 | 50 |
47 | 51 |
48 // simple tree structure | 52 // simple tree structure |
49 //@unittest | 53 //@unittest |
50 void graph2() { | 54 void graph2() { |
51 auto a = new Vertex("mod_a", "path.to.mod_a", 1); | 55 auto g = new DepGraph; |
52 auto b = new Vertex("mod_b", "path.to.mod_b", 2); | 56 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); |
53 auto c = new Vertex("mod_c", "path.to.mod_c", 3); | 57 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); |
54 auto d = new Vertex("mod_d", "path.to.mod_d", 4); | 58 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); |
59 g.add(new Vertex("mod_d", "path.to.mod_d", 4)); | |
55 | 60 |
56 Edge[] edges; | 61 g.connect(1, 0); |
57 edges ~= a.addChild(b); | 62 g.connect(2, 0); |
58 edges ~= a.addChild(c); | 63 g.connect(3, 2); |
59 edges ~= c.addChild(d); | |
60 | 64 |
61 saveDefaultGraph( [a,b,c,d], edges, "graph2.dot" ); | 65 saveDefaultGraph(g, "graph2.dot"); |
62 } | 66 } |
63 | 67 |
64 // circular imports | 68 // circular imports |
65 //@unittest | 69 //@unittest |
66 void graph3() { | 70 void graph3() { |
67 auto a = new Vertex("mod_a", "path.to.mod_a", 1); | 71 auto g = new DepGraph; |
68 auto b = new Vertex("mod_b", "path.to.mod_b", 2); | 72 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); |
69 auto c = new Vertex("mod_c", "path.to.mod_c", 3); | 73 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); |
70 auto d = new Vertex("mod_d", "path.to.mod_d", 4); | 74 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); |
75 g.add(new Vertex("mod_d", "path.to.mod_d", 4)); | |
71 | 76 |
72 Edge[] edges; | 77 g.connect(1, 0); |
73 edges ~= a.addChild(b); | 78 g.connect(2, 1); |
74 edges ~= b.addChild(c); | 79 g.connect(0, 2); |
75 edges ~= c.addChild(a); | 80 |
76 | 81 saveDefaultGraph(g, "graph3.dot"); |
77 saveDefaultGraph( [a,b,c,d], edges, "graph3.dot" ); | |
78 } | 82 } |
79 | 83 |
80 // more complex graph | 84 // more complex graph |
81 //@unittest | 85 //@unittest |
82 void graph4() { | 86 void graph4() { |
83 auto a = new Vertex("mod_a", "path.to.mod_a", 1); | 87 auto g = new DepGraph; |
84 auto b = new Vertex("mod_b", "path.to.mod_b", 2); | 88 g.add(new Vertex("mod_a", "path.to.mod_a", 1)); |
85 auto c = new Vertex("mod_c", "path.to.mod_c", 3); | 89 g.add(new Vertex("mod_b", "path.to.mod_b", 2)); |
86 auto d = new Vertex("mod_d", "path.to.mod_d", 4); | 90 g.add(new Vertex("mod_c", "path.to.mod_c", 3)); |
87 auto e = new Vertex("mod_e", "path.to.mod_e", 5); | 91 g.add(new Vertex("mod_d", "path.to.mod_d", 4)); |
88 auto f = new Vertex("mod_f", "path.to.mod_f", 6); | 92 g.add(new Vertex("mod_e", "path.to.mod_e", 5)); |
89 auto g = new Vertex("mod_g", "path.to.mod_g", 7); | 93 g.add(new Vertex("mod_f", "path.to.mod_f", 6)); |
94 g.add(new Vertex("mod_g", "path.to.mod_g", 7)); | |
90 | 95 |
91 Edge[] edges; | 96 g.connect(1, 0); |
92 edges ~= a.addChild(b); | 97 g.connect(2, 1); |
93 edges ~= b.addChild(c); | 98 g.connect(0, 2); |
94 edges ~= c.addChild(a); | 99 g.connect(0, 3); |
95 edges ~= d.addChild(a); | 100 g.connect(0, 4); |
96 edges ~= e.addChild(a); | 101 g.connect(3, 1); |
97 edges ~= b.addChild(d); | 102 g.connect(4, 1); |
98 edges ~= b.addChild(e); | 103 g.connect(0, 6); |
99 edges ~= g.addChild(a); | 104 g.connect(5, 1); |
100 edges ~= b.addChild(f); | 105 g.connect(5, 6); |
101 edges ~= g.addChild(f); | 106 g.connect(6, 0); |
102 edges ~= a.addChild(g); | |
103 | 107 |
104 saveDefaultGraph( [a,b,c,d,e,f,g], edges, "graph4.dot" ); | 108 saveDefaultGraph(g, "graph4.dot"); |
105 } | 109 } |
106 | 110 |
107 | 111 |
108 // parses the test modules and creates a dep graph | 112 // parses the test modules and creates a dep graph |
109 //@unittest | 113 //@unittest |
127 | 131 |
128 Parser.loadModules( | 132 Parser.loadModules( |
129 [ "c" ], [ "docgen/teststuff/" ], | 133 [ "c" ], [ "docgen/teststuff/" ], |
130 null, true, -1, | 134 null, true, -1, |
131 (char[] fqn, char[] path, Module m) { | 135 (char[] fqn, char[] path, Module m) { |
132 vertices[m.moduleFQN] = new Vertex(m.moduleFQN, m.filePath, id++); | 136 vertices[m.moduleFQN] = new DepGraph.Vertex(m.moduleFQN, m.filePath, id++); |
133 }, | 137 }, |
134 (Module imported, Module importer, bool isPublic) { | 138 (Module imported, Module importer, bool isPublic) { |
135 auto edge = vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); | 139 auto edge = vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); |
136 edge.type = isPublic ? EdgeType.PublicDependency : EdgeType.Dependency; | 140 edge.isPublic = isPublic; |
137 edges ~= edge; | 141 edges ~= edge; |
138 }, | 142 }, |
139 modules | 143 modules |
140 ); | 144 ); |
141 | 145 |
142 auto writer = gwf.createGraphWriter( | 146 auto writer = gwf.createGraphWriter( |
143 ddf.createPageWriter( [ file ], DocFormat.LaTeX ), | 147 ddf.createPageWriter( [ file ], DocFormat.LaTeX ), |
144 GraphFormat.Dot | 148 GraphFormat.Dot |
145 ); | 149 ); |
146 | 150 |
147 writer.generateDepGraph(vertices.values, edges, imgFile); | 151 auto graph = new DepGraph; |
152 graph.edges = edges; | |
153 graph.vertices = vertices.values; | |
154 | |
155 writer.generateDepGraph(graph, imgFile); | |
148 | 156 |
149 file.close(); | 157 file.close(); |
150 imgFile.close(); | 158 imgFile.close(); |
151 } | 159 } |