tartan 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/History.txt +11 -0
  2. data/Manifest.txt +42 -0
  3. data/{README → README.txt} +12 -8
  4. data/Rakefile +78 -0
  5. data/lib/core_ext/array.rb +9 -10
  6. data/lib/core_ext/module.rb +2 -0
  7. data/lib/{symbolize.rb → core_ext/symbolize.rb} +0 -0
  8. data/lib/core_ext.rb +7 -0
  9. data/lib/{markdown.yml → tartan/markdown/markdown.yml} +67 -25
  10. data/lib/tartan/markdown/rules.rb +11 -0
  11. data/lib/tartan/markdown.rb +14 -0
  12. data/lib/tartan/table/rules.rb +11 -0
  13. data/lib/{table.yml → tartan/table/table.yml} +1 -1
  14. data/lib/tartan/test/base_rules.rb +9 -0
  15. data/lib/{test_base.yml → tartan/test/test_base.yml} +0 -0
  16. data/lib/{wiki-test.rb → tartan/test/wiki-test.rb} +15 -12
  17. data/lib/tartan/wiki_rule.rb +242 -0
  18. data/lib/tartan/wikilink/rules.rb +18 -0
  19. data/lib/{wikilink.yml → tartan/wikilink/wikilink.yml} +4 -2
  20. data/lib/tartan.rb +259 -270
  21. data/test/test-combo.rb +21 -14
  22. data/test/test-combo.yml +17 -0
  23. data/test/test-markdown-and-wikilink.rb +22 -0
  24. data/test/test-markdown-and-wikilink.yml +6 -0
  25. data/test/test-markdown.rb +4 -5
  26. data/test/test-markdown.yml +194 -1
  27. data/test/test-readme-example.rb +6 -5
  28. data/test/test-tables.rb +11 -7
  29. data/test/test-tartan.rb +8 -7
  30. data/test/test-wikilink.rb +13 -9
  31. data/test/test-wikilink.yml +3 -0
  32. metadata +47 -86
  33. data/lib/tartan_markdown.rb +0 -8
  34. data/lib/tartan_markdown_def.rb +0 -7
  35. data/lib/tartan_table_def.rb +0 -7
  36. data/lib/tartan_test_base_def.rb +0 -5
  37. data/lib/tartan_wikilink_def.rb +0 -14
  38. data/lib/wiki_rule.rb +0 -240
  39. data/test/MarkdownTest_1.0/Amps and angle encoding.html +0 -17
  40. data/test/MarkdownTest_1.0/Amps and angle encoding.text +0 -21
  41. data/test/MarkdownTest_1.0/Auto links.html +0 -18
  42. data/test/MarkdownTest_1.0/Auto links.text +0 -13
  43. data/test/MarkdownTest_1.0/Backslash codeescapes.html +0 -68
  44. data/test/MarkdownTest_1.0/Backslash codeescapes.text +0 -68
  45. data/test/MarkdownTest_1.0/Backslash simpleescapes.html +0 -33
  46. data/test/MarkdownTest_1.0/Backslash simpleescapes.text +0 -33
  47. data/test/MarkdownTest_1.0/Blockquotes with code blocks.html +0 -15
  48. data/test/MarkdownTest_1.0/Blockquotes with code blocks.text +0 -11
  49. data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.html +0 -8
  50. data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.text +0 -8
  51. data/test/MarkdownTest_1.0/Horizontal rules.html +0 -71
  52. data/test/MarkdownTest_1.0/Horizontal rules.text +0 -67
  53. data/test/MarkdownTest_1.0/Inline HTML (Advanced).html +0 -14
  54. data/test/MarkdownTest_1.0/Inline HTML (Advanced).text +0 -14
  55. data/test/MarkdownTest_1.0/Inline HTML (Simple).html +0 -72
  56. data/test/MarkdownTest_1.0/Inline HTML (Simple).text +0 -69
  57. data/test/MarkdownTest_1.0/Inline HTML comments.html +0 -13
  58. data/test/MarkdownTest_1.0/Inline HTML comments.text +0 -13
  59. data/test/MarkdownTest_1.0/Links, inline style.html +0 -9
  60. data/test/MarkdownTest_1.0/Links, inline style.text +0 -9
  61. data/test/MarkdownTest_1.0/Links, reference style.html +0 -18
  62. data/test/MarkdownTest_1.0/Links, reference style.text +0 -31
  63. data/test/MarkdownTest_1.0/Literal quotes in titles.html +0 -3
  64. data/test/MarkdownTest_1.0/Literal quotes in titles.text +0 -7
  65. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.html +0 -314
  66. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.out +0 -316
  67. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.text +0 -306
  68. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.html +0 -942
  69. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.out +0 -947
  70. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.text +0 -888
  71. data/test/MarkdownTest_1.0/Nested blockquotes.html +0 -9
  72. data/test/MarkdownTest_1.0/Nested blockquotes.text +0 -5
  73. data/test/MarkdownTest_1.0/Ordered and unordered lists.html +0 -137
  74. data/test/MarkdownTest_1.0/Ordered and unordered lists.text +0 -122
  75. data/test/MarkdownTest_1.0/Strong and em together.html +0 -7
  76. data/test/MarkdownTest_1.0/Strong and em together.text +0 -7
  77. data/test/MarkdownTest_1.0/Tabs.html +0 -25
  78. data/test/MarkdownTest_1.0/Tabs.text +0 -21
  79. data/test/MarkdownTest_1.0/Tidyness.html +0 -8
  80. data/test/MarkdownTest_1.0/Tidyness.text +0 -5
  81. data/test/MarkdownTest_1.0/run-markdown.rb +0 -56
  82. data/test/MarkdownTest_1.0/test-fireball-markdown.rb +0 -177
  83. data/test/MarkdownTest_1.0/testdiff.rb +0 -42
  84. data/test/harder/test-markdown-harder.rb +0 -11
  85. data/test/harder/test-markdown-harder.yml +0 -111
  86. data/test/redcloth/redcloth-markdown-tests.rb +0 -29
  87. data/test/redcloth/redcloth-markdown-tests.yml +0 -218
  88. data/test/test-tartan-markdown.rb +0 -11
data/History.txt ADDED
@@ -0,0 +1,11 @@
1
+ = 0.1.2 2007-01-22 (r181)
2
+ * Refactored for "Tartan::" name space
3
+ * Strip out html scripts in the span context.
4
+ * Added select and option to the sets of span and block html tags.
5
+ * Fixed problem with multiple embedded bullet-lists.
6
+ -
7
+ = 0.1.1 2006-08-21 (r177)
8
+ * First gem
9
+ * Initial version of parsing engine
10
+ * Initial Markdown rules
11
+
data/Manifest.txt ADDED
@@ -0,0 +1,42 @@
1
+ History.txt
2
+ MIT-LICENSE
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ TODO
7
+ lib/core_ext.rb
8
+ lib/core_ext/array.rb
9
+ lib/core_ext/file.rb
10
+ lib/core_ext/hash.rb
11
+ lib/core_ext/match_data.rb
12
+ lib/core_ext/module.rb
13
+ lib/core_ext/regexp.rb
14
+ lib/core_ext/symbolize.rb
15
+ lib/tartan.rb
16
+ lib/tartan/markdown.rb
17
+ lib/tartan/markdown/markdown.yml
18
+ lib/tartan/markdown/rules.rb
19
+ lib/tartan/table/rules.rb
20
+ lib/tartan/table/table.yml
21
+ lib/tartan/test/base_rules.rb
22
+ lib/tartan/test/test_base.yml
23
+ lib/tartan/test/wiki-test.rb
24
+ lib/tartan/wiki_rule.rb
25
+ lib/tartan/wikilink/rules.rb
26
+ lib/tartan/wikilink/wikilink.yml
27
+ test/test-combo.rb
28
+ test/test-combo.yml
29
+ test/test-hash.rb
30
+ test/test-markdown-and-wikilink.rb
31
+ test/test-markdown-and-wikilink.yml
32
+ test/test-markdown.rb
33
+ test/test-markdown.yml
34
+ test/test-match-data.rb
35
+ test/test-readme-example.rb
36
+ test/test-regexp.rb
37
+ test/test-tables.rb
38
+ test/test-tables.yml
39
+ test/test-tartan.rb
40
+ test/test-wikilink.rb
41
+ test/test-wikilink.yml
42
+ test/wikilink-test-helper.rb
@@ -30,7 +30,7 @@ how you do it:
30
30
  # require 'rubygems' # if you are pulling Tartan in as a gem
31
31
  require 'tartan_markdown'
32
32
 
33
- html = TartanMarkdown.new("* howdy\n* doody").to_html
33
+ html = Tartan::Markdown::Parser.new("* howdy\n* doody").to_html
34
34
  # => "<ul>\n<li>howdy</li>\n<li>doody</li>\n</ul>"
35
35
 
36
36
  Other parsers would have similar names and would have the same usage. In
@@ -49,19 +49,23 @@ have a specification for table mark-up. You can combine them by creating a new
49
49
  class that layers the tables onto the Markdown[http://daringfireball.net/projects/markdown/] definition as follows in a file
50
50
  called <tt>tartan_markdown_tables.rb</tt>:
51
51
 
52
- require 'tartan_markdown_def'
53
- require 'tartan_table_def'
52
+ require 'tartan/markdown/rules'
53
+ require 'tartan/table/rules'
54
54
 
55
- class TartanMarkdownTables < Tartan
56
- include TartanMarkdownDef
57
- include TartanTableDef
55
+ modules Tartan
56
+ modules MarkdownTables
57
+ class Parser < Tartan::Parser
58
+ include TartanMarkdownDef
59
+ include TartanTableDef
60
+ end
61
+ end
58
62
  end
59
63
 
60
64
  In another file you could use this new parser:
61
65
 
62
66
  require 'tartan_markdown_tables'
63
67
 
64
- html = TartanMarkdownTables.new("[|*happy*||**days**|]").to_html
68
+ html = Tartan::MarkdownTables::Parser.new("[|*happy*||**days**|]").to_html
65
69
  # => "<table class=\"\">
66
70
  <tr><td><em>happy</em></td><td><strong>days</strong></td></tr>
67
71
  </table>"
@@ -204,7 +208,7 @@ So, to add this syntax parsing, you would create the following specification:
204
208
 
205
209
  That's it for the mix-in specification. Now we add these to the previous set. We didn't touch on file naming of specifications before, but now we need to. Let's say that we put the previous specification in a file called <tt>example-parser.yml</tt> and we put the new spec in <tt>entities.yml</tt>. To combine them, we would create a new Ruby class like this:
206
210
 
207
- class ExampleParserWithEntities < Tartan
211
+ class ExampleParserWithEntities < Tartan::Parser
208
212
  yaml "example-parser.yml"
209
213
  yaml "entities.yml"
210
214
  end
data/Rakefile ADDED
@@ -0,0 +1,78 @@
1
+ # $Id$
2
+
3
+ $:.push("lib", "test")
4
+
5
+ require 'rubygems'
6
+ require 'rake'
7
+ require 'rake/clean'
8
+ require 'rake/testtask'
9
+ require 'rake/gempackagetask'
10
+ require 'rake/rdoctask'
11
+ require 'hoe'
12
+
13
+ def version
14
+ if ENV['GEM_VERSION']: return ENV['GEM_VERSION']
15
+ elsif ENV['PWD'] =~ %r|tags/((?:[[:alnum:]]+\.)+[[:alnum:]]+)|: return $1
16
+ end
17
+
18
+ return nil
19
+ end
20
+
21
+ def name
22
+ "tartan"
23
+ end
24
+ namespace :build do
25
+ namespace :check do
26
+ task :manifest do
27
+ man_files = File.read('')
28
+ end
29
+ end
30
+
31
+ Hoe.new(name, version||"0.0.0") do |p|
32
+ p.summary = 'A library for building text parsers'
33
+ p.description = <<-TEXT_END
34
+ A text parsing engine. The syntax is defined outside the engine as regex-based
35
+ rules, in YAML or Ruby. It supports layering and multiple output types. Rules
36
+ for Markdown to HTML are included, with optional layered extensions for tables
37
+ and wikilinks.
38
+ TEXT_END
39
+ p.email = 'tartan@folklogic.com'
40
+ p.url = 'http://tartan.rubyforge.com/'
41
+ p.author = "Larry Baltz and David B. Anderson"
42
+ # p.files += extra_files
43
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
44
+ p.test_globs = 'test/test-*.rb'
45
+ end
46
+ end
47
+
48
+ def extra_files
49
+ %w(README TODO MIT-LICENSE)
50
+ end
51
+
52
+ def rdoc_extra
53
+ ['README']
54
+ end
55
+
56
+ def test_files
57
+ FileList['test/test*.rb']
58
+ end
59
+
60
+ namespace :test do
61
+ test_files.each do |file|
62
+ test_name = file.match(/^test\/test[-_]?(.*?)\.rb/)[1]
63
+ desc "Run #{test_name} tests"
64
+ task (test_name.to_sym) {ruby "-w -I test #{file}"}
65
+ end
66
+ end
67
+
68
+ task :default => [:test]
69
+
70
+ task :version_check do
71
+ if version.nil?
72
+ raise "can't figure out build version"
73
+ end
74
+ end
75
+
76
+ task :version do
77
+ p version
78
+ end
@@ -1,12 +1,11 @@
1
1
  class Array
2
- alias :old_index :index
3
- def index(*args, &block)
4
- if not args.empty?
5
- old_index(*args)
6
- else
7
- result = find_all(&block).map { |item| old_index(item) }
8
- return nil if result.empty?
9
- return result[0]
10
- end
2
+ alias :old_index :index
3
+ def index(*args, &block)
4
+ if block_given?
5
+ each_with_index { |v,i| return i if yield(v) }
6
+ return nil
7
+ else
8
+ old_index(*args)
11
9
  end
12
- end
10
+ end
11
+ end
@@ -4,6 +4,8 @@ class Module
4
4
  @arg_sets[method_name] = [args, block]
5
5
  end
6
6
 
7
+ alias :tartan_included :included
8
+
7
9
  def included(klass)
8
10
  return unless defined? @arg_sets
9
11
  @arg_sets.each do |method, (args, block)|
File without changes
data/lib/core_ext.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'core_ext/array'
2
+ require 'core_ext/file'
3
+ require 'core_ext/hash'
4
+ require 'core_ext/match_data'
5
+ require 'core_ext/module'
6
+ require 'core_ext/regexp'
7
+ require 'core_ext/symbolize'
@@ -6,6 +6,13 @@
6
6
  # handle return (\r) characters properly (especially in \r\n combo)
7
7
 
8
8
  span:
9
+ - title: html_script
10
+ shelve: true
11
+ match: /<script.*?\/script>/m
12
+ html:
13
+ start_mark: ''
14
+ end_mark: ''
15
+
9
16
  - title: backtick_2
10
17
  shelve: true
11
18
  match: /`` ?(.+?) ?``/
@@ -26,6 +33,8 @@ span:
26
33
  start_mark: '<code>'
27
34
  end_mark: '</code>'
28
35
 
36
+ - title: code_done
37
+
29
38
  - title: ref_image
30
39
  shelve: true
31
40
  match: /!\[(.*?)\][ ]?\[(.*?)\]/
@@ -50,7 +59,7 @@ span:
50
59
  / <\/?
51
60
  (?:span|cite|del|em|strong|dfn|code|samp|kbd|var|abbr
52
61
  |acronym|b|i|font|a|img|object|tt|big|small|strike|s|u
53
- |sup|sub|q)
62
+ |sup|sub|q|select|option)
54
63
  (:?\s+[^\s>][^>]*?)?
55
64
  >/x
56
65
  html:
@@ -64,6 +73,30 @@ span:
64
73
  start_mark: ''
65
74
  end_mark: ''
66
75
 
76
+ - title: inline_image_with_title
77
+ shelve: true
78
+ match: /!\[(.+?)\]\((.+??)\s+"(.+?)"\)/
79
+ html:
80
+ replace: '<img src="\2" alt="\1" title="\3" />'
81
+
82
+ - title: inline_image
83
+ shelve: true
84
+ match: /!\[(.+?)\]\((.*?)\)/
85
+ html:
86
+ replace: '<img src="\2" alt="\1" />'
87
+
88
+ - title: link_with_title
89
+ shelve: true
90
+ match: /\[(.+?)\]\(<?(.+??)>?\s+"(.+?)"\)/
91
+ html:
92
+ replace: '<a href="\2" title="\3">\1</a>'
93
+
94
+ - title: link
95
+ shelve: true
96
+ match: /\[(.+?)\]\(<?(.*?)>?\)/
97
+ html:
98
+ replace: '<a href="\2">\1</a>'
99
+
67
100
  - title: amp
68
101
  match: /&/
69
102
  html:
@@ -116,7 +149,7 @@ span:
116
149
 
117
150
  - title: link_with_title
118
151
  shelve: true
119
- match: /\[(.+?)\]\((.+??)\s+"(.+?)"\)/
152
+ match: /\[(.+?)\]\(<?(.+??)>?\s+"(.+?)"\)/
120
153
  html:
121
154
  replace: '<a href="\2" title="\3">\1</a>'
122
155
  - rescan
@@ -279,7 +312,7 @@ block:
279
312
 
280
313
  - title: bulletListSpaced
281
314
  match: >
282
- / (?>\A(\s*)|\n(\n))
315
+ / (?>\A(\s*)|(\n)[ \t]*(\n))
283
316
  (
284
317
  [-*+](?>[ ]+|\t)[^\n]*
285
318
  (?>\n(?>[ ]{4}|\t)?[^\n]+)*
@@ -301,20 +334,20 @@ block:
301
334
  )/xm
302
335
  subparse:
303
336
  context: listSpaced
304
- match_group: 3
337
+ match_group: 4
305
338
  html:
306
- start_mark: "\\1\\2<ul>\n"
339
+ start_mark: "\\1\\2\\3<ul>\n"
307
340
  end_mark: "\n</ul>"
308
341
 
309
342
  - title: bulletListClose
310
343
  match: >
311
- / (?:\A(\s*)|(\n\n))
312
- ([-*+](?:[ ]+|\t)[^\n]+(:?\n[ \t]*[^\s][^\n]*)*)/xm
344
+ / (?:\A(\s*)|(\n)[ \t]*(\n))
345
+ ([-*+][ \t]+[^\n]+(:?\n[ \t]*\S[^\n]*)*)/xm
313
346
  subparse:
314
347
  context: listClose
315
- match_group: 3
348
+ match_group: 4
316
349
  html:
317
- start_mark: "\\1\\2<ul>\n"
350
+ start_mark: "\\1\\2\\3<ul>\n"
318
351
  end_mark: "\n</ul>"
319
352
 
320
353
  - title: numberedListSpaced
@@ -365,10 +398,16 @@ block:
365
398
  start_mark: "\\1\\2<ol>\n"
366
399
  end_mark: "\n</ol>"
367
400
 
401
+ - title: html_self_closing
402
+ shelve: true
403
+ match: >
404
+ / ^[ ]{0,3}<input.*?>/x
405
+ html: true
406
+
368
407
  - title: html_block
369
408
  shelve: true
370
409
  match: >
371
- / ^[ ]{0,3}<(script|table|div|pre|center|blockquote|p|ul|ol|h[1-6])(?:[^>]*)?>
410
+ / ^[ ]{0,3}<(select|script|table|div|pre|center|blockquote|p|ul|ol|h[1-6])(?:[^>]*)?>
372
411
  .*?
373
412
  <\/\1>/xm
374
413
  html: true
@@ -391,8 +430,10 @@ block:
391
430
  end_mark: "\n</code></pre>"
392
431
 
393
432
  - title: paragraph
394
- match: '/((?:^\S.*?$)(?:\n\S[^\n]*)*)/m'
395
- subparse: span
433
+ match: '/^[ ]{0,3}((:?\S.*?$)(?:\n[ ]*\S[^\n]*)*)/m'
434
+ subparse:
435
+ context: span
436
+ match_group: 1
396
437
  html:
397
438
  start_mark: '<p>'
398
439
  end_mark: '</p>'
@@ -437,8 +478,8 @@ embeddedBlock:
437
478
 
438
479
  - title: embeddedPara
439
480
  position: first
440
- match:
441
- /\A (?:(?![*+-]|[[:digit:]]))
481
+ match: >
482
+ /\A (?:(?!(?:[*+-]|[[:digit:]]\.)(:?[ ]+|\t)))
442
483
  (?:(?:\S[^\n]*)(?:\n\S[^\n]*)*)
443
484
  \n?\z/xm
444
485
  subparse: span
@@ -462,7 +503,11 @@ listSpaced:
462
503
  (?:\n[^-*+[:digit:]\n][^\n]*)*
463
504
  )*/xm
464
505
  strip:
465
- match: '/^(([-*+]|[[:digit:]]\.)\s*|(?: |\t))/'
506
+ match: >
507
+ /^(?:
508
+ (?:[-*+]|[[:digit:]]\.)\s*
509
+ |(?:[ ]{1,4}|\t)
510
+ )/x
466
511
  replace: ''
467
512
  subparse: block
468
513
  html:
@@ -477,18 +522,15 @@ listSpaced:
477
522
  listClose:
478
523
  - title: closeListItem
479
524
  match: >
480
- /^(
481
- (?:
482
- (?:[-*+]|[[:digit:]+]\.)
483
- (?:[ ]+|\t).*?$
484
- )
485
- (?:\n(?![-*+\n]|[[:digit:]]+\.)[^\n]*)*
486
- )/xm
525
+ /^(?:[-*+]|[[:digit:]+]\.)[ \t]+(.*?$
526
+ (?:\n(?![-*+\n]|[[:digit:]]+\.)[^\n]*)*)
527
+ /xm
487
528
  strip:
488
529
  match: >
489
- /^( (?:[-*+]|[[:digit:]]+\.)\s*
490
- |(?:[ ]+|\t)
491
- )/x
530
+ /^(?:(?:[-*+]|[[:digit:]]+\.)\s*
531
+ |(?:[ ]{1,4}|\t)
532
+ )
533
+ /x
492
534
  replace: ''
493
535
  subparse: embeddedBlock
494
536
  html:
@@ -0,0 +1,11 @@
1
+ #$Id: rules.rb 182 2007-01-28 21:32:51Z bitherder $
2
+
3
+ require 'core_ext'
4
+
5
+ module Tartan
6
+ module Markdown
7
+ module Rules
8
+ yaml 'tartan/markdown/markdown.yml'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ #$Id: markdown.rb 186 2007-02-12 16:36:17Z bitherder $
2
+
3
+ baseDir = File.dirname(__FILE__)
4
+
5
+ require 'tartan'
6
+ require 'tartan/markdown/rules'
7
+
8
+ module Tartan
9
+ module Markdown
10
+ class Parser < Parser
11
+ include Rules
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'core_ext'
2
+
3
+ # This module should be included into a Tartan subclass to add table mark-up.
4
+
5
+ module Tartan
6
+ module Table
7
+ module Rules
8
+ yaml "tartan/table/table.yml"
9
+ end
10
+ end
11
+ end
@@ -5,7 +5,7 @@ block:
5
5
  end_mark: </table>
6
6
  after: html_comment
7
7
  match: |-
8
- / (?:\[([\w]*)[|!](?:.*?)\|\])
8
+ /^[ ]{0,3} (?:\[([\w]*)[|!](?:.*?)\|\])
9
9
  (?:\s*)
10
10
  (?:(?:\[[|!](?:.*?)\|\])(?:\s*))*/mx
11
11
  subparse: table
@@ -0,0 +1,9 @@
1
+ require 'core_ext'
2
+
3
+ module Tartan
4
+ module Test
5
+ module BaseRules
6
+ yaml "tartan/test/test_base.yml"
7
+ end
8
+ end
9
+ end
File without changes
@@ -1,13 +1,16 @@
1
- #$Id: wiki-test.rb 159 2006-07-24 08:13:02Z larry $
1
+ #$Id: wiki-test.rb 193 2007-04-18 15:27:15Z alpinegizmo $
2
2
 
3
3
  require 'test/unit'
4
4
  require 'yaml'
5
5
  require 'benchmark'
6
- require 'breakpoint'
7
6
  require 'core_ext/file'
8
7
 
9
8
  class WikiTestCases
10
- def initialize(parserKlass, testfiles, targets=[:html, :db])
9
+ def self.get_input(doc, type)
10
+ doc['in'].gsub(/\{\{\{(.*?)\}\}\}/) {|sub| subs[$1]}
11
+ end
12
+
13
+ def initialize(parserKlass, testfiles, targets=[:html])
11
14
 
12
15
  # if either the testfile or target argument is a single value, turn
13
16
  # it into a single element array
@@ -21,12 +24,17 @@ class WikiTestCases
21
24
  parserKlass
22
25
  end
23
26
 
24
- def assert_wiki(expected, wiki_text, options, type=:html)
27
+ def test_parser(doc, options, type, type_name)
28
+ input = WikiTestCases.get_input(doc, type)
29
+
30
+ expected \
31
+ = doc[type_name].gsub(/\{\{\{(.*?)\}\}\}/) {|sub| subs[$1]}
32
+
25
33
  # time limit in seconds
26
34
  time_limit = options['time_limit'] ? options['time_limit'] : 1.0
27
35
 
28
- parser = parserClass.new(wiki_text, options)
29
-
36
+ parser = parserClass.new(input, options)
37
+
30
38
  out = nil
31
39
  wtimes = Benchmark.measure do
32
40
  out = parser.to_type(type)
@@ -70,8 +78,6 @@ class WikiTestCases
70
78
 
71
79
  next unless doc['in']
72
80
 
73
- input = doc['in'].gsub(/\{\{\{(.*?)\}\}\}/) {|sub| subs[$1]}
74
-
75
81
  title = doc['title'] ? doc['title'] : (sequence += 1).to_s
76
82
 
77
83
  targets.each do |target|
@@ -80,11 +86,8 @@ class WikiTestCases
80
86
 
81
87
  next unless doc[target_name]
82
88
 
83
- expected \
84
- = doc[target_name].gsub(/\{\{\{(.*?)\}\}\}/) {|sub| subs[$1]}
85
-
86
89
  define_method "test_#{target_name}_" + title do
87
- assert_wiki expected, input, options.dup, target
90
+ test_parser doc, options.dup, target, target_name
88
91
  end # define_method
89
92
  end # targests.each
90
93
  end # YAML::load_documents