pseudohikiparser 0.0.0.11.develop → 0.0.0.12.develop

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -246,4 +246,23 @@ TEXT
246
246
  tree = BlockParser.parse(mal_formed_text.lines.to_a)
247
247
  assert_equal(expected_mal_formed_text, @verbose_formatter.format(tree).to_s)
248
248
  end
249
+
250
+ def test_self_format
251
+ text = <<TEXT
252
+ A test string ==with deleted words ==is here.
253
+ TEXT
254
+ expected_text = <<TEXT
255
+ A test string is here.
256
+
257
+ TEXT
258
+
259
+ expected_text_in_verbose_mode = <<TEXT
260
+ A test string [deleted:with deleted words ]is here.
261
+
262
+ TEXT
263
+ tree = BlockParser.parse(text.lines.to_a)
264
+ assert_equal(expected_text, PlainTextFormat.format(tree, { :verbose_mode => false }).to_s)
265
+ assert_equal(expected_text_in_verbose_mode, PlainTextFormat.format(tree, { :verbose_mode => true }).to_s)
266
+ assert_equal(expected_text, PlainTextFormat.format(tree, { :verbose_mode => false }).to_s)
267
+ end
249
268
  end
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'stringio'
4
+ require 'shellwords'
5
+ require 'minitest/autorun'
6
+ require 'pseudohiki/converter'
7
+
8
+ def set_argv(command_line_str)
9
+ ARGV.replace Shellwords.split(command_line_str)
10
+ end
11
+
12
+ class TC_OptionManager < MiniTest::Unit::TestCase
13
+ include PseudoHiki
14
+
15
+ def test_set_options_from_command_line
16
+ set_argv("-fx -s -m 'Table of Contents' -c css/with_toc.css wikipage.txt -o wikipage_with_toc.html")
17
+
18
+ options = OptionManager.new
19
+ options.set_options_from_command_line
20
+
21
+ assert_equal("xhtml1", options[:html_version].version)
22
+ assert_equal(true, options[:split_main_heading])
23
+ assert_equal("Table of Contents", options[:toc])
24
+ assert_equal(nil, options[:title])
25
+ assert_equal("css/with_toc.css", options[:css])
26
+ assert_equal("wikipage_with_toc.html", File.basename(options[:output]))
27
+ end
28
+
29
+ def test_set_options_from_command_line2
30
+ set_argv("-f h -m 'Table of Contents' -w 'Title' -c css/with_toc.css wikipage.txt")
31
+
32
+ options = OptionManager.new
33
+ options.set_options_from_command_line
34
+
35
+ assert_equal("html4", options[:html_version].version)
36
+ assert_equal(false, options[:split_main_heading])
37
+ assert_equal("Table of Contents", options[:toc])
38
+ assert_equal("Title", options[:title])
39
+ assert_equal("css/with_toc.css", options[:css])
40
+ assert_equal(nil, options[:output])
41
+ end
42
+
43
+ def test_set_options_from_input_file
44
+ input_data = <<LINES
45
+ //title: Title set in the input file
46
+ //toc: Table of Contents set in the input file
47
+
48
+ paragraph
49
+ LINES
50
+ set_argv("-f h -m 'Table of Contents' -w 'Title' -c css/with_toc.css wikipage.txt")
51
+
52
+ options = OptionManager.new
53
+ options.set_options_from_command_line
54
+ options.set_options_from_input_file(input_data.each_line.to_a)
55
+
56
+ assert_equal("Table of Contents set in the input file", options[:toc])
57
+ assert_equal("Title set in the input file", options[:title])
58
+ end
59
+
60
+ def test_set_options_from_input_file_overwritten_by_command_line_options
61
+ input_data = <<LINES
62
+ //title: Title set in the input file
63
+ //toc: Table of Contents set in the input file
64
+
65
+ paragraph
66
+ LINES
67
+ set_argv("-F -f h -m 'Table of Contents' -w 'Title' -c css/with_toc.css wikipage.txt")
68
+
69
+ options = OptionManager.new
70
+ options.set_options_from_command_line
71
+ options.set_options_from_input_file(input_data.each_line.to_a)
72
+
73
+ assert_equal("Table of Contents", options[:toc])
74
+ assert_equal("Title", options[:title])
75
+ end
76
+
77
+ def test_set_options_from_input_file_overwritten_by_command_line_options2
78
+ input_data = <<LINES
79
+ //title: Title set in the input file
80
+ //toc: Table of Contents set in the input file
81
+
82
+ paragraph
83
+ LINES
84
+ set_argv("-F -f h -m 'Table of Contents' -c css/with_toc.css wikipage.txt")
85
+
86
+ options = OptionManager.new
87
+ options.set_options_from_command_line
88
+ options.set_options_from_input_file(input_data.each_line.to_a)
89
+
90
+ assert_equal("Table of Contents", options[:toc])
91
+ assert_equal("Title set in the input file", options[:title])
92
+ end
93
+
94
+ def test_option_not_in_command_line_nor_in_input_file
95
+ input_data = <<LINES
96
+ //toc: Table of Contents set in the input file
97
+
98
+ paragraph
99
+ LINES
100
+ set_argv("-F -f h -m 'Table of Contents' -c css/with_toc.css wikipage.txt")
101
+
102
+ options = OptionManager.new
103
+ options.set_options_from_command_line
104
+ options.set_options_from_input_file(input_data.each_line.to_a)
105
+
106
+ assert_equal("Table of Contents", options[:toc])
107
+ assert_equal(nil, options[:title])
108
+ end
109
+ end
110
+
111
+ class TC_PageComposer < MiniTest::Unit::TestCase
112
+ include PseudoHiki
113
+
114
+ def test_output_in_gfm_with_toc
115
+ input = <<TEXT.each_line.to_a
116
+ //title: Test Data
117
+ //toc: Table of Contents
118
+
119
+ !Test Data
120
+
121
+ !![first]The first heading
122
+
123
+ Paragraph
124
+
125
+ !![second]The second heading
126
+
127
+ Paragraph
128
+ TEXT
129
+
130
+ output = <<GFM
131
+ # Test Data
132
+
133
+
134
+ ## Table of Contents
135
+
136
+ * The first heading
137
+ * The second heading
138
+
139
+ ## The first heading
140
+
141
+ Paragraph
142
+
143
+ ## The second heading
144
+
145
+ Paragraph
146
+
147
+ GFM
148
+
149
+ set_argv("-fg -s -c css/with_toc.css wikipage.txt")
150
+
151
+ options = OptionManager.new
152
+ options.set_options_from_command_line
153
+ options.set_options_from_input_file(input)
154
+
155
+ html = PageComposer.new(options).compose_html(input).join
156
+
157
+ assert_equal(output, html)
158
+ end
159
+ end
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env ruby
2
+ require 'minitest/autorun'
3
+ require 'pseudohikiparser'
4
+
5
+ class TC_MarkDownFormat < MiniTest::Unit::TestCase
6
+ include PseudoHiki
7
+
8
+ def setup
9
+ @text =<<TEXT
10
+ !! heading
11
+
12
+ ||!head 1||!head 2
13
+ ||cell 1||cell 2
14
+
15
+ the first paragraph with ''inline'' ``tags``
16
+
17
+ the second paragraph with ==block== [[inline|#id]] tags
18
+ TEXT
19
+ end
20
+
21
+ def test_to_html
22
+ expected = <<HTML
23
+ <div class="section h2">
24
+ <h2> heading
25
+ </h2>
26
+ <table>
27
+ <tr><th>head 1</th><th>head 2
28
+ </th></tr>
29
+ <tr><td>cell 1</td><td>cell 2
30
+ </td></tr>
31
+ </table>
32
+ <p>
33
+ the first paragraph with <em>inline</em> <code>tags</code>
34
+ </p>
35
+ <p>
36
+ the second paragraph with <del>block</del> <a href="#id">inline</a> tags
37
+ </p>
38
+ <!-- end of section h2 -->
39
+ </div>
40
+ HTML
41
+ assert_equal(expected, Format.to_html(@text))
42
+ end
43
+
44
+ def test_to_markdown
45
+ expected = <<MD
46
+ ## heading
47
+
48
+ <table>
49
+ <tr><th>head 1</th><th>head 2</th></tr>
50
+ <tr><td>cell 1</td><td>cell 2</td></tr>
51
+ </table>
52
+
53
+ the first paragraph with _inline_ `tags`
54
+
55
+ the second paragraph with ~~block~~ [inline](#id) tags
56
+
57
+ MD
58
+
59
+ assert_equal(expected, Format.to_markdown(@text))
60
+ end
61
+
62
+ def test_to_gfm
63
+ expected = <<MD
64
+ ## heading
65
+
66
+ |head 1|head 2|
67
+ |------|------|
68
+ |cell 1|cell 2|
69
+
70
+ the first paragraph with _inline_ `tags`
71
+
72
+ the second paragraph with ~~block~~ [inline](#id) tags
73
+
74
+ MD
75
+
76
+ assert_equal(expected, Format.to_gfm(@text))
77
+ end
78
+
79
+ def test_format
80
+ md_expected = <<MD
81
+ ## heading
82
+
83
+ <table>
84
+ <tr><th>head 1</th><th>head 2</th></tr>
85
+ <tr><td>cell 1</td><td>cell 2</td></tr>
86
+ </table>
87
+
88
+ the first paragraph with _inline_ `tags`
89
+
90
+ the second paragraph with ~~block~~ [inline](#id) tags
91
+
92
+ MD
93
+
94
+ table_text = <<TEXT
95
+ ||!head 1||!head 2||!head 3
96
+ ||> cell 1-2||cell 3
97
+ TEXT
98
+
99
+ html_expected = <<HTML
100
+ <table>
101
+ <tr><th>head 1</th><th>head 2</th><th>head 3</th></tr>
102
+ <tr><td colspan="2"> cell 1-2</td><td>cell 3</td></tr>
103
+ </table>
104
+
105
+ HTML
106
+
107
+ gfm_expected = <<MD
108
+ |head 1 |head 2|head 3|
109
+ |--------|------|------|
110
+ |cell 1-2| |cell 3|
111
+
112
+ MD
113
+
114
+ assert_equal(md_expected, Format.format(@text, :markdown))
115
+ assert_equal(html_expected, Format.format(table_text, :markdown, :gfm_style => true))
116
+ assert_equal(gfm_expected, Format.format(table_text, :markdown, :gfm_style => :force))
117
+ end
118
+
119
+ def test_format_with_block
120
+ hiki_table = <<TEXT
121
+ ||!head 1||!head 2
122
+ ||cell 1||cell 2
123
+ TEXT
124
+
125
+ expected_html_table = <<HTML
126
+ <table id="table">
127
+ <tr><th>head 1</th><th>head 2
128
+ </th></tr>
129
+ <tr><td>cell 1</td><td>cell 2
130
+ </td></tr>
131
+ </table>
132
+ HTML
133
+
134
+ table_with_id = Format.to_html(hiki_table) do |html|
135
+ html.traverse do |elm|
136
+ elm["id"] = "table" if elm.kind_of? HtmlElement and elm.tagname == "table"
137
+ end
138
+ end
139
+
140
+ assert_equal(expected_html_table, table_with_id)
141
+ end
142
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudohikiparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.11.develop
4
+ version: 0.0.0.12.develop
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,11 +67,13 @@ files:
67
67
  - lib/htmlelement.rb
68
68
  - lib/htmlelement/htmltemplate.rb
69
69
  - lib/pseudohiki/blockparser.rb
70
+ - lib/pseudohiki/converter.rb
70
71
  - lib/pseudohiki/htmlformat.rb
71
72
  - lib/pseudohiki/htmlplugin.rb
72
73
  - lib/pseudohiki/inlineparser.rb
73
74
  - lib/pseudohiki/markdownformat.rb
74
75
  - lib/pseudohiki/plaintextformat.rb
76
+ - lib/pseudohiki/sinatra_helpers.rb
75
77
  - lib/pseudohiki/treestack.rb
76
78
  - lib/pseudohiki/version.rb
77
79
  - lib/pseudohikiparser.rb
@@ -83,6 +85,8 @@ files:
83
85
  - test/test_inlineparser.rb
84
86
  - test/test_markdownformat.rb
85
87
  - test/test_plaintextformat.rb
88
+ - test/test_pseudohiki2html.rb
89
+ - test/test_pseudohikiparser.rb
86
90
  - test/test_treestack.rb
87
91
  homepage: https://github.com/nico-hn/PseudoHikiParser/wiki
88
92
  licenses:
@@ -110,7 +114,9 @@ specification_version: 4
110
114
  summary: 'PseudoHikiParser: a parser of texts in a Hiki like notation.'
111
115
  test_files:
112
116
  - test/test_htmltemplate.rb
117
+ - test/test_pseudohikiparser.rb
113
118
  - test/test_blockparser.rb
119
+ - test/test_pseudohiki2html.rb
114
120
  - test/test_plaintextformat.rb
115
121
  - test/test_htmlelement.rb
116
122
  - test/test_treestack.rb