tartan 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +42 -0
- data/{README → README.txt} +12 -8
- data/Rakefile +78 -0
- data/lib/core_ext/array.rb +9 -10
- data/lib/core_ext/module.rb +2 -0
- data/lib/{symbolize.rb → core_ext/symbolize.rb} +0 -0
- data/lib/core_ext.rb +7 -0
- data/lib/{markdown.yml → tartan/markdown/markdown.yml} +67 -25
- data/lib/tartan/markdown/rules.rb +11 -0
- data/lib/tartan/markdown.rb +14 -0
- data/lib/tartan/table/rules.rb +11 -0
- data/lib/{table.yml → tartan/table/table.yml} +1 -1
- data/lib/tartan/test/base_rules.rb +9 -0
- data/lib/{test_base.yml → tartan/test/test_base.yml} +0 -0
- data/lib/{wiki-test.rb → tartan/test/wiki-test.rb} +15 -12
- data/lib/tartan/wiki_rule.rb +242 -0
- data/lib/tartan/wikilink/rules.rb +18 -0
- data/lib/{wikilink.yml → tartan/wikilink/wikilink.yml} +4 -2
- data/lib/tartan.rb +259 -270
- data/test/test-combo.rb +21 -14
- data/test/test-combo.yml +17 -0
- data/test/test-markdown-and-wikilink.rb +22 -0
- data/test/test-markdown-and-wikilink.yml +6 -0
- data/test/test-markdown.rb +4 -5
- data/test/test-markdown.yml +194 -1
- data/test/test-readme-example.rb +6 -5
- data/test/test-tables.rb +11 -7
- data/test/test-tartan.rb +8 -7
- data/test/test-wikilink.rb +13 -9
- data/test/test-wikilink.yml +3 -0
- metadata +47 -86
- data/lib/tartan_markdown.rb +0 -8
- data/lib/tartan_markdown_def.rb +0 -7
- data/lib/tartan_table_def.rb +0 -7
- data/lib/tartan_test_base_def.rb +0 -5
- data/lib/tartan_wikilink_def.rb +0 -14
- data/lib/wiki_rule.rb +0 -240
- data/test/MarkdownTest_1.0/Amps and angle encoding.html +0 -17
- data/test/MarkdownTest_1.0/Amps and angle encoding.text +0 -21
- data/test/MarkdownTest_1.0/Auto links.html +0 -18
- data/test/MarkdownTest_1.0/Auto links.text +0 -13
- data/test/MarkdownTest_1.0/Backslash codeescapes.html +0 -68
- data/test/MarkdownTest_1.0/Backslash codeescapes.text +0 -68
- data/test/MarkdownTest_1.0/Backslash simpleescapes.html +0 -33
- data/test/MarkdownTest_1.0/Backslash simpleescapes.text +0 -33
- data/test/MarkdownTest_1.0/Blockquotes with code blocks.html +0 -15
- data/test/MarkdownTest_1.0/Blockquotes with code blocks.text +0 -11
- data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.html +0 -8
- data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.text +0 -8
- data/test/MarkdownTest_1.0/Horizontal rules.html +0 -71
- data/test/MarkdownTest_1.0/Horizontal rules.text +0 -67
- data/test/MarkdownTest_1.0/Inline HTML (Advanced).html +0 -14
- data/test/MarkdownTest_1.0/Inline HTML (Advanced).text +0 -14
- data/test/MarkdownTest_1.0/Inline HTML (Simple).html +0 -72
- data/test/MarkdownTest_1.0/Inline HTML (Simple).text +0 -69
- data/test/MarkdownTest_1.0/Inline HTML comments.html +0 -13
- data/test/MarkdownTest_1.0/Inline HTML comments.text +0 -13
- data/test/MarkdownTest_1.0/Links, inline style.html +0 -9
- data/test/MarkdownTest_1.0/Links, inline style.text +0 -9
- data/test/MarkdownTest_1.0/Links, reference style.html +0 -18
- data/test/MarkdownTest_1.0/Links, reference style.text +0 -31
- data/test/MarkdownTest_1.0/Literal quotes in titles.html +0 -3
- data/test/MarkdownTest_1.0/Literal quotes in titles.text +0 -7
- data/test/MarkdownTest_1.0/Markdown Documentation - Basics.html +0 -314
- data/test/MarkdownTest_1.0/Markdown Documentation - Basics.out +0 -316
- data/test/MarkdownTest_1.0/Markdown Documentation - Basics.text +0 -306
- data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.html +0 -942
- data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.out +0 -947
- data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.text +0 -888
- data/test/MarkdownTest_1.0/Nested blockquotes.html +0 -9
- data/test/MarkdownTest_1.0/Nested blockquotes.text +0 -5
- data/test/MarkdownTest_1.0/Ordered and unordered lists.html +0 -137
- data/test/MarkdownTest_1.0/Ordered and unordered lists.text +0 -122
- data/test/MarkdownTest_1.0/Strong and em together.html +0 -7
- data/test/MarkdownTest_1.0/Strong and em together.text +0 -7
- data/test/MarkdownTest_1.0/Tabs.html +0 -25
- data/test/MarkdownTest_1.0/Tabs.text +0 -21
- data/test/MarkdownTest_1.0/Tidyness.html +0 -8
- data/test/MarkdownTest_1.0/Tidyness.text +0 -5
- data/test/MarkdownTest_1.0/run-markdown.rb +0 -56
- data/test/MarkdownTest_1.0/test-fireball-markdown.rb +0 -177
- data/test/MarkdownTest_1.0/testdiff.rb +0 -42
- data/test/harder/test-markdown-harder.rb +0 -11
- data/test/harder/test-markdown-harder.yml +0 -111
- data/test/redcloth/redcloth-markdown-tests.rb +0 -29
- data/test/redcloth/redcloth-markdown-tests.yml +0 -218
- 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
|
data/{README → README.txt}
RENAMED
@@ -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 =
|
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 '
|
53
|
-
require '
|
52
|
+
require 'tartan/markdown/rules'
|
53
|
+
require 'tartan/table/rules'
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
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 =
|
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
|
data/lib/core_ext/array.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
class Array
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
data/lib/core_ext/module.rb
CHANGED
File without changes
|
data/lib/core_ext.rb
ADDED
@@ -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: /\[(.+?)\]\((.+??)
|
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*)
|
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:
|
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
|
-
([-*+]
|
344
|
+
/ (?:\A(\s*)|(\n)[ \t]*(\n))
|
345
|
+
([-*+][ \t]+[^\n]+(:?\n[ \t]*\S[^\n]*)*)/xm
|
313
346
|
subparse:
|
314
347
|
context: listClose
|
315
|
-
match_group:
|
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: '
|
395
|
-
subparse:
|
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:
|
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
|
-
|
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
|
-
/^(
|
490
|
-
|
491
|
-
)
|
530
|
+
/^(?:(?:[-*+]|[[:digit:]]+\.)\s*
|
531
|
+
|(?:[ ]{1,4}|\t)
|
532
|
+
)
|
533
|
+
/x
|
492
534
|
replace: ''
|
493
535
|
subparse: embeddedBlock
|
494
536
|
html:
|
File without changes
|
@@ -1,13 +1,16 @@
|
|
1
|
-
#$Id: wiki-test.rb
|
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
|
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
|
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(
|
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
|
-
|
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
|