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.
- checksums.yaml +4 -4
- data/data/bitclust/template/class-index +0 -1
- data/data/bitclust/template.epub/class +5 -5
- data/data/bitclust/template.epub/class-index +0 -1
- data/data/bitclust/template.epub/contents +7 -4
- data/data/bitclust/template.epub/layout +4 -4
- data/data/bitclust/template.offline/class-index +0 -1
- data/lib/bitclust/generators/epub.rb +69 -5
- data/lib/bitclust/irb.rb +14 -8
- data/lib/bitclust/markdown_bridge.rb +11 -6
- data/lib/bitclust/markdown_tree.rb +128 -11
- data/lib/bitclust/methoddatabase.rb +15 -4
- data/lib/bitclust/nameutils.rb +13 -0
- data/lib/bitclust/preprocessor.rb +0 -36
- data/lib/bitclust/remote.rb +405 -0
- data/lib/bitclust/runner.rb +5 -10
- data/lib/bitclust/screen.rb +2 -1
- data/lib/bitclust/searcher.rb +43 -24
- data/lib/bitclust/subcommands/chm_command.rb +1 -1
- data/lib/bitclust/subcommands/epub_command.rb +2 -2
- data/lib/bitclust/subcommands/extract_command.rb +7 -0
- data/lib/bitclust/subcommands/htmlfile_command.rb +73 -1
- data/lib/bitclust/subcommands/methods_command.rb +5 -28
- data/lib/bitclust/subcommands/query_command.rb +1 -0
- data/lib/bitclust/subcommands/server_command.rb +21 -10
- data/lib/bitclust/subcommands/setup_command.rb +28 -10
- data/lib/bitclust/syntax_highlighter.rb +65 -4
- data/lib/bitclust/user_dirs.rb +62 -0
- data/lib/bitclust/version.rb +1 -1
- data/test/test_chm_command.rb +22 -0
- data/test/test_epub_command.rb +60 -0
- data/test/test_epub_generator.rb +330 -0
- data/test/test_extract_command.rb +34 -0
- data/test/test_htmlfile_command.rb +211 -0
- data/test/test_irb_plugin.rb +100 -6
- data/test/test_markdown_bridge.rb +35 -0
- data/test/test_markdown_tree.rb +144 -0
- data/test/test_mdparser.rb +39 -0
- data/test/test_methods_command.rb +32 -0
- data/test/test_opensearchdescription_screen.rb +39 -0
- data/test/test_query_command.rb +30 -0
- data/test/test_remote.rb +374 -0
- data/test/test_runner.rb +61 -1
- data/test/test_searcher.rb +63 -0
- data/test/test_server_command.rb +41 -0
- data/test/test_setup_command.rb +143 -0
- data/test/test_syntax_highlighter.rb +124 -0
- data/test/test_user_dirs.rb +62 -0
- metadata +39 -2
- data/lib/bitclust/ridatabase.rb +0 -359
data/test/test_irb_plugin.rb
CHANGED
|
@@ -3,11 +3,14 @@ require 'test/unit'
|
|
|
3
3
|
require 'tmpdir'
|
|
4
4
|
require 'fileutils'
|
|
5
5
|
require 'stringio'
|
|
6
|
+
require 'json'
|
|
6
7
|
require 'bitclust'
|
|
7
8
|
require 'bitclust/methoddatabase'
|
|
8
9
|
require 'bitclust/searcher'
|
|
10
|
+
require 'bitclust/irb'
|
|
9
11
|
|
|
10
|
-
# bitclust-irb gem の irb コマンド(refe)
|
|
12
|
+
# bitclust-irb gem の irb コマンド(refe)。リモート検索そのものは
|
|
13
|
+
# test_remote.rb で検証する。
|
|
11
14
|
#
|
|
12
15
|
# テストリスト:
|
|
13
16
|
# [x] TerminalView が io: に出力する(既定は従来どおり $stdout)
|
|
@@ -16,6 +19,11 @@ require 'bitclust/searcher'
|
|
|
16
19
|
# [x] 空のパターンは使い方を表示して例外にしない
|
|
17
20
|
# [x] 見つからないパターンはメッセージを io へ書いて例外にしない
|
|
18
21
|
# [x] require で IRB::Command::Base のサブクラスとして登録される
|
|
22
|
+
# [x] Searcher#local_database? は既定の場所に DB が無ければ false・あれば true
|
|
23
|
+
# [x] Irb.lookup: db が与えられていれば remote を使わない
|
|
24
|
+
# [x] Irb.lookup: ローカル DB が無ければ remote で検索する
|
|
25
|
+
# [x] Irb.lookup: remote が nil なら bitclust setup を案内する
|
|
26
|
+
# [x] refe の CLI(Searcher#exec)も DB が無ければ remote で検索する
|
|
19
27
|
class TestBitClustIrbPlugin < Test::Unit::TestCase
|
|
20
28
|
FOO_MD = <<~'MD'
|
|
21
29
|
---
|
|
@@ -32,6 +40,16 @@ class TestBitClustIrbPlugin < Test::Unit::TestCase
|
|
|
32
40
|
bar の説明。
|
|
33
41
|
MD
|
|
34
42
|
|
|
43
|
+
BASE_URL = 'https://docs.ruby-lang.org/ja/latest/'
|
|
44
|
+
INDEX_JS = "var search_data = #{JSON.generate(index: [
|
|
45
|
+
{ name: 'String', full_name: 'String', type: 'class', path: 'class/String.html' },
|
|
46
|
+
{ name: 'gsub', full_name: 'String#gsub', type: 'instance_method', path: 'method/String/i/gsub.html' },
|
|
47
|
+
])};\n"
|
|
48
|
+
PAGES = {
|
|
49
|
+
'js/search_data.js' => INDEX_JS,
|
|
50
|
+
'method/String/i/gsub.md' => "# String#gsub\n\n置き換えます。\n",
|
|
51
|
+
}.freeze
|
|
52
|
+
|
|
35
53
|
def build_markdown_db(dir)
|
|
36
54
|
api = File.join(dir, 'manual', 'api')
|
|
37
55
|
FileUtils.mkdir_p(File.join(api, 'foo'))
|
|
@@ -56,15 +74,44 @@ class TestBitClustIrbPlugin < Test::Unit::TestCase
|
|
|
56
74
|
end
|
|
57
75
|
end
|
|
58
76
|
|
|
77
|
+
# 既定の DB 探索(環境変数・設定ファイル)がどれも当たらない状態
|
|
78
|
+
DB_ENV_KEYS = %w[REFE2_SERVER BITCLUST_SERVER REFE2_DATADIR BITCLUST_DATADIR
|
|
79
|
+
HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_CACHE_HOME].freeze
|
|
80
|
+
|
|
81
|
+
def without_local_db
|
|
82
|
+
saved = DB_ENV_KEYS.to_h {|k| [k, ENV[k]] }
|
|
83
|
+
Dir.mktmpdir do |home|
|
|
84
|
+
DB_ENV_KEYS.each {|k| ENV.delete(k) }
|
|
85
|
+
ENV['HOME'] = home
|
|
86
|
+
yield home
|
|
87
|
+
end
|
|
88
|
+
ensure
|
|
89
|
+
saved.each {|k, v| v ? ENV[k] = v : ENV.delete(k) }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def fake_remote(dir, pages = PAGES)
|
|
93
|
+
fetcher = lambda do |uri, _headers|
|
|
94
|
+
rel = uri.to_s.delete_prefix(BASE_URL)
|
|
95
|
+
pages.key?(rel) ? [200, pages[rel].dup] : [404, '']
|
|
96
|
+
end
|
|
97
|
+
BitClust::Remote.new(base_url: BASE_URL, fetcher: fetcher, cache_dir: File.join(dir, 'cache'))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def never_remote(dir)
|
|
101
|
+
BitClust::Remote.new(base_url: BASE_URL, cache_dir: File.join(dir, 'cache'),
|
|
102
|
+
fetcher: ->(_uri, _headers) { flunk 'remote must not be used' })
|
|
103
|
+
end
|
|
104
|
+
|
|
59
105
|
def test_terminal_view_writes_to_given_io
|
|
60
106
|
out = StringIO.new
|
|
61
107
|
view = BitClust::TerminalView.new(BitClust::Plain.new, {}, io: out)
|
|
62
108
|
view.send(:puts, 'hello')
|
|
63
109
|
assert_equal("hello\n", out.string)
|
|
110
|
+
assert_same(out, view.io)
|
|
111
|
+
assert_same($stdout, BitClust::TerminalView.new(BitClust::Plain.new, {}).io)
|
|
64
112
|
end
|
|
65
113
|
|
|
66
114
|
def test_lookup_method
|
|
67
|
-
require 'bitclust/irb'
|
|
68
115
|
with_db do |db|
|
|
69
116
|
out = StringIO.new
|
|
70
117
|
BitClust::Irb.lookup('Foo#bar', db: db, io: out)
|
|
@@ -74,7 +121,6 @@ class TestBitClustIrbPlugin < Test::Unit::TestCase
|
|
|
74
121
|
end
|
|
75
122
|
|
|
76
123
|
def test_lookup_class
|
|
77
|
-
require 'bitclust/irb'
|
|
78
124
|
with_db do |db|
|
|
79
125
|
out = StringIO.new
|
|
80
126
|
BitClust::Irb.lookup('Foo', db: db, io: out)
|
|
@@ -84,7 +130,6 @@ class TestBitClustIrbPlugin < Test::Unit::TestCase
|
|
|
84
130
|
end
|
|
85
131
|
|
|
86
132
|
def test_lookup_empty_pattern_shows_usage
|
|
87
|
-
require 'bitclust/irb'
|
|
88
133
|
with_db do |db|
|
|
89
134
|
out = StringIO.new
|
|
90
135
|
assert_nothing_raised do
|
|
@@ -95,7 +140,6 @@ class TestBitClustIrbPlugin < Test::Unit::TestCase
|
|
|
95
140
|
end
|
|
96
141
|
|
|
97
142
|
def test_lookup_not_found_reports_instead_of_raising
|
|
98
|
-
require 'bitclust/irb'
|
|
99
143
|
with_db do |db|
|
|
100
144
|
out = StringIO.new
|
|
101
145
|
assert_nothing_raised do
|
|
@@ -111,8 +155,58 @@ class TestBitClustIrbPlugin < Test::Unit::TestCase
|
|
|
111
155
|
rescue LoadError
|
|
112
156
|
omit 'irb >= 1.13 is not available'
|
|
113
157
|
end
|
|
114
|
-
require 'bitclust/irb'
|
|
115
158
|
assert(BitClust::Irb::RefeCommand < ::IRB::Command::Base)
|
|
116
159
|
assert_match(/るりま|リファレンス/, BitClust::Irb::RefeCommand.description)
|
|
117
160
|
end
|
|
161
|
+
|
|
162
|
+
def test_searcher_local_database_p
|
|
163
|
+
without_local_db do
|
|
164
|
+
assert_false(BitClust::Searcher.new.local_database?)
|
|
165
|
+
with_db do |db|
|
|
166
|
+
ENV['BITCLUST_DATADIR'] = db.instance_variable_get(:@prefix)
|
|
167
|
+
assert_true(BitClust::Searcher.new.local_database?)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def test_lookup_uses_local_db_when_given
|
|
173
|
+
with_db do |db|
|
|
174
|
+
Dir.mktmpdir do |dir|
|
|
175
|
+
out = StringIO.new
|
|
176
|
+
BitClust::Irb.lookup('Foo#bar', db: db, io: out, remote: never_remote(dir))
|
|
177
|
+
assert_match(/bar の説明。/, out.string)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def test_lookup_falls_back_to_remote_without_local_db
|
|
183
|
+
without_local_db do |home|
|
|
184
|
+
out = StringIO.new
|
|
185
|
+
BitClust::Irb.lookup('String#gsub', io: out, remote: fake_remote(home))
|
|
186
|
+
assert_match(/置き換えます。/, out.string)
|
|
187
|
+
assert_match(%r{method/String/i/gsub\.html}, out.string)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def test_lookup_without_remote_and_local_db_shows_setup_hint
|
|
192
|
+
without_local_db do
|
|
193
|
+
out = StringIO.new
|
|
194
|
+
assert_nothing_raised do
|
|
195
|
+
BitClust::Irb.lookup('String#gsub', io: out, remote: nil)
|
|
196
|
+
end
|
|
197
|
+
assert_match(/bitclust setup/, out.string)
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def test_refe_cli_falls_back_to_remote_without_local_db
|
|
202
|
+
without_local_db do |home|
|
|
203
|
+
out = StringIO.new
|
|
204
|
+
searcher = BitClust::Searcher.new
|
|
205
|
+
searcher.remote = fake_remote(home)
|
|
206
|
+
searcher.parse(%w[String#gsub])
|
|
207
|
+
view = BitClust::TerminalView.new(BitClust::Plain.new, {}, io: out)
|
|
208
|
+
searcher.run_query(nil, %w[String#gsub], view)
|
|
209
|
+
assert_match(/置き換えます。/, out.string)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
118
212
|
end
|
|
@@ -91,6 +91,41 @@ class TestMarkdownBridge < Test::Unit::TestCase
|
|
|
91
91
|
out["thread.rd"]
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
+
def test_membership_version_and_else_wrap_include_sites
|
|
95
|
+
# bitclust#331: #@version V は #@if (version == "V")、その #@else は
|
|
96
|
+
# #@if (version != "V") で再具現化する。範囲の #@else は 2 つの
|
|
97
|
+
# membership(A 未満 / B 以上)になるので include サイトも 2 つ
|
|
98
|
+
out = build_from(
|
|
99
|
+
"builtin.md" => "---\ntype: library\n---\nbuiltin 概要。\n",
|
|
100
|
+
"onlylib.md" => "---\ntype: library\n---\nonlylib 概要。\n",
|
|
101
|
+
"range.md" => "---\ntype: library\n---\nrange 概要。\n",
|
|
102
|
+
"onlylib/Shared.md" =>
|
|
103
|
+
"---\n" \
|
|
104
|
+
"library:\n" \
|
|
105
|
+
"\#@version 3.2\n" \
|
|
106
|
+
" - onlylib\n" \
|
|
107
|
+
"\#@else\n" \
|
|
108
|
+
" - builtin\n" \
|
|
109
|
+
"\#@end\n" \
|
|
110
|
+
"\#@version 3.1...3.3\n" \
|
|
111
|
+
" - range\n" \
|
|
112
|
+
"\#@else\n" \
|
|
113
|
+
" - range\n" \
|
|
114
|
+
"\#@end\n" \
|
|
115
|
+
"---\n" \
|
|
116
|
+
"# class Shared < Object\nS。\n"
|
|
117
|
+
)
|
|
118
|
+
assert_equal "onlylib 概要。\n\n\#@if (version == \"3.2\")\n\#@include(onlylib/Shared)\n\#@end\n",
|
|
119
|
+
out["onlylib.rd"]
|
|
120
|
+
assert_equal "builtin 概要。\n\n\#@if (version != \"3.2\")\n\#@include(onlylib/Shared)\n\#@end\n",
|
|
121
|
+
out["builtin.rd"]
|
|
122
|
+
assert_equal "range 概要。\n\n" \
|
|
123
|
+
"\#@until 3.3\n\#@since 3.1\n\#@include(onlylib/Shared)\n\#@end\n\#@end\n" \
|
|
124
|
+
"\#@until 3.1\n\#@include(onlylib/Shared)\n\#@end\n" \
|
|
125
|
+
"\#@since 3.3\n\#@include(onlylib/Shared)\n\#@end\n",
|
|
126
|
+
out["range.rd"]
|
|
127
|
+
end
|
|
128
|
+
|
|
94
129
|
def test_libraries_manifest
|
|
95
130
|
out = build
|
|
96
131
|
assert_equal "bar/baz\ndual\nfoo\n\#@until 3.1\ngated\n\#@end\nsub/sub\n", out["LIBRARIES"]
|
data/test/test_markdown_tree.rb
CHANGED
|
@@ -366,4 +366,148 @@ class TestMarkdownTree < Test::Unit::TestCase
|
|
|
366
366
|
"version-range-gated H1 relations must not be flagged"
|
|
367
367
|
assert_equal [], tree.warnings
|
|
368
368
|
end
|
|
369
|
+
|
|
370
|
+
# --- front matter ゲート付きリストのディレクティブ(bitclust#331) ---
|
|
371
|
+
# テストリスト:
|
|
372
|
+
# [x] #%else は直前ゲートの反転(until → since / since → until)
|
|
373
|
+
# [x] #%version A...B / A... / ...B / V(単一版)
|
|
374
|
+
# [x] #%version A...B の #%else は「A 未満」と「B 以上」の 2 membership
|
|
375
|
+
# [x] #%version V の #%else は except: [V]
|
|
376
|
+
# [x] 入れ子のゲートは交差(since は max・until は min)
|
|
377
|
+
# [x] 矛盾する入れ子(単一版 ≠ 単一版)は membership を作らない
|
|
378
|
+
# [x] #%# コメント行は無視
|
|
379
|
+
# [x] 未知の #% 行・#%if・対応のない #%else/#%end・二重 #%else・
|
|
380
|
+
# リスト終端で閉じていないゲートは ParseError(無音の打ち切りをやめる)
|
|
381
|
+
|
|
382
|
+
def membership_scan(list)
|
|
383
|
+
scan(
|
|
384
|
+
"a.md" => LIB, "b.md" => LIB, "c.md" => LIB,
|
|
385
|
+
"a/X.md" => "---\nlibrary:\n#{list}---\n# class X < Object\n"
|
|
386
|
+
)
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
def memberships_of(list)
|
|
390
|
+
tree = membership_scan(list)
|
|
391
|
+
assert_equal [], tree.warnings
|
|
392
|
+
tree.entities["a/X.md"][:memberships]
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
def test_else_inverts_until
|
|
396
|
+
assert_equal [
|
|
397
|
+
{ library: "a", until: "3.4" },
|
|
398
|
+
{ library: "b", since: "3.4" },
|
|
399
|
+
], memberships_of("#%until 3.4\n - a\n#%else\n - b\n#%end\n")
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
def test_else_inverts_since
|
|
403
|
+
assert_equal [
|
|
404
|
+
{ library: "a", since: "3.4" },
|
|
405
|
+
{ library: "b", until: "3.4" },
|
|
406
|
+
], memberships_of("#%since 3.4\n - a\n#%else\n - b\n#%end\n")
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
def test_version_range_forms
|
|
410
|
+
assert_equal [
|
|
411
|
+
{ library: "a", since: "3.1", until: "3.3" },
|
|
412
|
+
{ library: "b", since: "3.1" },
|
|
413
|
+
{ library: "c", until: "3.3" },
|
|
414
|
+
], memberships_of(
|
|
415
|
+
"#%version 3.1...3.3\n - a\n#%end\n" \
|
|
416
|
+
"#%version 3.1...\n - b\n#%end\n" \
|
|
417
|
+
"#%version ...3.3\n - c\n#%end\n"
|
|
418
|
+
)
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
def test_single_version
|
|
422
|
+
assert_equal [{ library: "a", version: "3.1" }],
|
|
423
|
+
memberships_of("#%version 3.1\n - a\n#%end\n")
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
def test_else_of_version_range_splits_into_two_memberships
|
|
427
|
+
assert_equal [
|
|
428
|
+
{ library: "a", since: "3.1", until: "3.3" },
|
|
429
|
+
{ library: "b", until: "3.1" },
|
|
430
|
+
{ library: "b", since: "3.3" },
|
|
431
|
+
], memberships_of("#%version 3.1...3.3\n - a\n#%else\n - b\n#%end\n")
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
def test_else_of_single_version_is_except
|
|
435
|
+
assert_equal [
|
|
436
|
+
{ library: "a", version: "3.1" },
|
|
437
|
+
{ library: "b", except: ["3.1"] },
|
|
438
|
+
], memberships_of("#%version 3.1\n - a\n#%else\n - b\n#%end\n")
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def test_nested_gates_intersect
|
|
442
|
+
assert_equal [
|
|
443
|
+
{ library: "a", since: "3.2", until: "3.4" },
|
|
444
|
+
{ library: "b", since: "3.0", until: "3.2" },
|
|
445
|
+
], memberships_of(
|
|
446
|
+
"#%since 3.0\n#%until 3.4\n#%since 3.2\n - a\n#%else\n - b\n#%end\n#%end\n#%end\n"
|
|
447
|
+
)
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
def test_contradicting_nested_single_versions_yield_no_membership
|
|
451
|
+
assert_equal [{ library: "b", version: "3.1" }],
|
|
452
|
+
memberships_of("#%version 3.1\n#%version 3.2\n - a\n#%end\n - b\n#%end\n")
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
def test_directive_comment_lines_are_ignored
|
|
456
|
+
assert_equal [{ library: "a" }, { library: "b", until: "3.4" }],
|
|
457
|
+
memberships_of("#%# comment\n - a\n#%until 3.4\n#%# another\n - b\n#%end\n")
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
def test_at_prefix_else_and_version
|
|
461
|
+
assert_equal [
|
|
462
|
+
{ library: "a", since: "3.1", until: "3.3" },
|
|
463
|
+
{ library: "b", until: "3.1" },
|
|
464
|
+
{ library: "b", since: "3.3" },
|
|
465
|
+
], memberships_of("\#@version 3.1...3.3\n - a\n\#@else\n - b\n\#@end\n")
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
def assert_list_parse_error(list, pattern)
|
|
469
|
+
e = assert_raise(BitClust::ParseError) { membership_scan(list) }
|
|
470
|
+
assert_match pattern, e.message
|
|
471
|
+
assert_match(/a\/X\.md:\d+/, e.message, "message must locate the file and line")
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
def test_unknown_directive_in_list_raises
|
|
475
|
+
assert_list_parse_error(" - a\n#%sinse 3.4\n - b\n#%end\n", /unknown preprocessor directive/)
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
def test_if_in_list_is_unsupported
|
|
479
|
+
assert_list_parse_error("#%if (version >= \"3.4\")\n - a\n#%end\n", /#%if is not supported/)
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
def test_else_without_gate_raises
|
|
483
|
+
assert_list_parse_error(" - a\n#%else\n - b\n#%end\n", /no matching/)
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
def test_end_without_gate_raises
|
|
487
|
+
assert_list_parse_error(" - a\n#%end\n", /no matching/)
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
def test_duplicate_else_raises
|
|
491
|
+
assert_list_parse_error("#%since 3.4\n - a\n#%else\n - b\n#%else\n - c\n#%end\n", /duplicate/)
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
def test_unterminated_gate_at_list_end_raises
|
|
495
|
+
assert_list_parse_error("#%since 3.4\n - a\n", /unterminated/)
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
def test_indented_directive_in_list_raises
|
|
499
|
+
# 列 0 でない #% 行は Preprocessor でも指令にならない(YAML コメント扱い)。
|
|
500
|
+
# リスト内で無音にゲートが無視されたりリストが打ち切られたりしないよう、
|
|
501
|
+
# 指令風のインデント行はエラーにする
|
|
502
|
+
assert_list_parse_error(" - a\n #%since 3.0\n - b\n#%end\n", /must start at column 0/)
|
|
503
|
+
end
|
|
504
|
+
|
|
505
|
+
def test_yaml_comment_in_list_is_ignored
|
|
506
|
+
assert_equal [{ library: "a" }, { library: "b", since: "3.0" }],
|
|
507
|
+
memberships_of(" # plain yaml comment\n - a\n#%since 3.0\n # another\n - b\n#%end\n")
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
def test_wrong_version_range_raises
|
|
511
|
+
assert_list_parse_error("#%version 3.1..3.3\n - a\n#%end\n", /wrong version range/)
|
|
512
|
+
end
|
|
369
513
|
end
|
data/test/test_mdparser.rb
CHANGED
|
@@ -412,6 +412,45 @@ class TestMDParser < Test::Unit::TestCase
|
|
|
412
412
|
end
|
|
413
413
|
end
|
|
414
414
|
|
|
415
|
+
def test_update_by_markdowntree_else_and_single_version_memberships
|
|
416
|
+
# bitclust#331: ゲート付き library リストの #@version V(単一版)と #@else。
|
|
417
|
+
# 3.2 だけ onlylib、それ以外は builtin に属する。版の比較は Gem::Version
|
|
418
|
+
# なので 3.2.0 の DB でも 3.2 と同じ版として扱う
|
|
419
|
+
require 'tmpdir'
|
|
420
|
+
Dir.mktmpdir do |root|
|
|
421
|
+
write = ->(rel, s) {
|
|
422
|
+
path = File.join(root, rel)
|
|
423
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
424
|
+
File.write(path, s)
|
|
425
|
+
}
|
|
426
|
+
write.call('builtin.md', "---\ntype: library\n---\nbuiltin。\n")
|
|
427
|
+
write.call('onlylib.md', "---\ntype: library\n---\nonlylib。\n")
|
|
428
|
+
write.call('onlylib/Shared.md', <<~'MD')
|
|
429
|
+
---
|
|
430
|
+
library:
|
|
431
|
+
#@version 3.2
|
|
432
|
+
- onlylib
|
|
433
|
+
#@else
|
|
434
|
+
- builtin
|
|
435
|
+
#@end
|
|
436
|
+
---
|
|
437
|
+
# class Shared < Object
|
|
438
|
+
|
|
439
|
+
共有クラス。
|
|
440
|
+
MD
|
|
441
|
+
|
|
442
|
+
classes = ->(version) {
|
|
443
|
+
db = BitClust::MethodDatabase.dummy("version" => version)
|
|
444
|
+
db.update_by_markdowntree(root)
|
|
445
|
+
%w[builtin onlylib].map { |lib| db.fetch_library(lib).classes.map(&:name) }
|
|
446
|
+
}
|
|
447
|
+
assert_equal [[], %w[Shared]], classes.call("3.2")
|
|
448
|
+
assert_equal [[], %w[Shared]], classes.call("3.2.0")
|
|
449
|
+
assert_equal [%w[Shared], []], classes.call("3.4")
|
|
450
|
+
assert_equal [%w[Shared], []], classes.call("3.0")
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
|
|
415
454
|
def test_update_by_markdowntree_parse_error_suggests_gem_update
|
|
416
455
|
# manual/ が新しい bitclust を必要とする記法を含むとき、古い gem では
|
|
417
456
|
# パースエラーになる。原因へたどり着けるよう gem 更新の案内を添える
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'bitclust'
|
|
4
|
+
require 'bitclust/subcommands/methods_command'
|
|
5
|
+
|
|
6
|
+
class TestMethodsCommand < Test::Unit::TestCase
|
|
7
|
+
def setup
|
|
8
|
+
@cmd = BitClust::Subcommands::MethodsCommand.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_needs_no_database
|
|
12
|
+
assert_false(@cmd.needs_database?)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_content_option_is_not_accepted
|
|
16
|
+
assert_raise(OptionParser::InvalidOption) do
|
|
17
|
+
@cmd.parse(['-c', 'Object'])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_ri_database_option_is_not_accepted
|
|
22
|
+
assert_raise(OptionParser::InvalidOption) do
|
|
23
|
+
@cmd.parse(['--ri-database=/tmp/ri', 'Object'])
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_diff_and_ruby_options_are_kept
|
|
28
|
+
assert_nothing_raised do
|
|
29
|
+
@cmd.parse(['--ruby=3.4.8', '--diff=refm/api/src/_builtin/Object', 'Object'])
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'uri'
|
|
3
|
+
require 'bitclust'
|
|
4
|
+
require 'bitclust/screen'
|
|
5
|
+
|
|
6
|
+
class TestOpenSearchDescriptionScreen < Test::Unit::TestCase
|
|
7
|
+
SRC = <<'HERE'
|
|
8
|
+
= class Foo
|
|
9
|
+
description
|
|
10
|
+
HERE
|
|
11
|
+
|
|
12
|
+
def screen
|
|
13
|
+
_lib, db = BitClust::RRDParser.parse(SRC, 'testlib', {'version' => '3.4'})
|
|
14
|
+
datadir = File.expand_path('../data/bitclust', __dir__)
|
|
15
|
+
manager = BitClust::ScreenManager.new(
|
|
16
|
+
:templatedir => "#{datadir}/template",
|
|
17
|
+
:catalogdir => "#{datadir}/catalog",
|
|
18
|
+
:encoding => 'utf-8',
|
|
19
|
+
:default_encoding => 'utf-8',
|
|
20
|
+
:base_url => '',
|
|
21
|
+
:cgi_url => '/view',
|
|
22
|
+
:target_version => '3.4'
|
|
23
|
+
)
|
|
24
|
+
manager.opensearchdescription_screen(URI.parse('http://example.com/view/opensearchdescription'),
|
|
25
|
+
:database => db)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_body_is_bare_xml_without_html_layout
|
|
29
|
+
body = screen.body
|
|
30
|
+
assert_match(/\A<\?xml/, body)
|
|
31
|
+
assert_not_include(body, '<html')
|
|
32
|
+
assert_match(%r{\A<\?xml[^>]*\?>\s*<OpenSearchDescription\b.*</OpenSearchDescription>\s*\z}m, body)
|
|
33
|
+
assert_include(body, 'http://example.com/view/search')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_content_type_is_opensearch_xml
|
|
37
|
+
assert_equal 'application/opensearchdescription+xml; charset=utf-8', screen.content_type
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'stringio'
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
require 'bitclust'
|
|
5
|
+
require 'bitclust/subcommands/query_command'
|
|
6
|
+
|
|
7
|
+
class TestQueryCommand < Test::Unit::TestCase
|
|
8
|
+
def run_query(script, capi: false)
|
|
9
|
+
Dir.mktmpdir do |dir|
|
|
10
|
+
cmd = BitClust::Subcommands::QueryCommand.new
|
|
11
|
+
cmd.parse([script])
|
|
12
|
+
out = StringIO.new
|
|
13
|
+
orig, $stdout = $stdout, out
|
|
14
|
+
begin
|
|
15
|
+
cmd.exec([script], {:prefix => dir, :capi => capi})
|
|
16
|
+
ensure
|
|
17
|
+
$stdout = orig
|
|
18
|
+
end
|
|
19
|
+
out.string
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_db_is_available_to_the_script
|
|
24
|
+
assert_equal %Q("BitClust::MethodDatabase"\n), run_query('@db.class.name')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_capi_uses_function_database
|
|
28
|
+
assert_equal %Q("BitClust::FunctionDatabase"\n), run_query('@db.class.name', capi: true)
|
|
29
|
+
end
|
|
30
|
+
end
|