tartan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +130 -0
  3. data/TODO +17 -0
  4. data/lib/core_ext/array.rb +12 -0
  5. data/lib/core_ext/file.rb +15 -0
  6. data/lib/core_ext/hash.rb +16 -0
  7. data/lib/core_ext/match_data.rb +62 -0
  8. data/lib/core_ext/module.rb +17 -0
  9. data/lib/core_ext/regexp.rb +33 -0
  10. data/lib/markdown.yml +499 -0
  11. data/lib/symbolize.rb +78 -0
  12. data/lib/table.yml +63 -0
  13. data/lib/tartan.rb +359 -0
  14. data/lib/tartan_markdown.rb +8 -0
  15. data/lib/tartan_markdown_def.rb +7 -0
  16. data/lib/tartan_table_def.rb +7 -0
  17. data/lib/tartan_test_base_def.rb +5 -0
  18. data/lib/tartan_wikilink_def.rb +14 -0
  19. data/lib/test_base.yml +18 -0
  20. data/lib/wiki-test.rb +94 -0
  21. data/lib/wiki_rule.rb +240 -0
  22. data/lib/wikilink.yml +18 -0
  23. data/test/MarkdownTest_1.0/Amps and angle encoding.html +17 -0
  24. data/test/MarkdownTest_1.0/Amps and angle encoding.text +21 -0
  25. data/test/MarkdownTest_1.0/Auto links.html +18 -0
  26. data/test/MarkdownTest_1.0/Auto links.text +13 -0
  27. data/test/MarkdownTest_1.0/Backslash codeescapes.html +68 -0
  28. data/test/MarkdownTest_1.0/Backslash codeescapes.text +68 -0
  29. data/test/MarkdownTest_1.0/Backslash simpleescapes.html +33 -0
  30. data/test/MarkdownTest_1.0/Backslash simpleescapes.text +33 -0
  31. data/test/MarkdownTest_1.0/Blockquotes with code blocks.html +15 -0
  32. data/test/MarkdownTest_1.0/Blockquotes with code blocks.text +11 -0
  33. data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.html +8 -0
  34. data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.text +8 -0
  35. data/test/MarkdownTest_1.0/Horizontal rules.html +71 -0
  36. data/test/MarkdownTest_1.0/Horizontal rules.text +67 -0
  37. data/test/MarkdownTest_1.0/Inline HTML (Advanced).html +14 -0
  38. data/test/MarkdownTest_1.0/Inline HTML (Advanced).text +14 -0
  39. data/test/MarkdownTest_1.0/Inline HTML (Simple).html +72 -0
  40. data/test/MarkdownTest_1.0/Inline HTML (Simple).text +69 -0
  41. data/test/MarkdownTest_1.0/Inline HTML comments.html +13 -0
  42. data/test/MarkdownTest_1.0/Inline HTML comments.text +13 -0
  43. data/test/MarkdownTest_1.0/Links, inline style.html +9 -0
  44. data/test/MarkdownTest_1.0/Links, inline style.text +9 -0
  45. data/test/MarkdownTest_1.0/Links, reference style.html +18 -0
  46. data/test/MarkdownTest_1.0/Links, reference style.text +31 -0
  47. data/test/MarkdownTest_1.0/Literal quotes in titles.html +3 -0
  48. data/test/MarkdownTest_1.0/Literal quotes in titles.text +7 -0
  49. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.html +314 -0
  50. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.text +306 -0
  51. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.html +942 -0
  52. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.text +888 -0
  53. data/test/MarkdownTest_1.0/Nested blockquotes.html +9 -0
  54. data/test/MarkdownTest_1.0/Nested blockquotes.text +5 -0
  55. data/test/MarkdownTest_1.0/Ordered and unordered lists.html +137 -0
  56. data/test/MarkdownTest_1.0/Ordered and unordered lists.text +122 -0
  57. data/test/MarkdownTest_1.0/Strong and em together.html +7 -0
  58. data/test/MarkdownTest_1.0/Strong and em together.text +7 -0
  59. data/test/MarkdownTest_1.0/Tabs.html +25 -0
  60. data/test/MarkdownTest_1.0/Tabs.text +21 -0
  61. data/test/MarkdownTest_1.0/Tidyness.html +8 -0
  62. data/test/MarkdownTest_1.0/Tidyness.text +5 -0
  63. data/test/MarkdownTest_1.0/run-markdown.rb +56 -0
  64. data/test/MarkdownTest_1.0/test-fireball-markdown.rb +177 -0
  65. data/test/MarkdownTest_1.0/testdiff.rb +42 -0
  66. data/test/harder/test-markdown-harder.rb +11 -0
  67. data/test/harder/test-markdown-harder.yml +111 -0
  68. data/test/redcloth/redcloth-markdown-tests.rb +29 -0
  69. data/test/redcloth/redcloth-markdown-tests.yml +218 -0
  70. data/test/test-combo.rb +23 -0
  71. data/test/test-hash.rb +31 -0
  72. data/test/test-markdown.rb +11 -0
  73. data/test/test-markdown.yml +1144 -0
  74. data/test/test-match-data.rb +54 -0
  75. data/test/test-readme-example.rb +48 -0
  76. data/test/test-tables.rb +16 -0
  77. data/test/test-tables.yml +82 -0
  78. data/test/test-tartan-markdown.rb +11 -0
  79. data/test/test-tartan.rb +306 -0
  80. data/test/test-wikilink.rb +18 -0
  81. data/test/test-wikilink.yml +22 -0
  82. data/test/wikilink-test-helper.rb +14 -0
  83. metadata +139 -0
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ # $Id: test-match-data.rb 159 2006-07-24 08:13:02Z larry $
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
+
6
+ require 'test/unit'
7
+ require 'core_ext/match_data'
8
+
9
+ class TestMatchData < Test::Unit::TestCase
10
+ def test_replace
11
+ numbers = %w(one two three four five six seven eight nine)
12
+ number_text = numbers.join(" ")
13
+ source = "pre" + number_text + "post"
14
+ match_string = '(' + numbers.join(')\s+(') + ')'
15
+ regex = Regexp.compile(match_string)
16
+
17
+ mr = source.match(regex)
18
+
19
+ numbers.length.times do |num|
20
+ assert_equal numbers[num], mr.replace('\\'+(num+1).to_s)
21
+ end
22
+
23
+ assert_equal "pre", mr.replace('\`')
24
+ assert_equal "post", mr.replace("\\'")
25
+ assert_equal "nine", mr.replace('\+')
26
+ assert_equal number_text, mr.replace('\&')
27
+ end
28
+
29
+ def test_pre_sub_match
30
+ mr = "xxx one two three yyy".match(/(one)\s+(two)\s+(three)/)
31
+ assert_equal "one ", mr.pre_sub_match(2)
32
+ end
33
+
34
+ def test_pre_sub_match_negative_index
35
+ mr = "xxx one two three yyy".match(/(one)\s+(two)\s+(three)/)
36
+ assert_equal "one two ", mr.pre_sub_match(-1)
37
+ end
38
+
39
+ def test_post_sub_match
40
+ mr = "xxx one two three yyy".match(/(one)\s+(two)\s+(three)/)
41
+ assert_equal " three", mr.post_sub_match(2)
42
+ end
43
+
44
+ def test_post_sub_match_negative_index
45
+ mr = "xxx one two three yyy".match(/(one)\s+(two)\s+(three)/)
46
+ assert_equal " three", mr.post_sub_match(-2)
47
+ end
48
+
49
+ def test_last_nul_match_group
50
+ mr = "one two three".match(/(one)?(\s+two)?(\s+three)?(\s+four)?/)
51
+
52
+ assert_equal ' three', mr.replace('\+')
53
+ end
54
+ end
@@ -0,0 +1,48 @@
1
+ #$Id: test-readme-example.rb 164 2006-08-13 18:17:48Z larry $
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
+
5
+ require 'test/unit'
6
+ require 'tartan'
7
+
8
+ ParagraphAndCodeDef = %q~
9
+ block:
10
+ - title: code
11
+ match: "/(^[ ]{2,}\S.+?$\n)+^[ ]{2,}\S.+?$/m"
12
+ html:
13
+ start_mark: <pre><code>
14
+ end_mark: </code></pre>
15
+ - title: paragraph
16
+ match: "/(^[^\n]+$\n)+^[^\n]+$/m"
17
+ html:
18
+ start_mark: <p>
19
+ end_mark: </p>
20
+ ~
21
+ class ReadmeTestCase < Test::Unit::TestCase
22
+ class ParagraphAndCode < Tartan
23
+ set_defs(ParagraphAndCodeDef)
24
+ end
25
+
26
+ def testParagraphAndCode
27
+ text = <<TEXT
28
+ Now is the time for all good
29
+ men to come to the aid of
30
+ their party.
31
+
32
+ p "Hello"
33
+ p "World"
34
+ TEXT
35
+
36
+ html = \
37
+ %q~<p>Now is the time for all good
38
+ men to come to the aid of
39
+ their party.</p>
40
+
41
+ <pre><code> p "Hello"
42
+ p "World"</code></pre>
43
+ ~
44
+
45
+ parser = ParagraphAndCode.new(text)
46
+ assert_equal(html, parser.to_html)
47
+ end
48
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #$Id: test-wikilink-addon.rb 158 2006-05-19 16:31:45Z david $
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
+
6
+ require 'tartan'
7
+ require 'tartan_table_def'
8
+ require 'wiki-test'
9
+ require 'tartan_test_base_def'
10
+
11
+ class TartanTestTable < Tartan
12
+ include TartanTestBaseDef
13
+ include TartanTableDef
14
+ end
15
+
16
+ cases = WikiTestCases.new(TartanTestTable, "test-tables.yml")
@@ -0,0 +1,82 @@
1
+ #$Id: test-tables.yml 124 2006-05-07 16:28:09Z larry $
2
+
3
+ title: OneLineTable
4
+ in: "[|bob||jim|]"
5
+ html: |-
6
+ <table class="">
7
+ <tr><td>bob</td><td>jim</td></tr>
8
+ </table>
9
+ ---
10
+ title: OneLineTableWithBarInCell
11
+ in: "[|bob|mike||jim|]"
12
+ html: |-
13
+ <table class="">
14
+ <tr><td>bob|mike</td><td>jim</td></tr>
15
+ </table>
16
+ ---
17
+ title: OneLineHeaderTable
18
+ in: "[!bob|!jim|]"
19
+ html: |-
20
+ <table class="">
21
+ <tr><th>bob</th><th>jim</th></tr>
22
+ </table>
23
+ ---
24
+ title: OneLineTableWithClass
25
+ in: "[class|bob||jim|]"
26
+ html: |-
27
+ <table class="class">
28
+ <tr><td>bob</td><td>jim</td></tr>
29
+ </table>
30
+ ---
31
+ title: OneRowMultipleLines
32
+ in: |-
33
+ [|
34
+ bob
35
+ ||
36
+ jim
37
+ |]
38
+ html: |-
39
+ <table class="">
40
+ <tr><td><p>bob</p></td><td><p>jim</p></td></tr>
41
+ </table>
42
+ ---
43
+ title: TwoLineTable
44
+ in: |-
45
+ [|first||last|]
46
+ [|billy||bob|]
47
+ html: |-
48
+ <table class="">
49
+ <tr><td>first</td><td>last</td></tr>
50
+ <tr><td>billy</td><td>bob</td></tr>
51
+ </table>
52
+ ---
53
+ title: TwoLineTableWithClass
54
+ in: |-
55
+ [class|first||last|]
56
+ [|billy||bob|]
57
+ html: |-
58
+ <table class="class">
59
+ <tr><td>first</td><td>last</td></tr>
60
+ <tr><td>billy</td><td>bob</td></tr>
61
+ </table>
62
+ ---
63
+ title: TwoLineTableWithClassAndHeaders
64
+ in: |-
65
+ [class!first|!last|]
66
+ [|billy||bob|]
67
+ html: |-
68
+ <table class="class">
69
+ <tr><th>first</th><th>last</th></tr>
70
+ <tr><td>billy</td><td>bob</td></tr>
71
+ </table>
72
+ ---
73
+ title: TwoOneLineTablesWithClass
74
+ in: |-
75
+ [class1|joe||sally|]
76
+ [class2|bob||jim|]
77
+ html: |-
78
+ <table class="class1">
79
+ <tr><td>joe</td><td>sally</td></tr>
80
+ </table><table class="class2">
81
+ <tr><td>bob</td><td>jim</td></tr>
82
+ </table>
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ #$Id: test-tartan-markdown.rb 148 2006-07-22 14:04:20Z larry $
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
+
6
+ #require 'tartan'
7
+ require 'tartan_markdown'
8
+ require 'wiki-test'
9
+
10
+ cases = WikiTestCases.new(TartanMarkdown, "test-markdown.yml")
11
+
@@ -0,0 +1,306 @@
1
+ #$Id: test-tartan.rb 169 2006-08-16 22:16:12Z bitherder $
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
+
5
+ require 'test/unit'
6
+ require 'tartan'
7
+
8
+ Wiki_def = %q~
9
+ block:
10
+ - title: rule
11
+ match: /:\)/
12
+ html:
13
+ replace: '\1'
14
+ ~
15
+
16
+ New_def = %q~
17
+ block:
18
+ - title: newRule
19
+ match: /:\(/
20
+ html:
21
+ replace: '\1'
22
+ ~
23
+
24
+ Newer_def = %q~
25
+ block:
26
+ - title: newerRule
27
+ match: /:\(/
28
+ html:
29
+ replace: '\1'
30
+ ~
31
+
32
+ Span_def = %q~
33
+ span:
34
+ - title: spanRule
35
+ match: /->/
36
+ html:
37
+ replace: '\1'
38
+ ~
39
+
40
+ Before_def = %q~
41
+ block:
42
+ - title: beforeRule
43
+ before: rule
44
+ match: '/:\(/'
45
+ html:
46
+ replace: '\1'
47
+ ~
48
+
49
+ After_def = %q~
50
+ block:
51
+ - title: afterRule
52
+ after: rule
53
+ match: '/:\(/'
54
+ html:
55
+ replace: '\1'
56
+ ~
57
+
58
+ Beginning_def = %q~
59
+ block:
60
+ - title: beginningRule
61
+ beginning: true
62
+ match: '/:\(/'
63
+ html:
64
+ replace: '\1'
65
+ ~
66
+
67
+ Literal_def = %q~
68
+ block:
69
+ - title: beginningRule
70
+ beginning: true
71
+ match: '/:\(/'
72
+ html:
73
+ replace: '\1'
74
+ - rescan
75
+ ~
76
+
77
+ Template_def = %q~
78
+ block:
79
+ - title: fullRule
80
+ match: /(:\))/
81
+ html:
82
+ replace: '--\1--'
83
+ - title: partialRule
84
+ template: fullRule
85
+ match: /(:\()/
86
+ ~
87
+ Default_def = %q~
88
+ block:
89
+ - title: defaultRule
90
+ default: true
91
+ match: /(:\))/
92
+ html:
93
+ replace: '--\1--'
94
+ - title: partialRule
95
+ match: /(:\()/
96
+ ~
97
+
98
+ Default_def2 = %q~
99
+ block:
100
+ - title: defaultRule
101
+ default: true
102
+ ingnore: true
103
+ match: /(;\))/
104
+ html:
105
+ replace: '--\1--'
106
+ - title: smileRule
107
+ match: /(:\))/
108
+ - title: frownRule
109
+ match: /(:\()/
110
+ ~
111
+
112
+ class WikiDefsTestCase < Test::Unit::TestCase
113
+ def testInitWNoArg
114
+ defs = WikiDefs.new
115
+ assert(defs, "New def is not nil")
116
+ end
117
+
118
+ def testInsert
119
+ defs = WikiDefs.new
120
+ defs[:something] = 'bob'
121
+ assert_equal('bob', defs[:something])
122
+ end
123
+
124
+ def testInit
125
+ defs = WikiDefs.new(Wiki_def)
126
+ assert_equal(:rule, defs[:block][0].title)
127
+ end
128
+
129
+ def testAdd
130
+ defs = WikiDefs.new(Wiki_def)
131
+ defs.add(New_def)
132
+
133
+ assert_equal(:newRule, defs[:block][1].title)
134
+ end
135
+
136
+ def testAddBeginning
137
+ defs = WikiDefs.new(Wiki_def)
138
+ defs.add(Beginning_def)
139
+ assert_equal(:beginningRule,defs[:block][0].title)
140
+ assert_equal(:rule,defs[:block][1].title)
141
+ end
142
+
143
+ def testAddThree
144
+ defs = WikiDefs.new(Wiki_def)
145
+ defs.add(New_def)
146
+ defs.add(Newer_def)
147
+ assert_equal(:rule, defs[:block][0].title)
148
+ assert_equal(:newRule,defs[:block][1].title)
149
+ assert_equal(:newerRule, defs[:block][2].title)
150
+ end
151
+
152
+ def testAddAfter
153
+ defs = WikiDefs.new(Wiki_def)
154
+ defs.add(New_def)
155
+ defs.add(After_def)
156
+ assert_equal(:rule, defs[:block][0].title)
157
+ assert_equal(:afterRule,defs[:block][1].title)
158
+ assert_equal(:newRule, defs[:block][2].title)
159
+ end
160
+
161
+ def testInitWBadBefore
162
+ assert_raises(RuntimeError) do WikiDefs.new(Before_def) end
163
+ end
164
+
165
+ def testInitWBadAfter
166
+ assert_raises(RuntimeError) do WikiDefs.new(After_def) end
167
+ end
168
+
169
+ def testAddSpan
170
+ defs = WikiDefs.new(Wiki_def)
171
+ defs.add(Span_def)
172
+ assert_equal(:rule, defs[:block][0].title)
173
+ assert_equal(:spanRule,defs[:span][0].title)
174
+ end
175
+
176
+ def testTemplate
177
+ defs = WikiDefs.new(Template_def)
178
+ assert_equal(:partialRule, defs[:block][1].title)
179
+ assert_equal('--\1--', defs[:block][1].replace_regex(:html))
180
+ end
181
+
182
+ def testLiteral
183
+ defs = WikiDefs.new(Literal_def)
184
+ assert(defs[:block][1].rescan,
185
+ "lone rescan should have been embedded in a hash and set to true")
186
+ end
187
+
188
+ def testFilePath
189
+ file_and_path = nil
190
+
191
+ assert_nothing_raised do
192
+ file_and_path = WikiDefs.find_file_in_path("tartan.rb")
193
+ end
194
+ end
195
+ end
196
+
197
+ class TartanTestCase < Test::Unit::TestCase
198
+ class TestTartan < Tartan
199
+ set_defs({:block => [
200
+ {:title => 'rule',
201
+ :match => /:\)/,
202
+ :html => {:replace => '\1'}}
203
+ ]})
204
+ end
205
+
206
+ def testCreateParser
207
+ parser = TestTartan.new("x", nil)
208
+ assert(parser.to_html, "Tartan failed on empty input")
209
+ end
210
+
211
+ def testCreatParserGlobalDefs
212
+ parser = TestTartan.new("x")
213
+ assert(parser.to_html, "Tartan failed on empty input")
214
+ end
215
+
216
+ def testRemoveCRs
217
+ parser = TestTartan.new("Test.\r\n")
218
+ assert_equal("Test.\n", parser.to_html)
219
+ end
220
+
221
+ class LastRuleTartan < Tartan
222
+ set_defs({:block => [
223
+ {:title => 'rule',
224
+ :position => :not_last,
225
+ :match => /(:\))/,
226
+ :html => {:replace => '\1'}
227
+ },
228
+ {:title => 'lastRule',
229
+ :position => :last,
230
+ :match => /(:\))/,
231
+ :html => {:replace => '\1-'}
232
+ },
233
+ ]})
234
+ end
235
+
236
+ def testLastAndNotLastChecks
237
+ parser = LastRuleTartan.new(":)\n:)", nil)
238
+ assert_equal(":)\n:)-", parser.to_html)
239
+ end
240
+
241
+ class VarSetTartan < Tartan
242
+ set_defs({:block => [
243
+ {:title => 'var_rule',
244
+ :match => /(:\))/,
245
+ :set => {'smiley' => '-\1-'},
246
+ :html => {:replace => '{{{smiley}}}'},
247
+ },
248
+ ]})
249
+ end
250
+
251
+ def testSetVariable
252
+ parser = VarSetTartan.new(":)", nil)
253
+ assert_equal("-:)-", parser.to_html)
254
+ end
255
+
256
+ class SetVarMarkTartan < Tartan
257
+ set_defs({:block => [
258
+ {:title => 'var_rule',
259
+ :match => /(:\))/,
260
+ :set => {'smiley' => '-\1-'},
261
+ :html => {:start_mark => '<{{{smiley}}}>', :end_mark => '<>'},
262
+ },
263
+ ]})
264
+ end
265
+
266
+ def testSetVariableUseInMarks
267
+ parser = SetVarMarkTartan.new(":)", nil)
268
+ assert_equal("<-:)->:)<>", parser.to_html)
269
+ end
270
+
271
+ class TemplateTartan < Tartan
272
+ set_defs Template_def
273
+ end
274
+
275
+ def testTemplate
276
+ parser = TemplateTartan.new(":)", nil)
277
+ assert_equal("--:)--", parser.to_html)
278
+ parser = TemplateTartan.new(":(", nil)
279
+ assert_equal("--:(--", parser.to_html)
280
+ parser = TemplateTartan.new(":}", nil)
281
+ assert_equal(":}", parser.to_html)
282
+ end
283
+
284
+ class DefaultTartan < Tartan
285
+ set_defs Default_def
286
+ end
287
+
288
+ def testDefault
289
+
290
+ parser = DefaultTartan.new(":)", nil)
291
+ assert_equal("--:)--", parser.to_html)
292
+ parser = DefaultTartan.new(":(", nil)
293
+ assert_equal("--:(--", parser.to_html)
294
+ parser = DefaultTartan.new(":}", nil)
295
+ assert_equal(":}", parser.to_html)
296
+ end
297
+
298
+ def testDefaultWithIgnore
299
+ parser = DefaultTartan.new(":)", nil)
300
+ assert_equal("--:)--", parser.to_html)
301
+ parser = DefaultTartan.new(":(", nil)
302
+ assert_equal("--:(--", parser.to_html)
303
+ parser = DefaultTartan.new(";)", nil)
304
+ assert_equal(";)", parser.to_html)
305
+ end
306
+ end