docgenerator 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/examples/creole_example_tabular.rb +95 -0
  2. data/examples/docgenerator_example.rb +5 -5
  3. data/lib/creole/creole2doc.rb +28 -18
  4. data/lib/creole/creole_inclusions.rb +4 -4
  5. data/lib/creole/creole_placeholder.rb +4 -1
  6. data/lib/creole/creole_tabular.rb +173 -155
  7. data/lib/creole/plugins/rail.rb +118 -119
  8. data/lib/creole/plugins/struktex.rb +35 -35
  9. data/lib/creole/plugins/todonotes.rb +8 -1
  10. data/lib/docgenerator/attribute.rb +160 -160
  11. data/lib/docgenerator/characters.rb +343 -311
  12. data/lib/docgenerator/css.rb +167 -167
  13. data/lib/docgenerator/document.rb +525 -511
  14. data/lib/docgenerator/element.rb +316 -316
  15. data/lib/docgenerator/element_meta.rb +114 -114
  16. data/lib/docgenerator/elements.rb +19 -9
  17. data/lib/docgenerator/environments.rb +3 -1
  18. data/lib/docgenerator/lists.rb +177 -174
  19. data/lib/docgenerator/packages/hyperref.rb +74 -70
  20. data/lib/docgenerator/packages/multicol.rb +33 -0
  21. data/lib/docgenerator/packages/scrlettr2.rb +152 -151
  22. data/lib/docgenerator/packages/todonotes.rb +1 -1
  23. data/lib/docgenerator/tabular.rb +463 -400
  24. data/lib/docgenerator/templates/docgenerator_template.rb +94 -84
  25. data/lib/docgenerator/templates/docgenerator_template.yaml +75 -15
  26. data/lib/docgenerator.rb +1 -1
  27. data/lib/wiki2doc/wiki2docgenerator.rb +1 -1
  28. data/meta_test_and_doc/build__meta.rb +125 -0
  29. data/meta_test_and_doc/build_doc.rb +333 -0
  30. data/meta_test_and_doc/build_test.rb +251 -0
  31. data/meta_test_and_doc/manpages/attachfile.rb +389 -0
  32. data/meta_test_and_doc/manpages/caption.rb +133 -0
  33. data/meta_test_and_doc/manpages/characters.rb +3738 -0
  34. data/meta_test_and_doc/manpages/elements.rb +6851 -0
  35. data/meta_test_and_doc/manpages/environments.rb +985 -0
  36. data/meta_test_and_doc/manpages/footnote.rb +439 -0
  37. data/meta_test_and_doc/manpages/hyperref.rb +605 -0
  38. data/meta_test_and_doc/manpages/listings.rb +988 -0
  39. data/meta_test_and_doc/manpages/lists.rb +1463 -0
  40. data/meta_test_and_doc/manpages/others.rb +129 -0
  41. data/meta_test_and_doc/manpages/packages.rb +13 -0
  42. data/meta_test_and_doc/manpages/pdfpages.rb +108 -0
  43. data/meta_test_and_doc/manpages/readme.rdoc +9 -0
  44. data/meta_test_and_doc/manpages/scrlettr2.rb +362 -0
  45. data/meta_test_and_doc/manpages/scrpage2.rb +2028 -0
  46. data/meta_test_and_doc/manpages/sectioning.rb +2467 -0
  47. data/meta_test_and_doc/manpages/tables.rb +2088 -0
  48. data/meta_test_and_doc/manpages/todonotes.rb +235 -0
  49. data/meta_test_and_doc/manpages/wiki2docgenerator.rb +64 -0
  50. data/{readme.rd → readme.rdoc} +18 -1
  51. data/unittest/expected/test_tabular.creole +33 -0
  52. data/unittest/expected_creole/test_creole_creole1.0test.html +3 -3
  53. data/unittest/expected_creole/test_creole_creole1.0test.latex +3 -3
  54. data/unittest/expected_creole/test_creole_creole1.0test.text +3 -3
  55. data/unittest/expected_creole/test_creole_inline_apostroph.html +6 -0
  56. data/unittest/expected_creole/test_creole_inline_apostroph.latex +8 -0
  57. data/unittest/expected_creole/test_creole_inline_apostroph.text +4 -0
  58. data/unittest/expected_creole/test_creole_input.normsource +12 -12
  59. data/unittest/expected_creole/test_creole_input.normsource_1.8 +23 -0
  60. data/unittest/expected_creole/test_creole_links_external_implicit.html +2 -2
  61. data/unittest/expected_creole/test_creole_links_external_implicit.latex +2 -2
  62. data/unittest/expected_creole/test_creole_links_external_implicit.text +2 -2
  63. data/unittest/expected_creole/test_creole_links_implicit_end.html +1 -1
  64. data/unittest/expected_creole/test_creole_links_implicit_end.latex +1 -1
  65. data/unittest/expected_creole/test_creole_list_ul.normsource +42 -42
  66. data/unittest/expected_creole/test_creole_list_ul.normsource_1.8 +83 -0
  67. data/unittest/expected_creole/test_creole_paragraphs.normsource +15 -15
  68. data/unittest/expected_creole/test_creole_paragraphs.normsource_1.8 +27 -0
  69. data/unittest/expected_creole/test_creole_tabular.creole +22 -0
  70. data/unittest/expected_creole/test_creole_tabular_creole.creole +19 -0
  71. data/unittest/expected_creole/test_creole_tabular_css.creole +24 -0
  72. data/unittest/expected_creole/test_creole_tabular_multicols.creole +16 -0
  73. data/unittest/expected_creole/test_creole_tabular_multicols.html +14 -0
  74. data/unittest/expected_creole/test_creole_tabular_multicols.latex +16 -0
  75. data/unittest/expected_creole/test_creole_tabular_with_cell_option.creole +21 -0
  76. data/unittest/expected_creole/test_creole_toc_level_text.html +2 -2
  77. data/unittest/expected_creole/test_creole_toc_level_text.latex +2 -2
  78. data/unittest/expected_packages/test_multicol_3.tex +2 -0
  79. data/unittest/expected_packages/test_multicol_3_titleline.tex +2 -0
  80. data/unittest/expected_templates/test_article.tex +23 -0
  81. data/unittest/expected_templates/test_article_utf8.tex +34 -0
  82. data/unittest/expected_templates/test_context.miv +18 -0
  83. data/unittest/expected_templates/test_creole.creole +8 -0
  84. data/unittest/expected_templates/test_html.html +12 -0
  85. data/unittest/expected_templates/test_html401_strict.html +14 -0
  86. data/unittest/expected_templates/test_html401_trans.html +14 -0
  87. data/unittest/expected_templates/test_html_utf8.html +14 -0
  88. data/unittest/expected_templates/test_include.tex +17 -0
  89. data/unittest/expected_templates/test_include_utf8.tex +17 -0
  90. data/unittest/expected_templates/test_text.txt +6 -0
  91. data/unittest/expected_templates/test_wiki.wiki +6 -0
  92. data/unittest/expected_templates/test_xhtml_strict.html +14 -0
  93. data/unittest/expected_templates/test_xhtml_trans.html +14 -0
  94. data/unittest/unittest_creole.rb +27 -6
  95. data/unittest/unittest_creole_placeholders.rb +1 -123
  96. data/unittest/unittest_creole_tabular.rb +174 -0
  97. data/unittest/unittest_docgenerator.rb +4 -3
  98. data/unittest/unittest_docgenerator_characters.rb +4769 -615
  99. data/unittest/unittest_packages_multicol.rb +84 -0
  100. data/unittest/unittest_rubycode4doc.rb +0 -1
  101. data/unittest/unittest_templates.rb +64 -0
  102. metadata +163 -77
  103. data/build_test_and_doc.rb +0 -505
  104. data/manpage_elements.rb +0 -10411
@@ -0,0 +1,333 @@
1
+ =begin rdoc
2
+ Build manpages for docgenerator.
3
+ =end
4
+ require_relative 'build__meta'
5
+ $log = Log4r::Logger.new('doc')
6
+ $log.outputters << Log4r::StdoutOutputter.new('stdout')
7
+
8
+ DOCHEADER = <<xx
9
+ =begin rdoc
10
+ Generated manpages for elements.
11
+
12
+ This document does not contain the implementation or code documentation.
13
+
14
+ This document is the source for a manpage for usage of Docgenerator elements.
15
+
16
+ The following Element are documented in this document:
17
+ xx
18
+
19
+ =begin rdoc
20
+ Prepare a documentation, based on execution and meta-analyse.
21
+ =end
22
+ def mk_element_doc(elementlist, filename )
23
+
24
+ rd_code = [
25
+ DOCHEADER,
26
+ list_of_elements = [],
27
+ "=end\n\n#"
28
+ ]
29
+ $log.info("Prepare #{filename}")
30
+
31
+ elementlist.each{|cl|
32
+ list_of_elements << "* #{cl.name}"
33
+
34
+ names = cl.name.to_s.split('::')
35
+ class_name = names.pop
36
+ ident = ''
37
+ names.each{|name|
38
+ rd_code << "#{ident}module #{name}"
39
+ ident << " "
40
+ }
41
+ rd_code << "=begin rdoc"
42
+ rd_code << mk_element_manpage(cl)
43
+ rd_code << "=end"
44
+
45
+ rd_code << "#{ident}class #{class_name}"
46
+ rd_code.last << " << #{cl.ancestors[1]}" #add ancestor
47
+ rd_code << "#{ident}#This coding is empty - this is the manpage definition, not the implementation"
48
+ rd_code << "#{ident}end #class #{class_name}"
49
+ names.reverse.each{|name|
50
+ ident.slice!(0..1)
51
+ rd_code << "#{ident}end #module #{name}"
52
+ }
53
+
54
+
55
+ } #Element.each
56
+
57
+ File.open(filename, 'w:utf-8'){|f_test|
58
+ $log.info("Create #{f_test.path}")
59
+ f_test << "#encoding utf-8\n"
60
+ f_test << rd_code.join("\n")
61
+ }
62
+
63
+ end #mk_element_doc
64
+
65
+ =begin rdoc
66
+ Create rdoc-code for element.
67
+
68
+ The documentation for the methods to_latex, to_html... is added
69
+ to the class.
70
+
71
+ We could put the documentation to the methods, but rdoc will take only
72
+ the documentation of the first definition.
73
+ Class documentation is added to the existing implementation documentation.
74
+ =end
75
+ def mk_element_manpage(cl)
76
+
77
+ $log.info("Create manpage content for #{cl.name}")
78
+ log = Log4r::Logger.new('log', Log4r::WARN) #avoid message
79
+ log.outputters = logoutputter = ArrayOutputter.new('xx')
80
+ rd_code = []
81
+ el = cl.new(:log => log )
82
+ rd_code << <<code
83
+ =#{cl.name}
84
+ code
85
+
86
+ #See also ::#{cl.name}
87
+
88
+ if el.attr.empty?
89
+ rd_code<< "#{cl.name} does not contain attributes"
90
+ else
91
+ #
92
+ # Attribute overview has three variants:
93
+ # - tab -- does not work
94
+ # - tab_ascii
95
+ # - list -- very long, bad vor overview -> not used
96
+ rd_code<< "==Attributes"
97
+ rd_code << mk_attr_overview(:tab_ascii, el.attr, el)
98
+ #~ rd_code << mk_attr_overview(:tab, el.attr)
99
+ #~ rd_code << mk_attr_overview(:list, el.attr)
100
+ end
101
+
102
+ rd_code<< "\n"
103
+ #~ rd_code<< "==Content"
104
+ if el.content?
105
+ el << 'content'
106
+ rd_code<< "#{cl.name} can contain content."
107
+ else
108
+ rd_code<< "#{cl.name} allows no content."
109
+ end
110
+
111
+ rd_code<< "\n==Generate an object"
112
+ cmd = " test = #{el.class}.new( "
113
+ if ! el.attr.empty?
114
+ cmd << "{"
115
+ el.attr.sort_by{|k,a| a.sortkey }.each{|k,a|
116
+ #~ cmd << "\n #{k.inspect} => #{a.content.empty? ? "''" : a.content.inspect}, #"
117
+ cmd << "\n %s%-20s => <<value>>, %% %s%s" % [
118
+ a.required? ? " " : '#',
119
+ k.inspect,
120
+ #~ a.content.empty? ? "''" : a.content.inspect,
121
+ a.required? ? "required" : 'optional',
122
+ a.allowed_values ? ", values: #{a.allowed_values.inspect}" : '',
123
+ ]
124
+ }
125
+ cmd << "\n }"
126
+ else
127
+ cmd << "{}" if el.content?
128
+ end
129
+ cmd << ", 'content'" if el.content?
130
+ cmd << ")"
131
+
132
+ #~ cmd << "\n test << #{el.content.inspect}" if el.content?
133
+
134
+ cmd << "\n\nAlternative generation\n"
135
+ el.element_ids.each{|id|
136
+ cmd << " test = element(#{id.inspect}"
137
+ if el.attr.empty?
138
+ cmd << ", {}" if el.content?
139
+ else
140
+ cmd << ", {...Attributes...}"
141
+ end
142
+ cmd << ", 'content' " if el.content?
143
+ cmd << ")\n"
144
+ }
145
+ rd_code << cmd
146
+
147
+
148
+ rd_code<< "\n==Outputs"
149
+
150
+
151
+ %w{latex html context text wiki creole}.each{|target|
152
+ check_cr = true #Is it necessary to check #cr, 'Cr...
153
+
154
+ el2 = el.dup #later check with cr, cR... would modify the result
155
+
156
+ logoutputter.flush #clear messages
157
+ result = el.send("to_#{target}".to_sym, :log => log)
158
+ rd_code<< <<code
159
+ ===#{cl.name}#to_#{target}
160
+ #{result.gsub(/^/, " ")}
161
+ code
162
+ logoutputter.flush.each{|message|
163
+ case message
164
+ when /(Missing output routine for .*)\(/
165
+ rd_code << "* No output routine defined for #{target} - use a dummy"
166
+ check_cr = false
167
+ when /No related document for tableofcontents/
168
+ when %r{ERROR log: :li/wiki: Unknown list type nil}
169
+ when /multicolumn without latex-position/ #Docgenerator::Tables::Multicolumn
170
+ else
171
+ $log.error("Uncatched message: #{message.strip} for #{cl.name}")
172
+ end
173
+ } #logoutputter.flush
174
+
175
+ #try different cr-commands
176
+ if check_cr
177
+ rd_code << <<code
178
+ ====:cr, :cR, :Cr, :CR for #{cl.name}#.to_#{target}
179
+ <<START>> and <<END>> are not part of the output, but needed to illustrate the line breaks.
180
+
181
+ Default:
182
+ #{"<<START>>#{result}<<END>>".gsub(/^/, " ")}
183
+ code
184
+ [ :cr, :cR, :Cr, :CR ].each{| cr |
185
+ el2.send(cr)
186
+ result2 = el2.send("to_#{target}".to_sym, :log => log)
187
+
188
+ if result == result2
189
+ rd_code << "* #{cl.name}##{cr} has no effect, same result as default"
190
+ else
191
+ rd_code << <<code
192
+ * Result after #{cl.name}##{cr}:
193
+
194
+ #{"<<START>>#{result2}<<END>>".gsub(/^/, " ")}
195
+ code
196
+ end
197
+ } #different cr-commands
198
+ end
199
+ } #targets
200
+ rd_code
201
+ end #mk_element_manpage
202
+
203
+ def mk_attr_overview(variant, attr, el)
204
+ tab = element(:tabular, columns: 10).Cr
205
+ tab << row = element(:row ).cr
206
+ row << element(:th, {}, 'Name')
207
+ row << element(:th, {}, 'required?')
208
+ row << element(:th, {}, 'HTML')
209
+ row << element(:th, {}, 'LaTeX')
210
+ row << element(:th, {}, '~keyval')
211
+ row << element(:th, {}, 'ConTeXt')
212
+ row << element(:th, {}, 'Text')
213
+ row << element(:th, {}, 'Wiki')
214
+ row << element(:th, {}, 'Creole')
215
+ row << element(:th, {}, 'Values')
216
+
217
+ tab_ascii = [' '] #two spaces to get a ASCII-Tabular layout
218
+ tab_ascii.last << '%-20s ' % 'Attribute'
219
+ tab_ascii.last << "%-10s" % 'required?'
220
+ tab_ascii.last << "%-10s" % 'HTML'
221
+ tab_ascii.last << "%-10s" % 'LaTeX'
222
+ tab_ascii.last << "%-10s" % '~keyval'
223
+ tab_ascii.last << "%-10s" % 'ConTeXt'
224
+ tab_ascii.last << "%-10s" % 'Text'
225
+ tab_ascii.last << "%-10s" % 'Wiki'
226
+ tab_ascii.last << "%-10s" % 'Creole'
227
+ tab_ascii.last << "%-10s" % 'Values'
228
+ tab_ascii << ' ' + "=" * 100
229
+
230
+ list = ['Attribute List:']
231
+
232
+ attr.sort_by{|k,a| a.sortkey }.each{|k,a|
233
+ ##fixme element(:radic) statt 'X'? -> http://www.google.de/url?sa=t&rct=j&q=rdoc%20table%20hanna&source=web&cd=1&ved=0CGoQFjAA&url=http%3A%2F%2Fforum.ruby-portal.de%2Fviewtopic.php%3Ff%3D6%26t%3D12387&ei=92PYT8COD4TFswah7fGeDw&usg=AFQjCNFw0KuMKykdsgCpASxRtvaybkG6GA
234
+ tab << row = element(:row).cr
235
+ row << element(:col, {}, k.inspect)
236
+ row << element(:col, {}, a.required? ? 'X' : '-' )
237
+ row << element(:col, {}, a.html? ? 'X' : '-' )
238
+ row << element(:col, {}, a.latex? ? 'X' : '-' )
239
+ row << element(:col, {}, a.texkeyval? ? 'X' : '-' )
240
+ row << element(:col, {}, a.context? ? 'X' : '-' )
241
+ row << element(:col, {}, a.text? ? 'X' : '-' )
242
+ row << element(:col, {}, a.wiki? ? 'X' : '-' )
243
+ row << element(:col, {}, a.creole? ? 'X' : '-' )
244
+
245
+ list << "* #{k}:"
246
+ tab_ascii << " %-20s: " % k
247
+ %w{required html latex texkeyval context text wiki creole}.each{|key|
248
+ list << " * #{key}: #{ a.send("#{key}?".to_sym) ? 'X' : '-' } "
249
+ tab_ascii.last << " %-9s" % (a.send("#{key}?".to_sym) ? 'X' : '-')
250
+ }
251
+
252
+ #~ rd_code << "===Attribute #{k.inspect}"
253
+ if a.required?
254
+ #this may give an error, if the attribute has wrong type/layout...
255
+ el[k] << "Value for #{k}"
256
+ #~ rd_code << "* required"
257
+ #~ else
258
+ #~ rd_code << "* optional"
259
+ end
260
+ #~ rd_code << "* used for:"
261
+ #~ rd_code << " * HTML" if a.html?()
262
+ #~ rd_code << " * LaTeX" if a.latex?()
263
+ #~ rd_code << " * LaTeX as key-val parameter" if a.texkeyval?()
264
+ #~ rd_code << " * ConTeXt" if a.context?()
265
+ #~ rd_code << " * text" if a.text?()
266
+ #~ rd_code << " * wiki (wikimedia)" if a.wiki?()
267
+ #~ rd_code << " * wiki (creole)" if a.creole?()
268
+
269
+ row << col = element(:col)
270
+ if a.allowed_values
271
+ col << ul = element(:ul)
272
+ #~ rd_code << "* Allowed values:"
273
+ a.allowed_values.each{|x|
274
+ ul << element(:li,{}, x.inspect)
275
+ #~ rd_code << " * #{x.inspect}"
276
+ }
277
+ end
278
+ }
279
+
280
+ case variant
281
+ when :tab
282
+ tab.to_html(:log=> log)# does not work correct
283
+ when :tab_ascii
284
+ tab_ascii
285
+ when :list
286
+ list #very long
287
+ end
288
+
289
+ end #mk_attr_overview
290
+
291
+
292
+ desc "Create all manpages"
293
+ task :all_man_files
294
+ #Build single file tasks
295
+ #Create file task
296
+ FILE_SEPARATION.each{|key, elementlist|
297
+ filename = File.join('manpages', key)
298
+ file filename do |tsk| mk_element_doc(elementlist, tsk.name); end #Create file task
299
+ task :all_man_files => filename #add file task as prerequisite to :all_man_files
300
+ }
301
+
302
+ task :force
303
+ task :clean do
304
+ Rake.application[:all_man_files].prerequisites.each{|f|
305
+ File.delete(f) if File.exist?(f)
306
+ }
307
+ end
308
+
309
+ task :rdoc_manpages do
310
+ STDOUT.flush
311
+ FileUtils.rm_r('doc') if File.exist?('doc')
312
+ `rdoc -f hanna manpages/readme.rdoc manpages/*.rb -m manpages/readme.rdoc -o doc -t "manpages for docgenerator"`
313
+ end
314
+
315
+
316
+ #~ task 'manpages/environments.rb' => :force
317
+ #~ task :default => 'manpages/environments.rb'
318
+ #~ task 'manpages/sectioning.rb' => :force
319
+ #~ task :default => 'manpages/sectioning.rb'
320
+ #~ task 'manpages/elements.rb' => :force
321
+ #~ task :default => 'manpages/elements.rb'
322
+ #~ task 'manpages/characters.rb' => :force
323
+ #~ task :default => 'manpages/characters.rb'
324
+
325
+ #~ task :default => :test
326
+ task :default => :clean
327
+ task :default => :all_man_files
328
+ #~ task :default => :rdoc_manpages
329
+
330
+ if $0 == __FILE__
331
+ app = Rake.application
332
+ app[:default].invoke
333
+ end
@@ -0,0 +1,251 @@
1
+ #encoding: utf-8
2
+ =begin
3
+ Generates new versions for test.
4
+
5
+ Generates:
6
+ * loop over all elements
7
+ * create an element
8
+ * make a test output and create unit tests for the elemnt.
9
+
10
+ The resultof this process is not a test for correctness,
11
+ but a test of "state of the art".
12
+
13
+ Effects of changes may be checked wih the result of this test.
14
+
15
+ Approved tests may be transferred as real unit tests.
16
+ =end
17
+
18
+ #~ Dir['lib/**/wiki*/*'].each{|file| puts "require '#{file}'".sub(/lib\//,'') }
19
+ #~ exit
20
+ require_relative 'build__meta'
21
+ $log = Log4r::Logger.new('testgenerator')
22
+ $log.outputters << Log4r::StdoutOutputter.new('stdout')
23
+
24
+ #Header for testfiles
25
+ TESTHEAD = <<testhead
26
+ #encoding: utf-8
27
+
28
+ =begin rdoc
29
+ Test generated by #{__FILE__} #{Date.today}
30
+
31
+ This is not a 'real' test unit.
32
+ The tests are created with #{__FILE__}:
33
+ 1) Each Element is taken and field.
34
+ =end
35
+
36
+ gem 'test-unit'
37
+ require 'test/unit'
38
+
39
+ if $0 == __FILE__
40
+ #Add lib, two insertions, depending on target directory level
41
+ $:.unshift("../lib")
42
+ $:.unshift("../../lib")
43
+ end
44
+ require 'docgenerator'
45
+ #~ DOCGENERATOR_LOGGER.level = Log4r::DEBUG
46
+
47
+ =begin rdoc
48
+ Define a new outputter to catch data into an array
49
+ =end
50
+ class ArrayOutputter < Log4r::StdoutOutputter
51
+ =begin rdoc
52
+ Collect messages in array.
53
+ =end
54
+ def write(message)
55
+ @messages ||= [] #create with first call
56
+ @messages << message
57
+ end
58
+ =begin rdoc
59
+ Clear message array and return messages
60
+ =end
61
+ def flush
62
+ @messages ||= [] #create with first call
63
+ messages = @messages.dup
64
+ @messages.clear
65
+ messages
66
+ end
67
+ end #ArrayOutputter
68
+
69
+ testhead
70
+
71
+ =begin rdoc
72
+ Create a unit-test file.
73
+ =end
74
+ def mk_element_test(elementlist, filename, requirements )
75
+
76
+ testcode= []
77
+ elementlist.each{|cl|
78
+ $log.info("Create test for #{cl.name}")
79
+ testcode << mk_element_testcase(cl)
80
+ }
81
+
82
+ File.open(filename, 'w:utf-8'){|f_test|
83
+ puts "Create #{f_test.path}"
84
+ f_test << TESTHEAD
85
+ f_test << "require '#{requirements}'\n" if requirements
86
+ f_test << testcode.join("\n")
87
+ }
88
+ #~ puts testcode.join("\n")
89
+
90
+ end #mk_element_test
91
+
92
+ =begin rdoc
93
+ =end
94
+ def mk_element_testcase(cl)
95
+ testclass = "Test_element_#{cl.name.downcase.gsub(/::/, '_')}"
96
+ testcode = []
97
+ case cl.name
98
+ when /::Characters::/
99
+ loglevel = Log4r::INFO
100
+ else
101
+ loglevel = Log4r::DEBUG
102
+ end
103
+
104
+ @@log = Log4r::Logger.new(cl.element_ids.first.to_s, loglevel)
105
+ @@log.outputters = @@logoutputter = ArrayOutputter.new('xx')
106
+ @@el = cl.new(:log => @@log )
107
+
108
+ testcode << <<code
109
+ =begin rdoc
110
+ Test #{cl.name}.
111
+ =end
112
+ class #{testclass} < Test::Unit::TestCase
113
+ def self.startup()
114
+ @@log = Log4r::Logger.new('#{cl.element_ids.first.to_s}', Log4r::#{Log4r::LNAMES[loglevel]})
115
+ @@log.outputters = @@logoutputter = ArrayOutputter.new('xx')
116
+ @@el = #{cl.name}.new(:log => @@log)
117
+ code
118
+ @@el.attr.sort_by{|k,a| a.sortkey}.each{|k,a|
119
+ #this may give an error, if the attribute has wrong type/layout...
120
+ @@el[k] << "Attr_#{k}" if a.required?
121
+ testcode << "%s @@el[%-10s] << %-20s #%s attribute" % [
122
+ a.required? ? ' ' : '#~',#only as template for optional values
123
+ k.inspect,
124
+ "'Attr_#{k}'", #Part of content
125
+ a.required? ? 'required' : 'optional',
126
+ ]
127
+ }
128
+
129
+ if @@el.content?
130
+ @@el << 'content'
131
+ testcode<< " #fill content"
132
+ testcode<< " @@el << 'content'"
133
+ else
134
+ testcode<< " #element allows no content"
135
+ end
136
+
137
+ testcode<< " #Store log messages"
138
+ testcode<< " @@messages = @@logoutputter.flush"
139
+ #test log-content
140
+ @@messages = @@log.outputters.first.flush
141
+ testname = "test_element_#{cl.name.downcase.gsub(/::/, '_')}_log"
142
+
143
+ testcode<< <<code
144
+ end #self.startup()
145
+ =begin rdoc
146
+ Check messages from logger.
147
+ This may include warnings for wrong content format...
148
+
149
+ The following messages are expected:
150
+ #{@@messages.to_yaml}
151
+ =end
152
+ def #{testname}
153
+ assert_equal(
154
+ #{@@messages.inspect},
155
+ @@messages
156
+ )
157
+ end ##{testname}
158
+ code
159
+ %w{latex html context text wiki creole}.each{|target|
160
+ testname = "test_element_#{cl.name.downcase.gsub(/::/, '_')}_#{target}"
161
+ result = @@el.send("to_#{target}".to_sym, :log => @@log)
162
+
163
+ #~ The target #{target} is #{@@el.send("#{target}?".to_sym) ? '' : 'not' } supported for #{cl.name}
164
+ testcode<< <<code
165
+ =begin
166
+ Test #{cl.name}#to_#{target}.
167
+ =end
168
+ def #{testname}()
169
+ assert_equal(
170
+ code
171
+ testcode.last.sub!(/\n$/,'') #remove newline of last entry
172
+ #Problem:
173
+ if result.count("\n") < 2 #one-line result in short version
174
+ #\u (\url...) wird als Unicode-eingabe interpretiert. Desahlb muss \ maskiert werden.
175
+ testcode<< " #{result.inspect.gsub(/\\/, '\\\\')},"
176
+ else #mehrzeilig
177
+ =begin
178
+ Problem: %{inhalt} macht Probleme bei Strings mit { und }
179
+ <<<xx fügt leerzeichen ein, komma für nächste Parameter geht auch nicht.
180
+ =end
181
+ testcode<< " %Q{#{result.gsub(/\\/, '\\\\\\\\')}}," #mehrzeilig
182
+ #~ testcode<< "#~ <<result"
183
+ #~ testcode<< @@el.send("to_#{target}".to_sym).gsub(/\\/, '\\\\\\\\').gsub(/^/, '#~ ')
184
+ #~ testcode<< "#~ result"
185
+ end
186
+ testcode<< " @@el.to_#{target}( :log => @@log).encode('utf-8')"
187
+ testcode<< " )"
188
+
189
+ messages = @@logoutputter.flush
190
+ if messages.empty?
191
+ testcode<< " assert_equal([],@@logoutputter.flush, 'No messages expected')"
192
+ else
193
+ testcode<< <<code
194
+ #Check messages from #{cl.name}#to_#{target}.
195
+ assert_equal([
196
+ #{messages.map{|m| m.inspect}.join(",\n ")}
197
+ ], @@logoutputter.flush
198
+ )
199
+ code
200
+ end
201
+ testcode<< " end ##{testname}"
202
+ }
203
+ testcode<< "end ##{testclass}"
204
+ testcode
205
+ end # mk_element_testcase(cl)
206
+
207
+
208
+ desc "Create all test files"
209
+ task :all_test_files
210
+
211
+ #Create file tasks
212
+ FILE_SEPARATION.each{|key, elementlist|
213
+ filename = File.join('unittest', "unittest_#{key}")
214
+ file filename do |tsk| mk_element_test(elementlist, tsk.name, FILE_SEPARATION_REQUIREMENTS[key] ); end #Create file task
215
+ task :all_test_files => filename #add file task as prerequisite to :all_test_files
216
+ }
217
+
218
+ task :force
219
+ task :clean do
220
+ Rake.application[:all_test_files].prerequisites.each{|f|
221
+ File.delete(f) if File.exist?(f)
222
+ }
223
+ end
224
+
225
+ require 'knut_tools/rake/testtask.rb'
226
+ Rake::TestTask.new(:run_tests) do |t|
227
+ t.dir = 'unittest'
228
+ t.libs << '../lib'
229
+ t.libs << '../../lib'
230
+ t.test_files = FileList['unittest*.rb']
231
+ t.verbose = true
232
+ end
233
+
234
+ task :default => :clean
235
+ task :default => :all_test_files
236
+ #~ task :default => :run_tests
237
+
238
+ if $0 == __FILE__
239
+ app = Rake.application
240
+ app[:default].invoke
241
+ end
242
+
243
+ #~ puts_elements
244
+
245
+ __END__
246
+ fixme:
247
+ - tests mit #cr...
248
+ - optionale attribute
249
+ - testdaten in DB? (verschiedene Attributesausprägungen?)
250
+
251
+