bitclust-core 1.7.0 → 1.9.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/data/bitclust/template/class-index +0 -1
  3. data/data/bitclust/template.epub/class +5 -5
  4. data/data/bitclust/template.epub/class-index +0 -1
  5. data/data/bitclust/template.epub/contents +7 -4
  6. data/data/bitclust/template.epub/layout +4 -4
  7. data/data/bitclust/template.offline/class-index +0 -1
  8. data/lib/bitclust/generators/epub.rb +69 -5
  9. data/lib/bitclust/irb.rb +14 -8
  10. data/lib/bitclust/markdown_bridge.rb +11 -6
  11. data/lib/bitclust/markdown_tree.rb +128 -11
  12. data/lib/bitclust/methoddatabase.rb +15 -4
  13. data/lib/bitclust/nameutils.rb +13 -0
  14. data/lib/bitclust/preprocessor.rb +0 -36
  15. data/lib/bitclust/remote.rb +405 -0
  16. data/lib/bitclust/runner.rb +5 -10
  17. data/lib/bitclust/screen.rb +2 -1
  18. data/lib/bitclust/searcher.rb +43 -24
  19. data/lib/bitclust/subcommands/chm_command.rb +1 -1
  20. data/lib/bitclust/subcommands/epub_command.rb +2 -2
  21. data/lib/bitclust/subcommands/extract_command.rb +7 -0
  22. data/lib/bitclust/subcommands/htmlfile_command.rb +73 -1
  23. data/lib/bitclust/subcommands/methods_command.rb +5 -28
  24. data/lib/bitclust/subcommands/query_command.rb +1 -0
  25. data/lib/bitclust/subcommands/server_command.rb +21 -10
  26. data/lib/bitclust/subcommands/setup_command.rb +28 -10
  27. data/lib/bitclust/syntax_highlighter.rb +65 -4
  28. data/lib/bitclust/user_dirs.rb +62 -0
  29. data/lib/bitclust/version.rb +1 -1
  30. data/test/test_chm_command.rb +22 -0
  31. data/test/test_epub_command.rb +60 -0
  32. data/test/test_epub_generator.rb +330 -0
  33. data/test/test_extract_command.rb +34 -0
  34. data/test/test_htmlfile_command.rb +211 -0
  35. data/test/test_irb_plugin.rb +100 -6
  36. data/test/test_markdown_bridge.rb +35 -0
  37. data/test/test_markdown_tree.rb +144 -0
  38. data/test/test_mdparser.rb +39 -0
  39. data/test/test_methods_command.rb +32 -0
  40. data/test/test_opensearchdescription_screen.rb +39 -0
  41. data/test/test_query_command.rb +30 -0
  42. data/test/test_remote.rb +374 -0
  43. data/test/test_runner.rb +61 -1
  44. data/test/test_searcher.rb +63 -0
  45. data/test/test_server_command.rb +41 -0
  46. data/test/test_setup_command.rb +143 -0
  47. data/test/test_syntax_highlighter.rb +124 -0
  48. data/test/test_user_dirs.rb +62 -0
  49. metadata +39 -2
  50. data/lib/bitclust/ridatabase.rb +0 -359
@@ -0,0 +1,330 @@
1
+ # frozen_string_literal: true
2
+ require 'test/unit'
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+ require 'rexml/document'
6
+ require 'bitclust'
7
+ require 'bitclust/generators/epub'
8
+ require 'bitclust/screen'
9
+ require 'bitclust/subcommands/statichtml_command'
10
+
11
+ # contents.opf のマニフェストは、statichtml が OEBPS 以下に生成する
12
+ # class/method/library/doc/function ページと css/image リソースを
13
+ # すべて(ユニークな id で)列挙しなければならない(EPUB の仕様上必須)。
14
+ class TestEpubGeneratorContentsOpf < Test::Unit::TestCase
15
+ def build_epub_generator
16
+ datadir = File.expand_path('../data/bitclust', __dir__)
17
+ BitClust::Generators::EPUB.new(:templatedir => Pathname.new("#{datadir}/template.epub"))
18
+ end
19
+
20
+ def setup
21
+ @dir = Dir.mktmpdir
22
+ @epub_directory = Pathname.new(@dir)
23
+ @oebps = @epub_directory + "OEBPS"
24
+ FileUtils.mkdir_p(@oebps + "class")
25
+ FileUtils.mkdir_p(@oebps + "method/-array/i")
26
+ FileUtils.mkdir_p(@oebps + "doc")
27
+ FileUtils.mkdir_p(@oebps + "library")
28
+ FileUtils.mkdir_p(@oebps + "function")
29
+ FileUtils.mkdir_p(@oebps + "images")
30
+
31
+ File.write(@oebps + "class/-array.xhtml", "<html/>")
32
+ File.write(@oebps + "class/index.xhtml", "<html/>") # クラス一覧ページ
33
+ File.write(@oebps + "method/-array/i/each.xhtml", "<html/>")
34
+ File.write(@oebps + "doc/index.xhtml", "<html/>") # マニュアルのトップページ
35
+ File.write(@oebps + "doc/help.xhtml", "<html/>")
36
+ File.write(@oebps + "library/index.xhtml", "<html/>")
37
+ File.write(@oebps + "library/json.xhtml", "<html/>")
38
+ File.write(@oebps + "function/index.xhtml", "<html/>")
39
+ File.write(@oebps + "function/rb_ary_new.xhtml", "<html/>")
40
+ File.write(@oebps + "style.css", "body{}")
41
+ File.write(@oebps + "images/rurema.png", "\x89PNG\r\n")
42
+ File.write(@epub_directory + "nav.xhtml", "<html/>")
43
+
44
+ @generator = build_epub_generator
45
+ @generator.send(:generate_contents_opf, @epub_directory)
46
+ @opf_path = @epub_directory + "contents.opf"
47
+ @xml = File.read(@opf_path)
48
+ @doc = REXML::Document.new(@xml)
49
+ end
50
+
51
+ def teardown
52
+ FileUtils.rm_rf(@dir)
53
+ end
54
+
55
+ def items
56
+ REXML::XPath.match(@doc, "//manifest/item")
57
+ end
58
+
59
+ def test_contents_opf_is_well_formed_xml
60
+ assert_nothing_raised { REXML::Document.new(@xml) }
61
+ end
62
+
63
+ def test_manifest_lists_every_xhtml_page_under_oebps
64
+ hrefs = items.map {|item| item.attributes['href'] }
65
+ %w[
66
+ OEBPS/class/-array.xhtml
67
+ OEBPS/class/index.xhtml
68
+ OEBPS/method/-array/i/each.xhtml
69
+ OEBPS/doc/index.xhtml
70
+ OEBPS/doc/help.xhtml
71
+ OEBPS/library/index.xhtml
72
+ OEBPS/library/json.xhtml
73
+ OEBPS/function/index.xhtml
74
+ OEBPS/function/rb_ary_new.xhtml
75
+ nav.xhtml
76
+ ].each do |href|
77
+ assert_include(hrefs, href)
78
+ end
79
+ end
80
+
81
+ def test_manifest_lists_non_xhtml_resources_that_exist
82
+ hrefs = items.map {|item| item.attributes['href'] }
83
+ assert_include(hrefs, "OEBPS/style.css")
84
+ assert_include(hrefs, "OEBPS/images/rurema.png")
85
+ style_item = items.find {|item| item.attributes['href'] == "OEBPS/style.css" }
86
+ assert_equal("text/css", style_item.attributes['media-type'])
87
+ image_item = items.find {|item| item.attributes['href'] == "OEBPS/images/rurema.png" }
88
+ assert_equal("image/png", image_item.attributes['media-type'])
89
+ end
90
+
91
+ def test_manifest_item_ids_are_unique
92
+ ids = items.map {|item| item.attributes['id'] }
93
+ assert_equal(ids.size, ids.uniq.size, "duplicate manifest item ids: #{ids}")
94
+ end
95
+
96
+ def test_manifest_item_ids_are_valid_xml_ncnames
97
+ ids = items.map {|item| item.attributes['id'] }
98
+ assert_false(ids.empty?)
99
+ ids.each do |id|
100
+ assert_match(/\A[A-Za-z_][A-Za-z0-9_.-]*\z/, id, "not a valid NCName: #{id.inspect}")
101
+ end
102
+ end
103
+
104
+ # doc/index.xhtml はマニフェスト中に決め打ちの id="index" として
105
+ # 一度だけ登場し、doc 以下を走査する側から重複登録されない。
106
+ def test_doc_index_is_listed_exactly_once_with_the_index_id
107
+ index_items = items.select {|item| item.attributes['href'] == "OEBPS/doc/index.xhtml" }
108
+ assert_equal(1, index_items.size)
109
+ assert_equal("index", index_items.first.attributes['id'])
110
+ end
111
+
112
+ def test_manifest_references_xhtml_not_html_for_the_index
113
+ hrefs = items.map {|item| item.attributes['href'] }
114
+ assert_not_include(hrefs, "OEBPS/doc/index.html")
115
+ end
116
+
117
+ # 目次ページ (nav) ・マニュアルのトップページ・クラスページだけが
118
+ # spine(読み進める順序)に載る。約 11,700 あるメソッドページなどを
119
+ # spine に加えると読書順序が壊れるので、マニフェストには載るが spine
120
+ # には載らない。
121
+ def test_spine_still_excludes_method_library_doc_and_function_pages
122
+ spine_idrefs = REXML::XPath.match(@doc, "//spine/itemref").map {|el| el.attributes['idref'] }
123
+ assert_equal(%w[toc index], spine_idrefs.first(2))
124
+
125
+ class_item_ids = items.select {|item| item.attributes['href'].to_s.start_with?('OEBPS/class/') }
126
+ .map {|item| item.attributes['id'] }
127
+ assert_equal(%w[toc index] + class_item_ids, spine_idrefs)
128
+
129
+ other_ids = items.map {|item| item.attributes['id'] } - %w[toc index] - class_item_ids
130
+ assert_false(other_ids.empty?)
131
+ other_ids.each do |id|
132
+ assert_not_include(spine_idrefs, id)
133
+ end
134
+ end
135
+ end
136
+
137
+ # EPUB のパッケージ(contents.opf)に載る前に、statichtml が出力ルートへ
138
+ # 書く 2 行のリダイレクトスタブ(<meta http-equiv=refresh> + <a>、
139
+ # ルート要素を持たず XML として整形式でない)を消す。
140
+ class TestEpubGeneratorIndexStub < Test::Unit::TestCase
141
+ def build_epub_generator
142
+ datadir = File.expand_path('../data/bitclust', __dir__)
143
+ BitClust::Generators::EPUB.new(:templatedir => Pathname.new("#{datadir}/template.epub"))
144
+ end
145
+
146
+ def setup
147
+ @dir = Dir.mktmpdir
148
+ @contents_directory = Pathname.new(@dir) + "OEBPS"
149
+ FileUtils.mkdir_p(@contents_directory)
150
+ @generator = build_epub_generator
151
+ end
152
+
153
+ def teardown
154
+ FileUtils.rm_rf(@dir)
155
+ end
156
+
157
+ def test_removes_the_redirect_stub_statichtml_writes_at_the_root
158
+ stub_path = @contents_directory + "index.xhtml"
159
+ File.write(stub_path, "<meta http-equiv=\"refresh\" content=\"0; URL=doc/index.xhtml\">\n<a href=\"doc/index.xhtml\">Go</a>\n")
160
+ assert_raise(REXML::ParseException) { REXML::Document.new(File.read(stub_path)) }
161
+
162
+ @generator.send(:remove_index_stub, @contents_directory)
163
+
164
+ assert_false(stub_path.exist?)
165
+ end
166
+
167
+ def test_is_a_noop_when_the_stub_is_absent
168
+ stub_path = @contents_directory + "index.xhtml"
169
+ assert_nothing_raised { @generator.send(:remove_index_stub, @contents_directory) }
170
+ assert_false(stub_path.exist?)
171
+ end
172
+
173
+ # doc/index.xhtml (マニュアルのトップページ) と紛れないことを確認する
174
+ def test_does_not_touch_the_doc_index_page
175
+ doc_dir = @contents_directory + "doc"
176
+ FileUtils.mkdir_p(doc_dir)
177
+ doc_index = doc_dir + "index.xhtml"
178
+ File.write(doc_index, "<html/>")
179
+ @generator.send(:remove_index_stub, @contents_directory)
180
+ assert_true(doc_index.exist?)
181
+ end
182
+ end
183
+
184
+ # data/bitclust/template.epub が整形式 XHTML を出力すること(layout の
185
+ # <meta>/<link> の自己終了、class のインデックス一覧での "<=>" や "&" を
186
+ # 含むメソッド名のエスケープ)を検証する。
187
+ #
188
+ # Screen#run_template は ERB 化したテンプレート本体をレシーバの
189
+ # self.class(ClassScreen / MethodScreen そのもの)に「respond_to? なら
190
+ # コンパイルしない」というガード付きでキャッシュする。同一プロセス内で
191
+ # template.offline 用の別テスト(例: test_class_screen.rb)が先に走ると、
192
+ # そちらのコンパイル結果を再利用してしまい、このテストが実際には
193
+ # template.epub を検証できなくなる(test_method_screen.rb に既知の注記
194
+ # あり)。
195
+ #
196
+ # 専用のサブクラスに分けるだけでは防げない: respond_to? は継承した
197
+ # メソッドにも true を返すので、スーパークラス(本物の ClassScreen /
198
+ # MethodScreen)側で他のテストが先に class_template 等をコンパイル済みだと、
199
+ # このサブクラスの run_template はガードに阻まれて自分の
200
+ # @template_repository(= template.epub)で再コンパイルしない。
201
+ # そこで、最初の render より前に明示的に def_method して
202
+ # class_template / method_template / layout をこのサブクラス自身に
203
+ # 直接定義しておく。直接定義されたメソッドは継承したものより優先されるので、
204
+ # 他のテストの実行順序に関係なく template.epub の内容を使わせられる。
205
+ class EpubTestClassScreen < BitClust::ClassScreen; end
206
+ class EpubTestMethodScreen < BitClust::MethodScreen; end
207
+ class EpubTestClassIndexScreen < BitClust::ClassIndexScreen; end
208
+
209
+ epub_template_repository = BitClust::TemplateRepository.new(
210
+ "#{File.expand_path('../data/bitclust', __dir__)}/template.epub"
211
+ )
212
+ [
213
+ [EpubTestClassScreen, 'class', 'class_template'],
214
+ [EpubTestMethodScreen, 'method', 'method_template'],
215
+ [EpubTestClassIndexScreen, 'class-index', 'class_index_template'],
216
+ ].each do |klass, id, method_name|
217
+ ERB.new(epub_template_repository.load(id)).def_method(klass, method_name, "#{id}.erb")
218
+ end
219
+ [EpubTestClassScreen, EpubTestMethodScreen, EpubTestClassIndexScreen].each do |klass|
220
+ ERB.new(epub_template_repository.load('layout')).def_method(klass, 'layout', 'layout.erb')
221
+ end
222
+
223
+ class TestEpubTemplateWellFormedness < Test::Unit::TestCase
224
+ SRC = <<'HERE'
225
+ = module Helper
226
+ 比較演算子を提供するヘルパーモジュール
227
+ = class Spaceship < Object
228
+ extend Helper
229
+ 比較演算子とビット演算子を持つサンプルクラス
230
+ == Instance Methods
231
+ --- <=>(other) -> Integer
232
+
233
+ 比較する。
234
+
235
+ --- &(other) -> Spaceship
236
+
237
+ 論理積を返す。
238
+ HERE
239
+
240
+ def setup
241
+ datadir = File.expand_path('../data/bitclust', __dir__)
242
+ @lib, @db = BitClust::RRDParser.parse(SRC, 'testlib', { 'version' => '3.4' })
243
+ urlmapper = BitClust::Subcommands::StatichtmlCommand::URLMapperEx.new(
244
+ :suffix => '.xhtml',
245
+ :css_url => 'style.css',
246
+ :favicon_url => 'rurema.png'
247
+ )
248
+ urlmapper.bitclust_html_base = '..'
249
+ @manager = BitClust::ScreenManager.new(
250
+ :templatedir => "#{datadir}/template.epub",
251
+ :catalogdir => "#{datadir}/catalog",
252
+ :encoding => 'utf-8',
253
+ :default_encoding => 'utf-8',
254
+ :urlmapper => urlmapper,
255
+ :target_version => '3.4'
256
+ )
257
+ end
258
+
259
+ def class_entry
260
+ @lib.fetch_class('Spaceship')
261
+ end
262
+
263
+ def method_entry(name)
264
+ class_entry.fetch_method(BitClust::MethodSpec.parse("Spaceship##{name}"))
265
+ end
266
+
267
+ def render_class_page
268
+ @manager.send(:new_screen, EpubTestClassScreen, class_entry, :database => @db).body
269
+ end
270
+
271
+ def render_method_page(name)
272
+ @manager.send(:new_screen, EpubTestMethodScreen, [method_entry(name)], :database => @db).body
273
+ end
274
+
275
+ def render_class_index_page
276
+ @manager.send(:new_screen, EpubTestClassIndexScreen, [class_entry], :database => @db).body
277
+ end
278
+
279
+ def test_class_page_escapes_spaceship_operator_in_the_index_list
280
+ html = render_class_page
281
+ assert_include(html, '&lt;=&gt;')
282
+ end
283
+
284
+ def test_class_page_escapes_ampersand_operator_in_the_index_list
285
+ html = render_class_page
286
+ # "&" 単体がエスケープされて "&amp;" として出る(リンクテキストの終端)
287
+ assert_match(/&amp;<\/a>/, html)
288
+ end
289
+
290
+ def test_class_page_is_well_formed_xml
291
+ html = render_class_page
292
+ assert_nothing_raised { REXML::Document.new(html) }
293
+ end
294
+
295
+ def test_method_page_for_spaceship_operator_is_well_formed_xml
296
+ html = render_method_page('<=>')
297
+ assert_nothing_raised { REXML::Document.new(html) }
298
+ end
299
+
300
+ def test_method_page_for_ampersand_operator_is_well_formed_xml
301
+ html = render_method_page('&')
302
+ assert_nothing_raised { REXML::Document.new(html) }
303
+ end
304
+
305
+ def test_layout_void_elements_are_self_closing
306
+ html = render_class_page
307
+ assert_not_match(%r{<meta[^>]*[^/]>}, html)
308
+ assert_not_match(%r{<link[^>]*[^/]>}, html)
309
+ end
310
+
311
+ # template.epub/class の "extend:" 行も <br>(非自己終了)を出しており、
312
+ # そのクラスページ全体が整形式 XML にならなかった(実データベースの
313
+ # Array・CSV クラスで再現した。どちらも extend/aliases 行を持つ)。
314
+ def test_class_page_extend_line_uses_a_self_closing_br
315
+ html = render_class_page
316
+ assert_include(html, 'extend: ')
317
+ assert_not_match(%r{<br[^>]*[^/]>}, html)
318
+ assert_nothing_raised { REXML::Document.new(html) }
319
+ end
320
+
321
+ # template.epub/class-index には対応する <ul> の無い孤立した </ul> が
322
+ # あり、実データベースで OEBPS/class/index.xhtml が整形式にならなかった
323
+ # (template.offline/class-index にも同じ孤立タグがあるが、HTML5 として
324
+ # 読まれる分には実害がないため未修正のまま。EPUB の XHTML では致命的)。
325
+ def test_class_index_page_has_no_orphaned_closing_tag
326
+ html = render_class_index_page
327
+ assert_not_include(html, '</ul>')
328
+ assert_nothing_raised { REXML::Document.new(html) }
329
+ end
330
+ end
@@ -0,0 +1,34 @@
1
+ require 'test/unit'
2
+ require 'stringio'
3
+ require 'tmpdir'
4
+ require 'bitclust'
5
+ require 'bitclust/subcommands/extract_command'
6
+
7
+ class TestRdOnlyCommandsRejectMarkdown < Test::Unit::TestCase
8
+ def with_md_file
9
+ Dir.mktmpdir do |dir|
10
+ path = File.join(dir, 'Array.md')
11
+ File.write(path, "---\nlibrary: _builtin\n---\n# class Array < Object\n")
12
+ yield path
13
+ end
14
+ end
15
+
16
+ def capture_stderr
17
+ err = StringIO.new
18
+ orig, $stderr = $stderr, err
19
+ yield
20
+ err.string
21
+ ensure
22
+ $stderr = orig
23
+ end
24
+
25
+ def test_extract_explains_markdown_is_unsupported
26
+ with_md_file do |path|
27
+ cmd = BitClust::Subcommands::ExtractCommand.new
28
+ cmd.parse([path])
29
+ msg = capture_stderr { assert_raise(SystemExit) { cmd.exec([path], {:prefix => nil, :capi => false}) } }
30
+ assert_match(/Markdown/, msg)
31
+ assert_match(/refm/, msg)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,211 @@
1
+ # frozen_string_literal: true
2
+ require 'test/unit'
3
+ require 'stringio'
4
+ require 'tmpdir'
5
+ require 'fileutils'
6
+ require 'bitclust'
7
+ require 'bitclust/subcommands/htmlfile_command'
8
+
9
+ # htmlfile サブコマンドの Markdown ソース(manual/)の変換。
10
+ #
11
+ # テストリスト:
12
+ # [x] エンティティ md は front matter の library: を所属として変換する
13
+ # [x] library: が多重所属なら、その版で生きている先頭の所属を使う
14
+ # [x] library: が無く --library も無ければエラー
15
+ # [x] --library で所属を指定できる
16
+ # [x] ライブラリルート md(type: library)はファイル名をライブラリ名にする
17
+ # [x] --ruby の版で #%since が解決される
18
+ # [x] manual/doc/ の md は doc ページとして変換する
19
+ # [x] --capi の md は C API として変換する
20
+ # [x] RD ソースは RD として変換する
21
+ class TestHtmlfileCommand < Test::Unit::TestCase
22
+ FOO_MD = <<~'MD'
23
+ ---
24
+ library: foo
25
+ ---
26
+ # class Foo < Object
27
+
28
+ クラスの説明。
29
+
30
+ ## Instance Methods
31
+
32
+ ### def bar -> nil
33
+
34
+ bar の **説明**。
35
+
36
+ #%since 3.4
37
+ ### def baz -> nil
38
+
39
+ baz の説明。
40
+ #%end
41
+ MD
42
+
43
+ def setup
44
+ @tmpdir = Dir.mktmpdir
45
+ @api = File.join(@tmpdir, 'manual', 'api')
46
+ FileUtils.mkdir_p(File.join(@api, 'foo'))
47
+ end
48
+
49
+ def teardown
50
+ FileUtils.rm_rf(@tmpdir)
51
+ end
52
+
53
+ def write(rel, content)
54
+ path = File.join(@tmpdir, rel)
55
+ FileUtils.mkdir_p(File.dirname(path))
56
+ File.write(path, content)
57
+ path
58
+ end
59
+
60
+ def run_htmlfile(args, capi: false)
61
+ cmd = BitClust::Subcommands::HtmlfileCommand.new
62
+ argv = args.dup
63
+ cmd.parse(argv)
64
+ out = StringIO.new
65
+ err = StringIO.new
66
+ orig_out, orig_err = $stdout, $stderr
67
+ $stdout, $stderr = out, err
68
+ status = nil
69
+ begin
70
+ cmd.exec(argv, {:prefix => nil, :capi => capi})
71
+ rescue SystemExit => e
72
+ status = e.status
73
+ ensure
74
+ $stdout, $stderr = orig_out, orig_err
75
+ end
76
+ [out.string, err.string, status]
77
+ end
78
+
79
+ def test_entity_uses_library_in_front_matter
80
+ path = write('manual/api/foo/Foo.md', FOO_MD)
81
+ out, _err, status = run_htmlfile(['--ruby=3.4', '--target=Foo', path])
82
+ assert_nil(status)
83
+ assert_match(/class Foo/, out)
84
+ assert_match(%r{library/foo">library foo<}, out)
85
+ assert_match(%r{<strong>説明</strong>}, out)
86
+ end
87
+
88
+ def test_entity_uses_first_live_membership
89
+ path = write('manual/api/foo/Foo.md', <<~'MD')
90
+ ---
91
+ library:
92
+ #%until 3.4
93
+ - old_foo
94
+ #%end
95
+ - foo
96
+ - foo_ext
97
+ ---
98
+ # class Foo < Object
99
+
100
+ クラスの説明。
101
+ MD
102
+ out, _err, status = run_htmlfile(['--ruby=3.4', '--target=Foo', path])
103
+ assert_nil(status)
104
+ assert_match(%r{library/foo">library foo<}, out)
105
+ out, _err, _status = run_htmlfile(['--ruby=3.3', '--target=Foo', path])
106
+ assert_match(%r{library/old_foo">library old_foo<}, out)
107
+ end
108
+
109
+ def test_entity_without_library_is_error
110
+ path = write('manual/api/foo/Foo.md', FOO_MD.sub(/\A---\nlibrary: foo\n---\n/, ''))
111
+ out, err, status = run_htmlfile(['--target=Foo', path])
112
+ assert_equal(1, status)
113
+ assert_equal('', out)
114
+ assert_match(/library:/, err)
115
+ assert_match(/--library/, err)
116
+ end
117
+
118
+ def test_library_option_gives_library
119
+ path = write('manual/api/foo/Foo.md', FOO_MD.sub(/\A---\nlibrary: foo\n---\n/, ''))
120
+ out, _err, status = run_htmlfile(['--library=bar', '--target=Foo', path])
121
+ assert_nil(status)
122
+ assert_match(%r{library/bar">library bar<}, out)
123
+ end
124
+
125
+ def test_library_root_uses_file_name
126
+ write('manual/api/foo/Foo.md', FOO_MD)
127
+ path = write('manual/api/net/foo.md', <<~'MD')
128
+ ---
129
+ type: library
130
+ category: Network
131
+ ---
132
+ foo ライブラリの **説明**。
133
+ MD
134
+ out, _err, status = run_htmlfile([path])
135
+ assert_nil(status)
136
+ assert_match(%r{<h1>library net/foo</h1>}, out)
137
+ assert_match(%r{<strong>説明</strong>}, out)
138
+ end
139
+
140
+ def test_builtin_library_root
141
+ path = write('manual/api/_builtin.md', "---\ntype: library\n---\n組み込みライブラリ。\n")
142
+ out, _err, status = run_htmlfile([path])
143
+ assert_nil(status)
144
+ assert_match(%r{<title>library _builtin }, out)
145
+ assert_match(/組み込みライブラリ。/, out)
146
+ end
147
+
148
+ def test_ruby_version_resolves_gates
149
+ path = write('manual/api/foo/Foo.md', FOO_MD)
150
+ out, _err, _status = run_htmlfile(['--ruby=3.4', '--target=Foo', path])
151
+ assert_match(/baz/, out)
152
+ out, _err, _status = run_htmlfile(['--ruby=3.3', '--target=Foo', path])
153
+ assert_match(/bar/, out)
154
+ assert_not_match(/baz/, out)
155
+ end
156
+
157
+ def test_target_method
158
+ path = write('manual/api/foo/Foo.md', FOO_MD)
159
+ out, _err, status = run_htmlfile(['--ruby=3.4', '--target=Foo#bar', path])
160
+ assert_nil(status)
161
+ assert_match(/bar の <strong>説明<\/strong>/, out)
162
+ assert_not_match(/baz の説明/, out)
163
+ end
164
+
165
+ def test_doc_page
166
+ path = write('manual/doc/spec/foo.md', <<~'MD')
167
+ # Foo の仕様
168
+
169
+ 本文の **強調**。
170
+ MD
171
+ out, _err, status = run_htmlfile([path])
172
+ assert_nil(status)
173
+ assert_match(/Foo の仕様/, out)
174
+ assert_match(%r{本文の <strong>強調</strong>}, out)
175
+ end
176
+
177
+ def test_capi
178
+ path = write('manual/capi/array.c.md', <<~'MD')
179
+ ### VALUE rb_foo_new()
180
+
181
+ 空の **Foo** を作ります。
182
+
183
+ ### VALUE rb_foo_bar(VALUE foo)
184
+
185
+ bar を返します。
186
+ MD
187
+ out, _err, status = run_htmlfile(['--target=rb_foo_new', path], capi: true)
188
+ assert_nil(status)
189
+ assert_match(/rb_foo_new/, out)
190
+ assert_match(%r{空の <strong>Foo</strong> を作ります。}, out)
191
+ assert_not_match(/bar を返します/, out)
192
+ end
193
+
194
+ def test_rd_source
195
+ path = write('refm/api/src/foo.rd', <<~'RD')
196
+ = class Foo < Object
197
+
198
+ クラスの説明。
199
+
200
+ == Instance Methods
201
+
202
+ --- bar -> nil
203
+
204
+ bar の説明。
205
+ RD
206
+ out, _err, status = run_htmlfile(['--target=Foo', path])
207
+ assert_nil(status)
208
+ assert_match(/class Foo/, out)
209
+ assert_match(/bar の説明。/, out)
210
+ end
211
+ end