motiro 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. data/AUTHORS +15 -0
  2. data/README +2 -2
  3. data/README.en +1 -2
  4. data/README.pt-br +1 -2
  5. data/app/controllers/account_controller.rb +1 -1
  6. data/app/controllers/application.rb +13 -12
  7. data/app/controllers/javascript_controller.rb +1 -1
  8. data/app/controllers/report_controller.rb +1 -1
  9. data/app/controllers/wiki_controller.rb +3 -5
  10. data/app/core/cache_reporter.rb +1 -1
  11. data/app/core/cache_reporter_fetcher.rb +1 -1
  12. data/app/core/chief_editor.rb +1 -1
  13. data/app/core/reporter.rb +1 -1
  14. data/app/core/reporter_driver.rb +1 -1
  15. data/app/core/reporter_fetcher.rb +1 -1
  16. data/app/core/settings.rb +1 -1
  17. data/app/core/version.rb +1 -1
  18. data/app/core/wiki_reporter.rb +1 -1
  19. data/app/helpers/application_helper.rb +5 -1
  20. data/app/helpers/default_page_provider.rb +6 -2
  21. data/app/helpers/report_helper.rb +14 -1
  22. data/app/models/change.rb +1 -1
  23. data/app/models/chunk.rb +1 -1
  24. data/app/models/feed_observer.rb +1 -1
  25. data/app/models/headline.rb +1 -1
  26. data/app/models/page.rb +38 -4
  27. data/app/models/revision.rb +1 -1
  28. data/app/models/user.rb +1 -1
  29. data/app/models/wiki_reference.rb +21 -0
  30. data/app/models/wiki_sweeper.rb +17 -2
  31. data/app/ports/chdir_runner.rb +1 -1
  32. data/app/ports/runner.rb +1 -1
  33. data/app/reporters/darcs_connection.rb +1 -1
  34. data/app/reporters/darcs_reporter.rb +1 -1
  35. data/app/reporters/darcs_temp_repo.rb +1 -1
  36. data/app/reporters/events_reporter.rb +1 -1
  37. data/app/reporters/features_reporter.rb +1 -1
  38. data/app/reporters/subversion_reporter.rb +1 -1
  39. data/app/reporters/svn_connection.rb +1 -1
  40. data/app/reporters/svn_settings.rb +1 -1
  41. data/app/views/report/list.rhtml +6 -7
  42. data/app/views/report/older.rhtml +1 -2
  43. data/app/views/report/rss.rxml +1 -1
  44. data/app/views/report/show.rhtml +2 -2
  45. data/app/views/wiki/_edit_event.rhtml +2 -0
  46. data/app/views/wiki/_edit_feature.rhtml +2 -0
  47. data/app/views/wiki/_properties_edit.rhtml +3 -5
  48. data/app/views/wiki/_properties_show.rhtml +4 -5
  49. data/app/views/wiki/_show_event.rhtml +3 -0
  50. data/app/views/wiki/_show_feature.rhtml +2 -0
  51. data/app/views/wiki/show.rhtml +1 -1
  52. data/bin/motiro +3 -3
  53. data/config/routes.rb +1 -1
  54. data/db/migrate/024_add_feature_status.rb +11 -0
  55. data/db/migrate/025_add_page_references.rb +12 -0
  56. data/db/migrate/026_convert_link_syntax.rb +12 -0
  57. data/db/migrate/027_register_page_references.rb +12 -0
  58. data/db/motirodb.sqlite.initial +0 -0
  59. data/db/schema_version +1 -1
  60. data/db/translation/pt-BR.rb +7 -1
  61. data/lib/array_extensions.rb +1 -1
  62. data/lib/diff_chunk_builder.rb +1 -1
  63. data/lib/differ.rb +1 -1
  64. data/lib/string_extensions.rb +13 -6
  65. data/lib/stub_hash.rb +1 -1
  66. data/lib/tasks/packaging.rake +10 -12
  67. data/lib/tasks/testing.rake +1 -1
  68. data/lib/tick_daemon.rb +1 -1
  69. data/lib/{wiki_url_generator.rb → wiki_link_handler.rb} +13 -3
  70. data/lib/wiki_renderer.rb +63 -34
  71. data/public/images/done.png +0 -0
  72. data/public/images/not-done.png +0 -0
  73. data/public/stylesheets/motiro.css +8 -0
  74. data/script/ticker +1 -1
  75. data/test/acceptance/account_test.rb +1 -1
  76. data/test/acceptance/darcs_test.rb +1 -1
  77. data/test/acceptance/events_test.rb +1 -1
  78. data/test/acceptance/main_page_test.rb +1 -1
  79. data/test/acceptance/subversion_test.rb +1 -1
  80. data/test/acceptance/ts_all_suites.rb +1 -1
  81. data/test/acceptance/wiki_test.rb +3 -3
  82. data/test/contract/darcs_test.rb +1 -1
  83. data/test/contract/remote_darcs_test.rb +1 -1
  84. data/test/contract/svn_test.rb +1 -1
  85. data/test/fixtures/pages.yml +20 -1
  86. data/test/fixtures/revisions.yml +40 -1
  87. data/test/fixtures/wiki_references.yml +5 -0
  88. data/test/functional/report_controller_test.rb +1 -1
  89. data/test/functional/report_features_test.rb +8 -1
  90. data/test/functional/report_subversion_test.rb +1 -1
  91. data/test/functional/root_controller_test.rb +1 -1
  92. data/test/functional/wiki_controller_test.rb +67 -2
  93. data/test/lib/acceptance_test_case.rb +1 -1
  94. data/test/lib/darcs_excerpts.rb +1 -1
  95. data/test/lib/darcs_repo.rb +1 -1
  96. data/test/lib/hash_extensions.rb +22 -0
  97. data/test/lib/live_mode_test.rb +1 -1
  98. data/test/lib/netutils.rb +1 -1
  99. data/test/lib/platform_thread.rb +1 -1
  100. data/test/lib/selenium_extensions.rb +1 -1
  101. data/test/lib/stubio.rb +1 -1
  102. data/test/lib/webserver.rb +1 -1
  103. data/test/meta/darcs_repo_test.rb +1 -1
  104. data/test/meta/local_svn_test.rb +1 -1
  105. data/test/meta/platform_thread_test.rb +1 -1
  106. data/test/meta/stubio_test.rb +1 -1
  107. data/test/stubs/{url_generator.rb → wiki_link_handler.rb} +8 -4
  108. data/test/test_helper.rb +3 -1
  109. data/test/unit/array_extensions_test.rb +1 -1
  110. data/test/unit/cache_reporter_fetcher_test.rb +1 -1
  111. data/test/unit/cache_reporter_test.rb +1 -1
  112. data/test/unit/change_test.rb +1 -1
  113. data/test/unit/chdir_runner_test.rb +1 -1
  114. data/test/unit/chief_editor_test.rb +1 -1
  115. data/test/unit/darcs_connection_test.rb +1 -1
  116. data/test/unit/darcs_reporter_test.rb +4 -4
  117. data/test/unit/darcs_temp_repo_test.rb +1 -1
  118. data/test/unit/default_page_provider_test.rb +23 -13
  119. data/test/unit/diff_chunk_builder_test.rb +1 -1
  120. data/test/unit/page_test.rb +67 -4
  121. data/test/unit/reporter_driver_test.rb +1 -1
  122. data/test/unit/reporter_test.rb +1 -1
  123. data/test/unit/revision_test.rb +1 -1
  124. data/test/unit/runner_test.rb +1 -1
  125. data/test/unit/string_extensions_test.rb +15 -3
  126. data/test/unit/svn_connection_test.rb +1 -1
  127. data/test/unit/svn_reporter_interaction_test.rb +1 -1
  128. data/test/unit/svn_reporter_test.rb +1 -1
  129. data/test/unit/svn_settings_test.rb +1 -1
  130. data/test/unit/user_test.rb +1 -1
  131. data/test/unit/{wiki_url_generator_test.rb → wiki_link_handler_test.rb} +3 -3
  132. data/test/unit/wiki_renderer_test.rb +75 -20
  133. data/test/unit/wiki_reporter_test.rb +1 -1
  134. data/vendor/mediacloth-trunk/MIT-LICENSE +20 -0
  135. data/vendor/mediacloth-trunk/README +32 -0
  136. data/vendor/mediacloth-trunk/Rakefile +33 -0
  137. data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiast.rb +122 -0
  138. data/vendor/mediacloth-trunk/lib/mediacloth/mediawikihtmlgenerator.rb +252 -0
  139. data/vendor/mediacloth-trunk/lib/mediacloth/mediawikilexer.rb +821 -0
  140. data/vendor/mediacloth-trunk/lib/mediacloth/mediawikilinkhandler.rb +68 -0
  141. data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiparams.rb +33 -0
  142. data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiparser.rb +1218 -0
  143. data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiparser.y +493 -0
  144. data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiwalker.rb +146 -0
  145. data/vendor/mediacloth-trunk/lib/mediacloth.rb +29 -0
  146. data/vendor/mediacloth-trunk/mediacloth.gemspec +24 -0
  147. data/vendor/mediacloth-trunk/mediacloth.kdevelop +117 -0
  148. data/vendor/mediacloth-trunk/setup.rb +1585 -0
  149. data/vendor/mediacloth-trunk/test/data/html1 +26 -0
  150. data/vendor/mediacloth-trunk/test/data/html10 +130 -0
  151. data/vendor/mediacloth-trunk/test/data/html11 +17 -0
  152. data/vendor/mediacloth-trunk/test/data/html12 +12 -0
  153. data/vendor/mediacloth-trunk/test/data/html13 +11 -0
  154. data/vendor/mediacloth-trunk/test/data/html2 +2 -0
  155. data/vendor/mediacloth-trunk/test/data/html3 +1 -0
  156. data/vendor/mediacloth-trunk/test/data/html4 +47 -0
  157. data/vendor/mediacloth-trunk/test/data/html5 +57 -0
  158. data/vendor/mediacloth-trunk/test/data/html6 +8 -0
  159. data/vendor/mediacloth-trunk/test/data/html7 +45 -0
  160. data/vendor/mediacloth-trunk/test/data/html8 +1 -0
  161. data/vendor/mediacloth-trunk/test/data/html9 +14 -0
  162. data/vendor/mediacloth-trunk/test/data/input1 +34 -0
  163. data/vendor/mediacloth-trunk/test/data/input10 +124 -0
  164. data/vendor/mediacloth-trunk/test/data/input11 +17 -0
  165. data/vendor/mediacloth-trunk/test/data/input12 +15 -0
  166. data/vendor/mediacloth-trunk/test/data/input13 +10 -0
  167. data/vendor/mediacloth-trunk/test/data/input2 +2 -0
  168. data/vendor/mediacloth-trunk/test/data/input3 +2 -0
  169. data/vendor/mediacloth-trunk/test/data/input4 +50 -0
  170. data/vendor/mediacloth-trunk/test/data/input5 +63 -0
  171. data/vendor/mediacloth-trunk/test/data/input6 +8 -0
  172. data/vendor/mediacloth-trunk/test/data/input7 +45 -0
  173. data/vendor/mediacloth-trunk/test/data/input8 +1 -0
  174. data/vendor/mediacloth-trunk/test/data/input9 +14 -0
  175. data/vendor/mediacloth-trunk/test/data/lex1 +26 -0
  176. data/vendor/mediacloth-trunk/test/data/lex10 +85 -0
  177. data/vendor/mediacloth-trunk/test/data/lex11 +17 -0
  178. data/vendor/mediacloth-trunk/test/data/lex12 +15 -0
  179. data/vendor/mediacloth-trunk/test/data/lex13 +3 -0
  180. data/vendor/mediacloth-trunk/test/data/lex2 +2 -0
  181. data/vendor/mediacloth-trunk/test/data/lex3 +1 -0
  182. data/vendor/mediacloth-trunk/test/data/lex4 +47 -0
  183. data/vendor/mediacloth-trunk/test/data/lex5 +57 -0
  184. data/vendor/mediacloth-trunk/test/data/lex6 +8 -0
  185. data/vendor/mediacloth-trunk/test/data/lex7 +45 -0
  186. data/vendor/mediacloth-trunk/test/data/lex8 +1 -0
  187. data/vendor/mediacloth-trunk/test/data/lex9 +14 -0
  188. data/vendor/mediacloth-trunk/test/data/result1 +48 -0
  189. data/vendor/mediacloth-trunk/test/dataproducers/html.rb +18 -0
  190. data/vendor/mediacloth-trunk/test/dataproducers/lex.rb +15 -0
  191. data/vendor/mediacloth-trunk/test/debugwalker.rb +68 -0
  192. data/vendor/mediacloth-trunk/test/htmlgenerator.rb +97 -0
  193. data/vendor/mediacloth-trunk/test/lexer.rb +542 -0
  194. data/vendor/mediacloth-trunk/test/linkhandler.rb +39 -0
  195. data/vendor/mediacloth-trunk/test/parser.rb +22 -0
  196. data/vendor/mediacloth-trunk/test/testhelper.rb +27 -0
  197. data/vendor/mediacloth.rb +3 -0
  198. data/vendor/motiro-installer.rb +1 -1
  199. data/vendor/plugins/cache_test-0.2/CHANGELOG +14 -0
  200. data/vendor/plugins/cache_test-0.2/MIT-LICENSE +20 -0
  201. data/vendor/plugins/cache_test-0.2/README +124 -0
  202. data/vendor/plugins/cache_test-0.2/init.rb +8 -0
  203. data/vendor/plugins/cache_test-0.2/lib/fragment_cache_test.rb +205 -0
  204. data/vendor/plugins/cache_test-0.2/lib/page_cache_test.rb +140 -0
  205. data/vendor/plugins/global_routing/init.rb +1 -1
  206. metadata +517 -455
@@ -0,0 +1,97 @@
1
+ require 'mediacloth/mediawikilexer'
2
+ require 'mediacloth/mediawikiparser'
3
+ require 'mediacloth/mediawikihtmlgenerator'
4
+ require 'mediacloth/mediawikilinkhandler'
5
+
6
+ require 'test/unit'
7
+ require 'testhelper'
8
+
9
+ class HTMLGenerator_Test < Test::Unit::TestCase
10
+
11
+ include TestHelper
12
+
13
+ def test_input
14
+ test_files("html") do |input,result, name|
15
+ puts name
16
+ assert_generates(result, input, nil, name)
17
+ end
18
+ end
19
+
20
+ def test_uses_element_attributes_from_link_handler
21
+ assert_generates '<p><a class="empty" href="http://www.example.com/wiki/InternalLink">This is just an internal link</a></p>',
22
+ '[[InternalLink|This is just an internal link]]',
23
+ ClassEmptyLinkHandler.new
24
+ end
25
+
26
+ def test_accepts_url_only_link_handlers
27
+ assert_generates '<p><a href="http://www.example.com/wiki/InternalLink/">This is just an internal link</a></p>',
28
+ '[[InternalLink|This is just an internal link]]',
29
+ UrlOnlyLinkHandler.new
30
+ end
31
+
32
+ def test_prefers_url_from_attributes_when_provided_with_ambiguous_link_info
33
+ assert_generates '<p><a href="http://www.example.com/wiki/InternalLink" rel="nofollow">This is just an internal link</a></p>',
34
+ '[[InternalLink|This is just an internal link]]',
35
+ AmbiguousLinkHandler.new
36
+ end
37
+
38
+ def test_allows_specification_of_all_attributes
39
+ assert_generates '<p><a href="http://www.mysite.com/MyLink" id="123">Here is my link</a></p>',
40
+ '[[MyLink|Here is my link]]',
41
+ LinkAttributeHandler.new
42
+ end
43
+
44
+ def test_allows_full_customization_of_link_tags
45
+ assert_generates '<p><span class="link">This doesn\'t even render into a real link</span></p>',
46
+ "[[AnotherLink|This doesn't even render into a real link]]",
47
+ FullLinkHandler.new
48
+ end
49
+
50
+ private
51
+
52
+ def assert_generates(result, input, link_handler=nil, message=nil)
53
+ parser = MediaWikiParser.new
54
+ parser.lexer = MediaWikiLexer.new
55
+ ast = parser.parse(input)
56
+ MediaWikiParams.instance.time = Time.utc(2000, 1, 1, 1, 1, 1, 1)
57
+ generator = MediaWikiHTMLGenerator.new
58
+ generator.link_handler = link_handler if link_handler
59
+ generator.parse(ast)
60
+ assert_equal(result, generator.html, message)
61
+ end
62
+ end
63
+
64
+ class LinkAttributeHandler < MediaWikiLinkHandler
65
+ def link_attributes_for(page)
66
+ { :href => "http://www.mysite.com/#{page}", :id => '123' }
67
+ end
68
+ end
69
+
70
+ class ClassEmptyLinkHandler < MediaWikiLinkHandler
71
+ def link_attributes_for(resource)
72
+ {:class => 'empty', :href => "http://www.example.com/wiki/#{resource}"}
73
+ end
74
+ end
75
+
76
+ class UrlOnlyLinkHandler < MediaWikiLinkHandler
77
+ def url_for(resource)
78
+ "http://www.example.com/wiki/#{resource}/"
79
+ end
80
+ end
81
+
82
+ class AmbiguousLinkHandler < MediaWikiLinkHandler
83
+ def url_for(resource)
84
+ "http://www.somewhereelse.net"
85
+ end
86
+
87
+ def link_attributes_for(resource)
88
+ {:rel => 'nofollow', :href => "http://www.example.com/wiki/#{resource}"}
89
+ end
90
+ end
91
+
92
+ class FullLinkHandler < MediaWikiLinkHandler
93
+ def link_for(page, text)
94
+ "<span class=\"link\">#{text}</span>"
95
+ end
96
+ end
97
+
@@ -0,0 +1,542 @@
1
+ require 'mediacloth/mediawikilexer'
2
+ require 'test/unit'
3
+ require 'testhelper'
4
+
5
+ class Lexer_Test < Test::Unit::TestCase
6
+
7
+ include TestHelper
8
+
9
+ def test_standard_formatted_input
10
+ test_files("lex") { |input,result,resultname|
11
+ lexer = MediaWikiLexer.new
12
+ tokens = lexer.tokenize(input)
13
+ assert_equal(result, tokens.to_s, "Mismatch in #{resultname}")
14
+ }
15
+ end
16
+
17
+ def test_internet_formatted_input
18
+ test_files("lex") { |input,result,resultname|
19
+ lexer = MediaWikiLexer.new
20
+ tokens = lexer.tokenize(input.gsub("\n", "\r\n"))
21
+ assert_equal(result.gsub("\n", "\r\n"), tokens.to_s, "Mismatch in #{resultname}")
22
+ }
23
+ end
24
+
25
+ def test_empty
26
+ assert_equal([[false,false]], lex(""))
27
+ end
28
+
29
+ def test_paragraphs
30
+ assert_equal(
31
+ [[:PARA_START, ""], [:TEXT, "text"], [:PARA_END, ""], [false,false]],
32
+ lex("text"))
33
+ assert_equal(
34
+ [[:PARA_START, ""], [:TEXT, "text\ntext"], [:PARA_END, ""], [false,false]],
35
+ lex("text\ntext"))
36
+ assert_equal(
37
+ [[:PARA_START, ""], [:TEXT, "text\r\ntext"], [:PARA_END, ""], [false,false]],
38
+ lex("text\r\ntext"))
39
+ assert_equal(
40
+ [[:PARA_START, ""], [:TEXT, "text\n\n"], [:PARA_END, ""],
41
+ [:PARA_START, ""], [:TEXT, "text"], [:PARA_END, ""], [false,false]],
42
+ lex("text\n\ntext"))
43
+ assert_equal(
44
+ [[:PARA_START, ""], [:TEXT, "text\r\n\r\n"], [:PARA_END, ""],
45
+ [:PARA_START, ""], [:TEXT, "text"], [:PARA_END, ""], [false,false]],
46
+ lex("text\r\n\r\ntext"))
47
+ assert_equal(
48
+ [[:PARA_START, ""], [:TEXT, "text\n\n"], [:PARA_END, ""],
49
+ [:PARA_START, ""], [:TEXT, "\ntext"], [:PARA_END, ""], [false,false]],
50
+ lex("text\n\n\ntext"))
51
+ assert_equal(
52
+ [[:PARA_START, ""], [:TEXT, "text\n\n"], [:PARA_END, ""], [:PARA_START, ""],
53
+ [:TEXT, "\n\n"], [:PARA_END, ""], [:PARA_START, ""], [:TEXT, "text"], [:PARA_END, ""],
54
+ [false,false]],
55
+ lex("text\n\n\n\ntext"))
56
+ assert_equal(
57
+ [[:PARA_START, ""], [:TEXT, "text\n"], [:PARA_END, ""],
58
+ [:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="], [false,false]],
59
+ lex("text\n=heading="))
60
+ assert_equal(
61
+ [[:PARA_START, ""], [:TEXT, "text\r\n"], [:PARA_END, ""],
62
+ [:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="], [false,false]],
63
+ lex("text\r\n=heading="))
64
+ assert_equal(
65
+ [[:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="],
66
+ [:PARA_START, ""], [:TEXT, "\ntext"], [:PARA_END, ""], [false,false]],
67
+ lex("=heading=\ntext"))
68
+ assert_equal(
69
+ [[:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="],
70
+ [:PARA_START, ""], [:TEXT, "\r\ntext"], [:PARA_END, ""], [false,false]],
71
+ lex("=heading=\r\ntext"))
72
+ assert_equal(
73
+ [[:PARA_START, ""], [:TEXT, "text\n\n"], [:PARA_END, ""],
74
+ [:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="], [false,false]],
75
+ lex("text\n\n=heading="))
76
+ assert_equal(
77
+ [[:PARA_START, ""], [:TEXT, "text\r\n\r\n"], [:PARA_END, ""],
78
+ [:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="], [false,false]],
79
+ lex("text\r\n\r\n=heading="))
80
+ end
81
+
82
+ def test_formatting
83
+ assert_equal(
84
+ [[:PARA_START, ""], [:ITALIC_START, "''"], [:TEXT, "italic"], [:ITALIC_END, "''"],
85
+ [:PARA_END, ""], [false,false]],
86
+ lex("''italic''"))
87
+ assert_equal(
88
+ [[:PARA_START, ""], [:BOLD_START, "'''"], [:TEXT, "bold"], [:BOLD_END, "'''"],
89
+ [:PARA_END, ""], [false,false]],
90
+ lex("'''bold'''"))
91
+ assert_equal(
92
+ [[:PARA_START, ""], [:ITALIC_START, "''"], [:TEXT, "italic"], [:BOLD_START, "'''"],
93
+ [:TEXT, "bold"], [:BOLD_END, "'''"], [:TEXT, "italic"], [:ITALIC_END, "''"],
94
+ [:PARA_END, ""], [false,false]],
95
+ lex("''italic'''bold'''italic''"))
96
+ assert_equal(
97
+ [[:PARA_START, ""], [:ITALIC_START, "''"], [:BOLD_START, "'''"],
98
+ [:TEXT, "bolditalic"], [:BOLD_END, "'''"], [:ITALIC_END, "''"],
99
+ [:PARA_END, ""], [false,false]],
100
+ lex("'''''bolditalic'''''"))
101
+ assert_equal(
102
+ [[:PARA_START, ""], [:ITALIC_START, "''"], [:TEXT, "italic\n\n"], [:ITALIC_END, ""],
103
+ [:PARA_END, ""], [false,false]],
104
+ lex("''italic\n\n"))
105
+ end
106
+
107
+ def test_headings
108
+ assert_equal(
109
+ [[:SECTION_START, "="], [:TEXT, "heading"], [:SECTION_END, "="], [false,false]],
110
+ lex("=heading="))
111
+ assert_equal(
112
+ [[:SECTION_START, "=="], [:TEXT, "heading"], [:SECTION_END, "=="], [false,false]],
113
+ lex("==heading=="))
114
+ assert_equal(
115
+ [[:SECTION_START, "=="], [:TEXT, " 1 <= 2 "], [:SECTION_END, "=="], [false,false]],
116
+ lex("== 1 <= 2 =="))
117
+ assert_equal(
118
+ [[:SECTION_START, "=="], [:TEXT, "heading"], [:SECTION_END, "=="],
119
+ [:PARA_START, ""], [:TEXT, "text"], [:PARA_END, ""], [false,false]],
120
+ lex("==heading==text"))
121
+ assert_equal(
122
+ [[:SECTION_START, "="], [:ITALIC_START, "''"], [:TEXT, "italic"], [:ITALIC_END, "''"],
123
+ [:SECTION_END, "="], [false,false]],
124
+ lex("=''italic''="))
125
+ assert_equal(
126
+ [[:SECTION_START, "=="], [:TEXT, "heading"], [:SECTION_END, ""], [:PARA_START, ""],
127
+ [:TEXT, "\n\n"], [:PARA_END, ''], [false,false]],
128
+ lex("==heading\n\n"))
129
+ assert_equal(
130
+ [[:SECTION_START, "=="], [:TEXT, "heading"], [:SECTION_END, ""], [:PARA_START, ""],
131
+ [:TEXT, "\ntext"], [:PARA_END, ''], [false,false]],
132
+ lex("==heading\ntext"))
133
+ end
134
+
135
+ def test_inline_links
136
+ assert_equal(
137
+ [[:PARA_START, ""], [:LINK_START, ""], [:TEXT, "http://example.com"], [:LINK_END, ""],
138
+ [:PARA_END, ""], [false, false]],
139
+ lex("http://example.com"))
140
+ assert_equal(
141
+ [[:PARA_START, ""], [:LINK_START, ""], [:TEXT, "http://example.com"], [:LINK_END, ""],
142
+ [:PARA_END, ""], [false, false]],
143
+ lex("http://example.com\n"))
144
+ assert_equal(
145
+ [[:PARA_START, ""], [:LINK_START, ""], [:TEXT, "http://example.com"], [:LINK_END, ""],
146
+ [:ITALIC_START, "''"], [:TEXT, "italic"], [:ITALIC_END, "''"], [:PARA_END, ""], [false, false]],
147
+ lex("http://example.com''italic''"))
148
+ assert_equal(
149
+ [[:PARA_START, ""], [:TEXT, "http:notaurl"], [:PARA_END, ""], [false,false]],
150
+ lex("http:notaurl"))
151
+ assert_equal(
152
+ [[:SECTION_START, "="], [:TEXT, " "], [:LINK_START, ""], [:TEXT, "http://example.com"],
153
+ [:LINK_END, ""], [:TEXT, " "], [:SECTION_END, "="], [false, false]],
154
+ lex("= http://example.com ="))
155
+ assert_equal(
156
+ [[:PARA_START, ""], [:LINK_START, ""], [:TEXT, "http://example.com/SpecialCharacters%C3%A7%C3%A3o"], [:LINK_END, ""],
157
+ [:PARA_END, ""], [false, false]],
158
+ lex("http://example.com/SpecialCharacters%C3%A7%C3%A3o"))
159
+ end
160
+
161
+ def test_links
162
+ assert_equal(
163
+ [[:PARA_START, ""], [:TEXT, "[]"], [:PARA_END, ""], [false, false]],
164
+ lex("[]"))
165
+ assert_equal(
166
+ [[:PARA_START, ""], [:TEXT, "[ ]"], [:PARA_END, ""], [false, false]],
167
+ lex("[ ]"))
168
+ assert_equal(
169
+ [[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINK_END, "]"],
170
+ [:PARA_END, ""], [false, false]],
171
+ lex("[http://example.com]"))
172
+ assert_equal(
173
+ [[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINK_END, "]"],
174
+ [:PARA_END, ""], [false, false]],
175
+ lex("[http://example.com ]"))
176
+ assert_equal(
177
+ [[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINK_END, "]"],
178
+ [:PARA_END, ""], [false, false]],
179
+ lex("[ http://example.com]"))
180
+ assert_equal(
181
+ [[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINKSEP, " "],
182
+ [:TEXT, "example"], [:LINK_END, "]"], [:PARA_END, ""], [false, false]],
183
+ lex("[http://example.com example]"))
184
+ assert_equal(
185
+ [[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINKSEP, " "],
186
+ [:TEXT, "example"], [:LINK_END, "]"], [:PARA_END, ""], [false, false]],
187
+ lex("[http://example.com example]"))
188
+ assert_equal(
189
+ [[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINKSEP, " "],
190
+ [:TEXT, "this is an example"], [:LINK_END, "]"], [:PARA_END, ""], [false, false]],
191
+ lex("[http://example.com this is an example]"))
192
+ assert_equal(
193
+ [[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINKSEP, " "],
194
+ [:ITALIC_START, "''"], [:TEXT, "italic"], [:ITALIC_END, "''"], [:LINK_END, "]"],
195
+ [:PARA_END, ""], [false, false]],
196
+ lex("[http://example.com ''italic'']"))
197
+ assert_equal(
198
+ [[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINKSEP, " "],
199
+ [:TEXT, "[example"], [:LINK_END, "]"], [:PARA_END, ""], [false, false]],
200
+ lex("[http://example.com [example]"))
201
+ assert_equal(
202
+ [[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINK_END, ""],
203
+ [:TEXT, "\ntext"], [:PARA_END, ""], [false, false]],
204
+ lex("[http://example.com\ntext"))
205
+ assert_equal(
206
+ [[:PARA_START, ""], [:TEXT, "[text]"], [:PARA_END, ""], [false,false]],
207
+ lex("[text]"))
208
+ end
209
+
210
+ def test_internal_links
211
+ assert_equal(
212
+ [[:PARA_START, ""], [:TEXT, "[[]]"], [:PARA_END, ""], [false, false]],
213
+ lex("[[]]"))
214
+ assert_equal(
215
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "example"], [:INTLINK_END, "]]"],
216
+ [:PARA_END, ""], [false, false]],
217
+ lex("[[example]]"))
218
+ assert_equal(
219
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "example page"], [:INTLINK_END, "]]"],
220
+ [:PARA_END, ""], [false, false]],
221
+ lex("[[example page]]"))
222
+ assert_equal(
223
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "example"], [:INTLINKSEP, "|"],
224
+ [:TEXT, "option"], [:INTLINK_END, "]]"], [:PARA_END, ""], [false, false]],
225
+ lex("[[example|option]]"))
226
+ assert_equal(
227
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "example"], [:INTLINKSEP, "|"],
228
+ [:TEXT, "option1|option2"], [:INTLINK_END, "]]"], [:PARA_END, ""], [false, false]],
229
+ lex("[[example|option1|option2]]"))
230
+ assert_equal(
231
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "resource"], [:RESOURCESEP, ":"],
232
+ [:TEXT, "example"], [:INTLINKSEP, "|"], [:TEXT, "option1"], [:INTLINKSEP, "|"],
233
+ [:TEXT, "option2"], [:INTLINK_END, "]]"], [:PARA_END, ""], [false, false]],
234
+ lex("[[resource:example|option1|option2]]"))
235
+ assert_equal(
236
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "resource"], [:RESOURCESEP, ":"],
237
+ [:TEXT, "example"], [:INTLINKSEP, "|"], [:TEXT, "this:that"], [:INTLINK_END, "]]"],
238
+ [:PARA_END, ""], [false, false]],
239
+ lex("[[resource:example|this:that]]"))
240
+ assert_equal(
241
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "resource"], [:RESOURCESEP, ":"],
242
+ [:TEXT, "example"], [:INTLINKSEP, "|"], [:INTLINK_START, "[["], [:TEXT, "link"],
243
+ [:INTLINK_END, "]]"], [:INTLINK_END, "]]"], [:PARA_END, ""], [false, false]],
244
+ lex("[[resource:example|[[link]]]]"))
245
+ assert_equal(
246
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "resource"], [:RESOURCESEP, ":"],
247
+ [:TEXT, "example"], [:INTLINKSEP, "|"], [:INTLINKSEP, "|"], [:TEXT, "option"],
248
+ [:INTLINK_END, "]]"], [:PARA_END, ""], [false, false]],
249
+ lex("[[resource:example||option]]"))
250
+ assert_equal(
251
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "example"], [:INTLINKSEP, "|"],
252
+ [:TEXT, "option"], [:ITALIC_START, "''"], [:TEXT, "italic"], [:ITALIC_END, "''"],
253
+ [:TEXT, "option"], [:INTLINK_END, "]]"], [:PARA_END, ""], [false, false]],
254
+ lex("[[example|option''italic''option]]"))
255
+ assert_equal(
256
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "example"], [:INTLINKSEP, "|"],
257
+ [:TEXT, "option[http://example.com]option"], [:INTLINK_END, "]]"], [:PARA_END, ""], [false, false]],
258
+ lex("[[example|option[http://example.com]option]]"))
259
+ assert_equal(
260
+ [[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "example"], [:INTLINKSEP, "|"],
261
+ [:TEXT, "option"], [:INTLINK_END, ""], [:TEXT, "\n\n"], [:PARA_END, ""], [false, false]],
262
+ lex("[[example|option\n\n"))
263
+ end
264
+
265
+ def test_table
266
+ assert_equal([[:TABLE_START, "{|"], [:TABLE_END, "|}"], [false, false]],
267
+ lex("{|\n|}"))
268
+ assert_equal([[:TABLE_START, "{|"], [:TEXT, " width='100%'\n"], [:TABLE_END, "|}"],
269
+ [false, false]],
270
+ lex("{| width='100%'\n|}"))
271
+ assert_equal([[:TABLE_START, "{|"], [:ROW_START, ""], [:CELL_START, "|"], [:TEXT, "a\n"],
272
+ [:CELL_END, ""], [:CELL_START, "|"], [:TEXT, "b\n"], [:CELL_END, ""], [:ROW_END, ""],
273
+ [:TABLE_END, "|}"], [false, false]],
274
+ lex("{|\n|a\n|b\n|}"))
275
+ assert_equal([[:TABLE_START, "{|"], [:ROW_START, ""], [:CELL_START, "|"], [:TEXT, "a"],
276
+ [:CELL_END, ""], [:CELL_START, "||"], [:TEXT, "b\n"], [:CELL_END, ""], [:ROW_END, ""],
277
+ [:TABLE_END, "|}"], [false, false]],
278
+ lex("{|\n|a||b\n|}"))
279
+ assert_equal([[:TABLE_START, "{|"], [:ROW_START, ""], [:CELL_START, "|"], [:TEXT, "a\n"],
280
+ [:CELL_END, ""], [:ROW_END, ""], [:ROW_START, "|-"], [:CELL_START, "|"], [:TEXT, "b\n"],
281
+ [:CELL_END, ""], [:ROW_END, ""], [:TABLE_END, "|}"], [false, false]],
282
+ lex("{|\n|a\n|-\n|b\n|}"))
283
+ assert_equal([[:TABLE_START, "{|"], [:ROW_START, ""], [:CELL_START, "|"], [:TEXT, "a\n"],
284
+ [:CELL_END, ""], [:ROW_END, ""], [:ROW_START, "|-"], [:TEXT, " align='left'\n"],
285
+ [:CELL_START, "|"], [:TEXT, "b\n"], [:CELL_END, ""], [:ROW_END, ""], [:TABLE_END, "|}"],
286
+ [false, false]],
287
+ lex("{|\n|a\n|- align='left'\n|b\n|}"))
288
+ end
289
+
290
+ def test_preformatted
291
+ assert_equal([[:PRE_START, ''], [:TEXT, " text\n"], [:PRE_END, ''], [false, false]],
292
+ lex(" text\n"))
293
+ assert_equal([[:PRE_START, ''], [:TEXT, " text\r\n"], [:PRE_END, ''], [false, false]],
294
+ lex(" text\r\n"))
295
+ assert_equal([[:PRE_START, ''], [:TEXT, " text\n text\n"], [:PRE_END, ''], [false, false]],
296
+ lex(" text\n text\n"))
297
+ assert_equal([[:PARA_START, ''], [:TEXT, "text\n"], [:PARA_END, ''], [:PRE_START, ''],
298
+ [:TEXT, " text\n"], [:PRE_END, ''], [false, false]],
299
+ lex("text\n text\n"))
300
+ assert_equal([[:PRE_START, ''], [:TEXT, " text\n"], [:PRE_END, ''], [:PARA_START, ''],
301
+ [:TEXT, "text\n"], [:PARA_END, ''], [false, false]],
302
+ lex(" text\ntext\n"))
303
+ assert_equal([[:PRE_START, ''], [:TEXT, ' '], [:ITALIC_START, "''"], [:TEXT, "italic"],
304
+ [:ITALIC_END, "''"], [:TEXT, "\n"], [:PRE_END, ''], [false, false]],
305
+ lex(" ''italic''\n"))
306
+ end
307
+
308
+ def test_hline
309
+ assert_equal([[:HLINE, "----"], [false, false]], lex("----"))
310
+ assert_equal([[:HLINE, "----"], [false, false]], lex("\n----"))
311
+ assert_equal([[:HLINE, "----"], [false, false]], lex("\r\n----"))
312
+ assert_equal([[:PARA_START, ""], [:TEXT, "text\n"], [:PARA_END, ""], [:HLINE, "----"], [false, false]],
313
+ lex("text\n----"))
314
+ assert_equal([[:PARA_START, ""], [:TEXT, "text\r\n"], [:PARA_END, ""], [:HLINE, "----"], [false, false]],
315
+ lex("text\r\n----"))
316
+ assert_equal([[:PARA_START, ""], [:TEXT, "text\n\n"], [:PARA_END, ""], [:HLINE, "----"], [false, false]],
317
+ lex("text\n\n----"))
318
+ assert_equal([[:HLINE, "----"], [:PARA_START, ""], [:TEXT, "\ntext"], [:PARA_END, ""], [false, false]],
319
+ lex("----\ntext"))
320
+ assert_equal([[:HLINE, "----"], [:PARA_START, ""], [:TEXT, "\r\ntext"], [:PARA_END, ""], [false, false]],
321
+ lex("----\r\ntext"))
322
+ assert_equal([[:HLINE, "----"], [:PARA_START, ""], [:TEXT, "\n\n"], [:PARA_END, ""], [:PARA_START, ""],
323
+ [:TEXT, "text"], [:PARA_END, ""], [false, false]],
324
+ lex("----\n\ntext"))
325
+ end
326
+
327
+ def test_nowiki
328
+ assert_equal([[:PARA_START, ""], [:TEXT, "''italic''"], [:PARA_END, ""], [false, false]],
329
+ lex("<nowiki>''italic''</nowiki>"))
330
+ assert_equal([[:PARA_START, ""], [:TEXT, "text''italic''text"], [:PARA_END, ""], [false, false]],
331
+ lex("text<nowiki>''italic''</nowiki>text"))
332
+ assert_equal([[:PARA_START, ""], [:TEXT, "<u>uuu</u>"], [:PARA_END, ""], [false, false]],
333
+ lex("<nowiki><u>uuu</u></nowiki>"))
334
+ end
335
+
336
+ def test_variable
337
+ assert_equal([[:PARA_START, ""], [:VARIABLE_START, "{{"], [:TEXT, "ref"], [:VARIABLE_END, "}}"],
338
+ [:PARA_END, ""], [false, false]],
339
+ lex("{{ref}}"))
340
+ assert_equal([[:PARA_START, ""], [:VARIABLE_START, "{{"], [:TEXT, "ref1}ref2"], [:VARIABLE_END, "}}"],
341
+ [:PARA_END, ""], [false, false]],
342
+ lex("{{ref1}ref2}}"))
343
+ assert_equal([[:PARA_START, ""], [:VARIABLE_START, "{{"], [:TEXT, "ref1\n{|\n|not a table!\n|} "],
344
+ [:VARIABLE_END, "}}"], [:PARA_END, ""], [false, false]],
345
+ lex("{{ref1\n{|\n|not a table!\n|} }}"))
346
+ assert_equal([[:PARA_START, ""], [:TEXT, "{{}}"], [:PARA_END, ""], [false, false]],
347
+ lex("{{}}"))
348
+ end
349
+
350
+ def test_xhtml_markup
351
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:TEXT, "text"], [:TAG_END, "tt"],
352
+ [:PARA_END, ""], [false, false]],
353
+ lex("<tt>text</tt>"))
354
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:TAG_END, "tt"], [:PARA_END, ""], [false, false]],
355
+ lex("<tt/>"))
356
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:TAG_END, "tt"], [:PARA_END, ""], [false, false]],
357
+ lex("<tt />"))
358
+ assert_equal([[:PARA_START, ""], [:TEXT, "<123>"], [:PARA_END, ""], [false, false]],
359
+ lex("<123>"))
360
+ assert_equal([[:PARA_START, ""], [:TEXT, "<xx xx>"], [:PARA_END, ""], [false, false]],
361
+ lex("<xx xx>"))
362
+ assert_equal([[:PARA_START, ""], [:TEXT, "</xxx "], [:PARA_END, ""], [false, false]],
363
+ lex("</xxx "))
364
+ assert_equal([[:PARA_START, ""], [:TEXT, "<xx </xx>"], [:PARA_END, ""], [false, false]],
365
+ lex("<xx </xx>"))
366
+ assert_equal([[:PARA_START, ""], [:TEXT, "<xx a='b' c>"], [:PARA_END, ""], [false, false]],
367
+ lex("<xx a='b' c>"))
368
+ assert_equal([[:PARA_START, ""], [:TEXT, "<>"], [:PARA_END, ""], [false, false]],
369
+ lex("<>"))
370
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:ATTR_NAME, 'class'], [:ATTR_VALUE, 'tt'],
371
+ [:TEXT, "text"], [:TAG_END, "tt"], [:PARA_END, ""], [false, false]],
372
+ lex("<tt class='tt'>text</tt>"))
373
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:ATTR_NAME, 'class'], [:ATTR_VALUE, 'tt'],
374
+ [:TEXT, "text"], [:TAG_END, "tt"], [:PARA_END, ""], [false, false]],
375
+ lex("<tt class = 'tt' >text</tt >"))
376
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:ATTR_NAME, 'class'], [:ATTR_VALUE, 'tt'],
377
+ [:TEXT, "text"], [:TAG_END, "tt"], [:PARA_END, ""], [false, false]],
378
+ lex("<tt\nclass\n=\n'tt'\n>text</tt\n>"))
379
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:ATTR_NAME, 'class'], [:ATTR_VALUE, 'tt'],
380
+ [:TAG_END, "tt"], [:PARA_END, ""], [false, false]],
381
+ lex("<tt class='tt' />"))
382
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:TEXT, "\ntext\n"], [:TAG_END, "tt"],
383
+ [:PARA_END, ""], [false, false]],
384
+ lex("<tt>\ntext\n</tt>"))
385
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:TEXT, "\n\ntext\n"], [:TAG_END, "tt"],
386
+ [:PARA_END, ""], [false, false]],
387
+ lex("<tt>\n\ntext\n</tt>"))
388
+ assert_equal([[:PARA_START, ""], [:TAG_START, "tt"], [:TEXT, "<tt/>"], [:TAG_END, "tt"],
389
+ [:PARA_END, ""], [false, false]],
390
+ lex("<tt><nowiki><tt/></nowiki></tt>"))
391
+ assert_equal([[:PARA_START, ""], [:LINK_START, "["], [:TEXT, "http://example.com"], [:LINKSEP, " "],
392
+ [:TAG_START, "tt"], [:TEXT, "text"], [:TAG_END, "tt"], [:LINK_END, "]"], [:PARA_END, ""], [false, false]],
393
+ lex("[http://example.com <tt>text</tt>]"))
394
+ assert_equal([[:PARA_START, ""], [:INTLINK_START, "[["], [:TEXT, "page"], [:INTLINKSEP, "|"],
395
+ [:TAG_START, "tt"], [:TEXT, "text"], [:TAG_END, "tt"], [:INTLINK_END, "]]"], [:PARA_END, ""], [false, false]],
396
+ lex("[[page|<tt>text</tt>]]"))
397
+ end
398
+
399
+ def test_xhtml_char_entities
400
+ assert_equal([[:PARA_START, ""], [:CHAR_ENT, "lt"], [:PARA_END, ""], [false, false]],
401
+ lex("&lt;"))
402
+ assert_equal([[:PARA_START, ""], [:CHAR_ENT, "amp"], [:TEXT, "amp;"], [:PARA_END, ""], [false, false]],
403
+ lex("&amp;amp;"))
404
+ assert_equal([[:PARA_START, ""], [:TEXT, "&"], [:PARA_END, ""], [false, false]],
405
+ lex("&"))
406
+ assert_equal([[:PARA_START, ""], [:TEXT, "&amp"], [:PARA_END, ""], [false, false]],
407
+ lex("&amp"))
408
+ assert_equal([[:PARA_START, ""], [:TEXT, "&amp ;"], [:PARA_END, ""], [false, false]],
409
+ lex("&amp ;"))
410
+ assert_equal([[:PARA_START, ""], [:TEXT, "&amp amp;"], [:PARA_END, ""], [false, false]],
411
+ lex("&amp amp;"))
412
+ assert_equal([[:PARA_START, ""], [:TEXT, "&amp"], [:CHAR_ENT, "amp"], [:PARA_END, ""], [false, false]],
413
+ lex("&amp&amp;"))
414
+ end
415
+
416
+ def test_unordered_lists
417
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:TEXT, "a"], [:LI_END, ''], [:UL_END, ''],
418
+ [false, false]],
419
+ lex("*a"))
420
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:TEXT, "a\n"], [:LI_END, ''], [:UL_END, ''],
421
+ [false, false]],
422
+ lex("*a\n"))
423
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:TEXT, "a"], [:LI_END, ''], [:UL_END, ''],
424
+ [false, false]],
425
+ lex("\n*a"))
426
+ assert_equal([[:PARA_START, ""], [:TEXT, "text\n"], [:PARA_END, ""], [:UL_START, ''],
427
+ [:LI_START, ''], [:TEXT, "a"], [:LI_END, ''], [:UL_END, ''], [false, false]],
428
+ lex("text\n*a"))
429
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:TEXT, "a\n"], [:LI_END, ''],
430
+ [:LI_START, ''], [:TEXT, "b\n"], [:LI_END, ''], [:UL_END, ''], [false, false]],
431
+ lex("*a\n*b\n"))
432
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:TEXT, "a\n"],
433
+ [:UL_START, ''], [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:UL_END, ''], [:LI_END, ''],
434
+ [:LI_START, ''], [:TEXT, "b\n"], [:LI_END, ''], [:UL_END, ''], [false, false]],
435
+ lex("*a\n**i\n*b\n"))
436
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:TEXT, "a\n"],
437
+ [:UL_START, ''], [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:UL_END, ''], [:LI_END, ''],
438
+ [:UL_END, ''], [false, false]],
439
+ lex("*a\n**i\n"))
440
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:UL_START, ''],
441
+ [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:UL_END, ''], [:LI_END, ''],
442
+ [:UL_END, ''], [false, false]],
443
+ lex("**i\n"))
444
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:UL_START, ''],
445
+ [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:UL_END, ''], [:LI_END, ''],
446
+ [:LI_START, ''], [:TEXT, "b\n"], [:LI_END, ''], [:UL_END, ''], [false, false]],
447
+ lex("**i\n*b\n"))
448
+ end
449
+
450
+ def test_ordered_lists
451
+ assert_equal([[:OL_START, ''], [:LI_START, ''], [:TEXT, "a"], [:LI_END, ''], [:OL_END, ''],
452
+ [false, false]],
453
+ lex("#a"))
454
+ assert_equal([[:OL_START, ''], [:LI_START, ''], [:TEXT, "a\n"], [:LI_END, ''], [:OL_END, ''],
455
+ [false, false]],
456
+ lex("#a\n"))
457
+ assert_equal([[:OL_START, ''], [:LI_START, ''], [:TEXT, "a"], [:LI_END, ''], [:OL_END, ''],
458
+ [false, false]],
459
+ lex("\n#a"))
460
+ assert_equal([[:PARA_START, ""], [:TEXT, "text\n"], [:PARA_END, ""], [:OL_START, ''],
461
+ [:LI_START, ''], [:TEXT, "a"], [:LI_END, ''], [:OL_END, ''], [false, false]],
462
+ lex("text\n#a"))
463
+ assert_equal([[:OL_START, ''], [:LI_START, ''], [:TEXT, "a\n"], [:LI_END, ''],
464
+ [:LI_START, ''], [:TEXT, "b\n"], [:LI_END, ''], [:OL_END, ''], [false, false]],
465
+ lex("#a\n#b\n"))
466
+ assert_equal([[:OL_START, ''], [:LI_START, ''], [:TEXT, "a\n"],
467
+ [:OL_START, ''], [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:OL_END, ''], [:LI_END, ''],
468
+ [:LI_START, ''], [:TEXT, "b\n"], [:LI_END, ''], [:OL_END, ''], [false, false]],
469
+ lex("#a\n##i\n#b\n"))
470
+ assert_equal([[:OL_START, ''], [:LI_START, ''], [:TEXT, "a\n"],
471
+ [:OL_START, ''], [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:OL_END, ''], [:LI_END, ''],
472
+ [:OL_END, ''], [false, false]],
473
+ lex("#a\n##i\n"))
474
+ assert_equal([[:OL_START, ''], [:LI_START, ''], [:OL_START, ''],
475
+ [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:OL_END, ''], [:LI_END, ''],
476
+ [:OL_END, ''], [false, false]],
477
+ lex("##i\n"))
478
+ assert_equal([[:OL_START, ''], [:LI_START, ''], [:OL_START, ''],
479
+ [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:OL_END, ''], [:LI_END, ''],
480
+ [:LI_START, ''], [:TEXT, "b\n"], [:LI_END, ''], [:OL_END, ''], [false, false]],
481
+ lex("##i\n#b\n"))
482
+ end
483
+
484
+ def test_mixed_lists
485
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:TEXT, "a\n"], [:LI_END, ''], [:UL_END, ''],
486
+ [:OL_START, ''], [:LI_START, ''], [:TEXT, "b\n"], [:LI_END, ''], [:OL_END, ''], [false, false]],
487
+ lex("*a\n#b\n"))
488
+ assert_equal([[:OL_START, ''], [:LI_START, ''], [:TEXT, "a\n"],
489
+ [:UL_START, ''], [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:UL_END, ''], [:LI_END, ''],
490
+ [:LI_START, ''], [:TEXT, "b\n"], [:LI_END, ''], [:OL_END, ''], [false, false]],
491
+ lex("#a\n#*i\n#b\n"))
492
+ assert_equal([[:UL_START, ''], [:LI_START, ''], [:TEXT, "a\n"],
493
+ [:OL_START, ''], [:LI_START, ''], [:TEXT, "i\n"], [:LI_END, ''], [:OL_END, ''], [:LI_END, ''],
494
+ [:LI_START, ''], [:TEXT, "b\n"], [:LI_END, ''], [:UL_END, ''], [false, false]],
495
+ lex("*a\n*#i\n*b\n"))
496
+ end
497
+
498
+ def test_definition_lists
499
+ assert_equal([[:DL_START, ''], [:DT_START, ';'], [:TEXT, "a"], [:DT_END, ''], [:DL_END, ''],
500
+ [false, false]],
501
+ lex(";a"))
502
+ assert_equal([[:DL_START, ''], [:DT_START, ';'], [:TEXT, "a\n"], [:DT_END, ''], [:DL_END, ''],
503
+ [false, false]],
504
+ lex(";a\n"))
505
+ assert_equal([[:DL_START, ''], [:DD_START, ':'], [:TEXT, "b"], [:DD_END, ''], [:DL_END, ''],
506
+ [false, false]],
507
+ lex(":b"))
508
+ assert_equal([[:DL_START, ''], [:DD_START, ':'], [:TEXT, "b\n"], [:DD_END, ''], [:DL_END, ''],
509
+ [false, false]],
510
+ lex(":b\n"))
511
+ assert_equal([[:DL_START, ''], [:DT_START, ';'], [:TEXT, "a\n"], [:DT_END, ''],
512
+ [:DD_START, ':'], [:TEXT, "b\n"], [:DD_END, ''], [:DL_END, ''], [false, false]],
513
+ lex(";a\n:b\n"))
514
+ assert_equal([[:DL_START, ''], [:DT_START, ';'], [:TEXT, "a"], [:DT_END, ''],
515
+ [:DD_START, ':'], [:TEXT, "b\n"], [:DD_END, ''], [:DL_END, ''], [false, false]],
516
+ lex(";a:b\n"))
517
+ assert_equal([[:DL_START, ''], [:DT_START, ';'], [:TEXT, "a\n"], [:DT_END, ''],
518
+ [:DD_START, ':'], [:TEXT, "b\n"], [:DD_END, ''], [:DD_START, ':'], [:TEXT, "c\n"],
519
+ [:DD_END, ''],[:DL_END, ''], [false, false]],
520
+ lex(";a\n:b\n:c\n"))
521
+ assert_equal([[:DL_START, ''], [:DT_START, ';'], [:TEXT, "a\n"], [:DT_END, ''], [:DL_END, ''],
522
+ [:DL_START, ''], [:DT_START, ';'], [:TEXT, "a\n"], [:DT_END, ''], [:DL_END, ''],
523
+ [false, false]],
524
+ lex(";a\n;a\n"))
525
+ assert_equal([[:DL_START, ''], [:DT_START, ';'], [:TEXT, "a\n"], [:DT_END, ''], [:DL_END, ''],
526
+ [:PARA_START, ''], [:TEXT, 'text'], [:PARA_END, ''], [false, false]],
527
+ lex(";a\ntext"))
528
+ assert_equal([[:DL_START, ''], [:DT_START, ';'], [:TEXT, "a"], [:DT_END, ''],
529
+ [:DD_START, ':'], [:INTLINK_START, '[['], [:TEXT, "resource"], [:RESOURCESEP, ':'],
530
+ [:TEXT, 'text'], [:INTLINK_END, ']]'], [:DD_END, ''], [:DL_END, ''], [false, false]],
531
+ lex(";a:[[resource:text]]\n"))
532
+ end
533
+
534
+
535
+ private
536
+
537
+ def lex(string)
538
+ lexer = MediaWikiLexer.new
539
+ lexer.tokenize(string)
540
+ end
541
+
542
+ end