yard 0.9.24 → 0.9.25
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +37 -24
- data/CHANGELOG.md +18 -3
- data/README.md +96 -101
- data/Rakefile +2 -0
- data/lib/yard/cli/diff.rb +4 -1
- data/lib/yard/cli/server.rb +22 -13
- data/lib/yard/code_objects/proxy.rb +2 -1
- data/lib/yard/globals.rb +1 -1
- data/lib/yard/handlers/c/base.rb +164 -129
- data/lib/yard/parser/ruby/ruby_parser.rb +6 -4
- data/lib/yard/registry_store.rb +1 -1
- data/lib/yard/templates/helpers/html_helper.rb +10 -3
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
- data/lib/yard/version.rb +1 -1
- data/tasks/update_error_map.rake +53 -0
- data/yard.gemspec +1 -1
- metadata +3 -207
- data/spec/cli/command_parser_spec.rb +0 -43
- data/spec/cli/command_spec.rb +0 -36
- data/spec/cli/config_spec.rb +0 -148
- data/spec/cli/diff_spec.rb +0 -254
- data/spec/cli/display_spec.rb +0 -30
- data/spec/cli/gems_spec.rb +0 -81
- data/spec/cli/graph_spec.rb +0 -18
- data/spec/cli/help_spec.rb +0 -22
- data/spec/cli/i18n_spec.rb +0 -107
- data/spec/cli/list_spec.rb +0 -8
- data/spec/cli/markup_types_spec.rb +0 -22
- data/spec/cli/server_spec.rb +0 -324
- data/spec/cli/stats_spec.rb +0 -96
- data/spec/cli/yard_on_yard_spec.rb +0 -38
- data/spec/cli/yardoc_spec.rb +0 -896
- data/spec/cli/yri_spec.rb +0 -101
- data/spec/code_objects/base_spec.rb +0 -485
- data/spec/code_objects/class_object_spec.rb +0 -226
- data/spec/code_objects/code_object_list_spec.rb +0 -36
- data/spec/code_objects/constants_spec.rb +0 -116
- data/spec/code_objects/extra_file_object_spec.rb +0 -161
- data/spec/code_objects/macro_object_spec.rb +0 -150
- data/spec/code_objects/method_object_spec.rb +0 -184
- data/spec/code_objects/module_object_spec.rb +0 -142
- data/spec/code_objects/namespace_mapper_spec.rb +0 -32
- data/spec/code_objects/namespace_object_spec.rb +0 -171
- data/spec/code_objects/proxy_spec.rb +0 -147
- data/spec/code_objects/spec_helper.rb +0 -3
- data/spec/config_spec.rb +0 -171
- data/spec/core_ext/array_spec.rb +0 -13
- data/spec/core_ext/file_spec.rb +0 -72
- data/spec/core_ext/hash_spec.rb +0 -14
- data/spec/core_ext/insertion_spec.rb +0 -37
- data/spec/core_ext/module_spec.rb +0 -9
- data/spec/core_ext/string_spec.rb +0 -42
- data/spec/core_ext/symbol_hash_spec.rb +0 -89
- data/spec/docstring_parser_spec.rb +0 -280
- data/spec/docstring_spec.rb +0 -373
- data/spec/handlers/alias_handler_spec.rb +0 -82
- data/spec/handlers/attribute_handler_spec.rb +0 -96
- data/spec/handlers/base_spec.rb +0 -216
- data/spec/handlers/c/alias_handler_spec.rb +0 -34
- data/spec/handlers/c/attribute_handler_spec.rb +0 -41
- data/spec/handlers/c/class_handler_spec.rb +0 -78
- data/spec/handlers/c/constant_handler_spec.rb +0 -71
- data/spec/handlers/c/init_handler_spec.rb +0 -48
- data/spec/handlers/c/method_handler_spec.rb +0 -327
- data/spec/handlers/c/mixin_handler_spec.rb +0 -44
- data/spec/handlers/c/module_handler_spec.rb +0 -71
- data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
- data/spec/handlers/c/path_handler_spec.rb +0 -36
- data/spec/handlers/c/spec_helper.rb +0 -23
- data/spec/handlers/c/struct_handler_spec.rb +0 -16
- data/spec/handlers/class_condition_handler_spec.rb +0 -87
- data/spec/handlers/class_handler_spec.rb +0 -247
- data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
- data/spec/handlers/class_variable_handler_spec.rb +0 -12
- data/spec/handlers/constant_handler_spec.rb +0 -112
- data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
- data/spec/handlers/dsl_handler_spec.rb +0 -226
- data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
- data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
- data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
- data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
- data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
- data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
- data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
- data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
- data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
- data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
- data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
- data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
- data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
- data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
- data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
- data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
- data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
- data/spec/handlers/exception_handler_spec.rb +0 -49
- data/spec/handlers/extend_handler_spec.rb +0 -28
- data/spec/handlers/legacy_base_spec.rb +0 -128
- data/spec/handlers/method_condition_handler_spec.rb +0 -15
- data/spec/handlers/method_handler_spec.rb +0 -214
- data/spec/handlers/mixin_handler_spec.rb +0 -60
- data/spec/handlers/module_function_handler_spec.rb +0 -106
- data/spec/handlers/module_handler_spec.rb +0 -35
- data/spec/handlers/private_class_method_handler_spec.rb +0 -11
- data/spec/handlers/private_constant_handler_spec.rb +0 -25
- data/spec/handlers/processor_spec.rb +0 -35
- data/spec/handlers/public_class_method_handler_spec.rb +0 -11
- data/spec/handlers/ruby/base_spec.rb +0 -95
- data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
- data/spec/handlers/spec_helper.rb +0 -33
- data/spec/handlers/visibility_handler_spec.rb +0 -44
- data/spec/handlers/yield_handler_spec.rb +0 -52
- data/spec/i18n/locale_spec.rb +0 -81
- data/spec/i18n/message_spec.rb +0 -52
- data/spec/i18n/messages_spec.rb +0 -67
- data/spec/i18n/pot_generator_spec.rb +0 -295
- data/spec/i18n/text_spec.rb +0 -184
- data/spec/logging_spec.rb +0 -44
- data/spec/options_spec.rb +0 -171
- data/spec/parser/base_spec.rb +0 -24
- data/spec/parser/c_parser_spec.rb +0 -236
- data/spec/parser/examples/array.c.txt +0 -6267
- data/spec/parser/examples/example1.rb.txt +0 -8
- data/spec/parser/examples/extrafile.c.txt +0 -8
- data/spec/parser/examples/file.c.txt +0 -28
- data/spec/parser/examples/multifile.c.txt +0 -22
- data/spec/parser/examples/namespace.cpp.txt +0 -68
- data/spec/parser/examples/override.c.txt +0 -424
- data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
- data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
- data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
- data/spec/parser/ruby/ast_node_spec.rb +0 -33
- data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
- data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
- data/spec/parser/ruby/ruby_parser_spec.rb +0 -520
- data/spec/parser/ruby/token_resolver_spec.rb +0 -165
- data/spec/parser/source_parser_spec.rb +0 -727
- data/spec/parser/tag_parsing_spec.rb +0 -17
- data/spec/rake/yardoc_task_spec.rb +0 -118
- data/spec/registry_resolver_spec.rb +0 -15
- data/spec/registry_spec.rb +0 -463
- data/spec/registry_store_spec.rb +0 -327
- data/spec/rubygems/doc_manager_spec.rb +0 -112
- data/spec/serializers/data/serialized_yardoc/checksums +0 -1
- data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
- data/spec/serializers/file_system_serializer_spec.rb +0 -145
- data/spec/serializers/spec_helper.rb +0 -2
- data/spec/serializers/yardoc_serializer_spec.rb +0 -90
- data/spec/server/adapter_spec.rb +0 -39
- data/spec/server/commands/base_spec.rb +0 -91
- data/spec/server/commands/library_command_spec.rb +0 -39
- data/spec/server/doc_server_helper_spec.rb +0 -72
- data/spec/server/doc_server_serializer_spec.rb +0 -60
- data/spec/server/rack_adapter_spec.rb +0 -21
- data/spec/server/router_spec.rb +0 -123
- data/spec/server/spec_helper.rb +0 -22
- data/spec/server/static_caching_spec.rb +0 -47
- data/spec/server/webrick_servlet_spec.rb +0 -20
- data/spec/server_spec.rb +0 -19
- data/spec/spec_helper.rb +0 -212
- data/spec/tags/default_factory_spec.rb +0 -168
- data/spec/tags/default_tag_spec.rb +0 -11
- data/spec/tags/directives_spec.rb +0 -463
- data/spec/tags/library_spec.rb +0 -48
- data/spec/tags/overload_tag_spec.rb +0 -53
- data/spec/tags/ref_tag_list_spec.rb +0 -53
- data/spec/tags/types_explainer_spec.rb +0 -203
- data/spec/templates/class_spec.rb +0 -45
- data/spec/templates/constant_spec.rb +0 -41
- data/spec/templates/engine_spec.rb +0 -131
- data/spec/templates/examples/class001.html +0 -308
- data/spec/templates/examples/class001.txt +0 -36
- data/spec/templates/examples/class002.html +0 -39
- data/spec/templates/examples/constant001.txt +0 -25
- data/spec/templates/examples/constant002.txt +0 -7
- data/spec/templates/examples/constant003.txt +0 -11
- data/spec/templates/examples/method001.html +0 -137
- data/spec/templates/examples/method001.txt +0 -35
- data/spec/templates/examples/method002.html +0 -91
- data/spec/templates/examples/method002.txt +0 -20
- data/spec/templates/examples/method003.html +0 -165
- data/spec/templates/examples/method003.txt +0 -45
- data/spec/templates/examples/method004.html +0 -48
- data/spec/templates/examples/method004.txt +0 -10
- data/spec/templates/examples/method005.html +0 -105
- data/spec/templates/examples/method005.txt +0 -33
- data/spec/templates/examples/method006.html +0 -108
- data/spec/templates/examples/method006.txt +0 -20
- data/spec/templates/examples/module001.dot +0 -33
- data/spec/templates/examples/module001.html +0 -833
- data/spec/templates/examples/module001.txt +0 -33
- data/spec/templates/examples/module002.html +0 -341
- data/spec/templates/examples/module003.html +0 -202
- data/spec/templates/examples/module004.html +0 -394
- data/spec/templates/examples/module005.html +0 -82
- data/spec/templates/examples/tag001.txt +0 -82
- data/spec/templates/helpers/base_helper_spec.rb +0 -171
- data/spec/templates/helpers/html_helper_spec.rb +0 -666
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
- data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
- data/spec/templates/helpers/markup_helper_spec.rb +0 -136
- data/spec/templates/helpers/method_helper_spec.rb +0 -107
- data/spec/templates/helpers/module_helper_spec.rb +0 -35
- data/spec/templates/helpers/shared_signature_examples.rb +0 -126
- data/spec/templates/helpers/text_helper_spec.rb +0 -65
- data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
- data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -50
- data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -48
- data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
- data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -64
- data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -64
- data/spec/templates/method_spec.rb +0 -118
- data/spec/templates/module_spec.rb +0 -203
- data/spec/templates/onefile_spec.rb +0 -66
- data/spec/templates/section_spec.rb +0 -144
- data/spec/templates/spec_helper.rb +0 -76
- data/spec/templates/tag_spec.rb +0 -52
- data/spec/templates/template_spec.rb +0 -410
- data/spec/verifier_spec.rb +0 -106
@@ -1,150 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe YARD::CodeObjects::MacroObject do
|
5
|
-
before do
|
6
|
-
Registry.clear
|
7
|
-
end
|
8
|
-
|
9
|
-
describe ".create" do
|
10
|
-
def create(*args) MacroObject.create(*args) end
|
11
|
-
|
12
|
-
it "creates an object" do
|
13
|
-
create('foo', '')
|
14
|
-
obj = Registry.at('.macro.foo')
|
15
|
-
expect(obj).not_to be nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it "uses identity map" do
|
19
|
-
obj1 = create('foo', '')
|
20
|
-
obj2 = create('foo', '')
|
21
|
-
expect(obj1.object_id).to eq obj2.object_id
|
22
|
-
end
|
23
|
-
|
24
|
-
it "allows specifying of macro data" do
|
25
|
-
obj = create('foo', 'MACRODATA')
|
26
|
-
expect(obj.macro_data).to eq 'MACRODATA'
|
27
|
-
end
|
28
|
-
|
29
|
-
context "if a method object is provided" do
|
30
|
-
it "attaches it" do
|
31
|
-
obj = create('foo', 'MACRODATA', P('Foo.property'))
|
32
|
-
expect(obj.method_object).to eq P('Foo.property')
|
33
|
-
expect(obj).to be_attached
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe ".find" do
|
39
|
-
before { MacroObject.create('foo', 'DATA') }
|
40
|
-
|
41
|
-
it "searches for an object by name" do
|
42
|
-
expect(MacroObject.find('foo').macro_data).to eq 'DATA'
|
43
|
-
end
|
44
|
-
|
45
|
-
it "accepts Symbol" do
|
46
|
-
expect(MacroObject.find(:foo).macro_data).to eq 'DATA'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe ".find_or_create" do
|
51
|
-
it "looks up name if @!macro is present and find object" do
|
52
|
-
macro1 = MacroObject.create('foo', 'FOO')
|
53
|
-
macro2 = MacroObject.find_or_create('foo', "a b c")
|
54
|
-
expect(macro1).to eq macro2
|
55
|
-
end
|
56
|
-
|
57
|
-
it "creates new macro if macro by that name does not exist" do
|
58
|
-
MacroObject.find_or_create('foo', "@!method $1")
|
59
|
-
expect(MacroObject.find('foo').macro_data).to eq "@!method $1"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe ".apply" do
|
64
|
-
let(:args) { %w(foo a b c) }
|
65
|
-
|
66
|
-
def apply(comments)
|
67
|
-
MacroObject.apply(comments, args)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "only expands macros if @macro is present" do
|
71
|
-
expect(apply("$1$2$3")).to eq "$1$2$3"
|
72
|
-
end
|
73
|
-
|
74
|
-
it "handles macro text inside block" do
|
75
|
-
expect(apply("@!macro\n foo$1$2$3\nfoobaz")).to eq "fooabc\nfoobaz"
|
76
|
-
end
|
77
|
-
|
78
|
-
it "appends docstring to existing macro" do
|
79
|
-
MacroObject.create('name', '$3$2$1')
|
80
|
-
result = MacroObject.apply("@!macro name\nfoobar", args)
|
81
|
-
expect(result).to eq "cba\nfoobar"
|
82
|
-
end
|
83
|
-
|
84
|
-
it "uses only non-macro data if docstring is an existing macro" do
|
85
|
-
data = "@!macro name\n $3$2$1\nEXTRA"
|
86
|
-
result = MacroObject.apply(data, args, 'SOURCE')
|
87
|
-
expect(result).to eq "cba\nEXTRA"
|
88
|
-
expect(MacroObject.apply("@!macro name\nFOO", args)).to eq "cba\nFOO"
|
89
|
-
end
|
90
|
-
|
91
|
-
it "creates macros if they don't exist" do
|
92
|
-
result = MacroObject.apply("@!macro name\n foo!$1", args, 'SOURCE')
|
93
|
-
expect(result).to eq "foo!a"
|
94
|
-
expect(MacroObject.find('name').macro_data).to eq 'foo!$1'
|
95
|
-
end
|
96
|
-
|
97
|
-
it "keeps other tags" do
|
98
|
-
expect(apply("@!macro\n foo$1$2$3\n@param name foo\nfoo")).to eq(
|
99
|
-
"fooabc\nfoo\n@param name\n foo"
|
100
|
-
)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe ".expand" do
|
105
|
-
def expand(comments)
|
106
|
-
args = %w(foo a b c)
|
107
|
-
full_line = 'foo :bar, :baz'
|
108
|
-
MacroObject.expand(comments, args, full_line)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "allows escaping of macro syntax" do
|
112
|
-
expect(expand("$1\\$2$3")).to eq "a$2c"
|
113
|
-
end
|
114
|
-
|
115
|
-
it "replaces $* with the whole statement" do
|
116
|
-
expect(expand("$* ${*}")).to eq "foo :bar, :baz foo :bar, :baz"
|
117
|
-
end
|
118
|
-
|
119
|
-
it "replaces $0 with method name" do
|
120
|
-
expect(expand("$0 ${0}")).to eq "foo foo"
|
121
|
-
end
|
122
|
-
|
123
|
-
it "replaces all $N values with the Nth argument in the method call" do
|
124
|
-
expect(expand("$1$2$3${3}\nfoobar")).to eq "abcc\nfoobar"
|
125
|
-
end
|
126
|
-
|
127
|
-
it "replaces ${N-M} ranges with N-M arguments (incl. commas)" do
|
128
|
-
expect(expand("${1-2}x")).to eq "a, bx"
|
129
|
-
end
|
130
|
-
|
131
|
-
it "handles open ended ranges (${N-})" do
|
132
|
-
expect(expand("${2-}")).to eq "b, c"
|
133
|
-
end
|
134
|
-
|
135
|
-
it "handles negative indexes ($-N)" do
|
136
|
-
expect(expand("$-1 ${-2-} ${-2--2}")).to eq "c b, c b"
|
137
|
-
end
|
138
|
-
|
139
|
-
it "accepts Docstring objects" do
|
140
|
-
expect(expand(Docstring.new("$1\n@param name foo"))).to eq "a\n@param name foo"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe "#expand" do
|
145
|
-
it "expands a macro given its data" do
|
146
|
-
macro = MacroObject.create_docstring('foo', '$1 $2 THREE!')
|
147
|
-
expect(macro.expand(['NAME', 'ONE', 'TWO'])).to eq "ONE TWO THREE!"
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe YARD::CodeObjects::MethodObject do
|
5
|
-
before do
|
6
|
-
Registry.clear
|
7
|
-
@yard = ModuleObject.new(:root, :YARD)
|
8
|
-
end
|
9
|
-
|
10
|
-
context "for an instance method in the root" do
|
11
|
-
it "has a path of testing" do
|
12
|
-
meth = MethodObject.new(:root, :testing)
|
13
|
-
expect(meth.path).to eq "#testing"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "for an instance method in YARD" do
|
18
|
-
it "has a path of YARD#testing" do
|
19
|
-
meth = MethodObject.new(@yard, :testing)
|
20
|
-
expect(meth.path).to eq "YARD#testing"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "for a class method in YARD" do
|
25
|
-
it "has a path of YARD.testing" do
|
26
|
-
meth = MethodObject.new(@yard, :testing, :class)
|
27
|
-
expect(meth.path).to eq "YARD.testing"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "for a class method added to root namespace" do
|
32
|
-
it "has a path of ::testing (note the ::)" do
|
33
|
-
meth = MethodObject.new(:root, :testing, :class)
|
34
|
-
expect(meth.path).to eq "::testing"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "exists in the registry after successful creation" do
|
39
|
-
MethodObject.new(@yard, :something, :class)
|
40
|
-
expect(Registry.at("YARD.something")).not_to be nil
|
41
|
-
expect(Registry.at("YARD#something")).to be nil
|
42
|
-
expect(Registry.at("YARD::something")).to be nil
|
43
|
-
MethodObject.new(@yard, :somethingelse)
|
44
|
-
expect(Registry.at("YARD#somethingelse")).not_to be nil
|
45
|
-
end
|
46
|
-
|
47
|
-
it "allows #scope to be changed after creation" do
|
48
|
-
obj = MethodObject.new(@yard, :something, :class)
|
49
|
-
expect(Registry.at("YARD.something")).not_to be nil
|
50
|
-
obj.scope = :instance
|
51
|
-
expect(Registry.at("YARD.something")).to be nil
|
52
|
-
expect(Registry.at("YARD#something")).not_to be nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it "creates object in :class scope if scope is :module" do
|
56
|
-
obj = MethodObject.new(@yard, :module_func, :module)
|
57
|
-
expect(obj.scope).to eq :class
|
58
|
-
expect(obj.visibility).to eq :public
|
59
|
-
expect(Registry.at('YARD.module_func')).not_to be nil
|
60
|
-
end
|
61
|
-
|
62
|
-
it "creates second private instance method if scope is :module" do
|
63
|
-
MethodObject.new(@yard, :module_func, :module)
|
64
|
-
obj = Registry.at('YARD#module_func')
|
65
|
-
expect(obj).not_to be nil
|
66
|
-
expect(obj.visibility).to eq :private
|
67
|
-
expect(obj.scope).to eq :instance
|
68
|
-
end
|
69
|
-
|
70
|
-
it "yields block to second method if scope is :module" do
|
71
|
-
MethodObject.new(@yard, :module_func, :module) do |o|
|
72
|
-
o.docstring = 'foo'
|
73
|
-
end
|
74
|
-
expect(Registry.at('YARD.module_func').docstring).to eq 'foo'
|
75
|
-
expect(Registry.at('YARD#module_func').docstring).to eq 'foo'
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "#name" do
|
79
|
-
it "shows a prefix for an instance method when prefix=true" do
|
80
|
-
obj = MethodObject.new(nil, :something)
|
81
|
-
expect(obj.name(true)).to eq "#something"
|
82
|
-
end
|
83
|
-
|
84
|
-
it "never shows a prefix for a class method" do
|
85
|
-
obj = MethodObject.new(nil, :something, :class)
|
86
|
-
expect(obj.name).to eq :something
|
87
|
-
expect(obj.name(true)).to eq "something"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "#is_attribute?" do
|
92
|
-
it "only returns true if attribute is set in namespace for read/write" do
|
93
|
-
obj = MethodObject.new(@yard, :foo)
|
94
|
-
@yard.attributes[:instance][:foo] = {:read => obj, :write => nil}
|
95
|
-
expect(obj.is_attribute?).to be true
|
96
|
-
expect(MethodObject.new(@yard, :foo=).is_attribute?).to be false
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "#attr_info" do
|
101
|
-
it "returns attribute info if namespace is available" do
|
102
|
-
obj = MethodObject.new(@yard, :foo)
|
103
|
-
@yard.attributes[:instance][:foo] = {:read => obj, :write => nil}
|
104
|
-
expect(obj.attr_info).to eq @yard.attributes[:instance][:foo]
|
105
|
-
end
|
106
|
-
|
107
|
-
it "returns nil if namespace is proxy" do
|
108
|
-
MethodObject.new(P(:ProxyClass), :foo)
|
109
|
-
expect(MethodObject.new(@yard, :foo).attr_info).to eq nil
|
110
|
-
end
|
111
|
-
|
112
|
-
it "returns nil if meth is not an attribute" do
|
113
|
-
expect(MethodObject.new(@yard, :notanattribute).attr_info).to eq nil
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "#writer?" do
|
118
|
-
it "returns true if method is a writer attribute" do
|
119
|
-
obj = MethodObject.new(@yard, :foo=)
|
120
|
-
@yard.attributes[:instance][:foo] = {:read => nil, :write => obj}
|
121
|
-
expect(obj.writer?).to be true
|
122
|
-
expect(MethodObject.new(@yard, :NOTfoo=).writer?).to be false
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "#reader?" do
|
127
|
-
it "returns true if method is a reader attribute" do
|
128
|
-
obj = MethodObject.new(@yard, :foo)
|
129
|
-
@yard.attributes[:instance][:foo] = {:read => obj, :write => nil}
|
130
|
-
expect(obj.reader?).to be true
|
131
|
-
expect(MethodObject.new(@yard, :NOTfoo).reader?).to be false
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "#constructor?" do
|
136
|
-
before { @class = ClassObject.new(:root, :MyClass) }
|
137
|
-
|
138
|
-
it "marks the #initialize method as constructor" do
|
139
|
-
MethodObject.new(@class, :initialize)
|
140
|
-
end
|
141
|
-
|
142
|
-
it "does not mark Klass.initialize as constructor" do
|
143
|
-
expect(MethodObject.new(@class, :initialize, :class).constructor?).to be false
|
144
|
-
end
|
145
|
-
|
146
|
-
it "does not mark module method #initialize as constructor" do
|
147
|
-
expect(MethodObject.new(@yard, :initialize).constructor?).to be false
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "#overridden_method" do
|
152
|
-
before { Registry.clear }
|
153
|
-
|
154
|
-
it "returns overridden method from mixin first" do
|
155
|
-
YARD.parse_string(<<-eof)
|
156
|
-
module C; def foo; end end
|
157
|
-
class A; def foo; end end
|
158
|
-
class B < A; include C; def foo; end end
|
159
|
-
eof
|
160
|
-
expect(Registry.at('B#foo').overridden_method).to eq Registry.at('C#foo')
|
161
|
-
end
|
162
|
-
|
163
|
-
it "returns overridden method from superclass" do
|
164
|
-
YARD.parse_string(<<-eof)
|
165
|
-
class A; def foo; end end
|
166
|
-
class B < A; def foo; end end
|
167
|
-
eof
|
168
|
-
expect(Registry.at('B#foo').overridden_method).to eq Registry.at('A#foo')
|
169
|
-
end
|
170
|
-
|
171
|
-
it "returns nil if none is found" do
|
172
|
-
YARD.parse_string(<<-eof)
|
173
|
-
class A; end
|
174
|
-
class B < A; def foo; end end
|
175
|
-
eof
|
176
|
-
expect(Registry.at('B#foo').overridden_method).to be nil
|
177
|
-
end
|
178
|
-
|
179
|
-
it "returns nil if namespace is a proxy" do
|
180
|
-
YARD.parse_string "def ARGV.foo; end"
|
181
|
-
expect(Registry.at('ARGV.foo').overridden_method).to be nil
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
@@ -1,142 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe YARD::CodeObjects::ModuleObject do
|
5
|
-
describe "#meths" do
|
6
|
-
before do
|
7
|
-
Registry.clear
|
8
|
-
|
9
|
-
# setup the object space:
|
10
|
-
#
|
11
|
-
# YARD:module
|
12
|
-
# YARD#foo:method
|
13
|
-
# YARD#foo2:method
|
14
|
-
# YARD#xyz:method
|
15
|
-
# YARD.bar:method
|
16
|
-
# SomeMod#mixmethod
|
17
|
-
# SomeMod#xyz:method
|
18
|
-
#
|
19
|
-
@yard = ModuleObject.new(:root, :YARD)
|
20
|
-
MethodObject.new(@yard, :foo)
|
21
|
-
MethodObject.new(@yard, :xyz)
|
22
|
-
MethodObject.new(@yard, :foo2) do |o|
|
23
|
-
o.visibility = :protected
|
24
|
-
end
|
25
|
-
MethodObject.new(@yard, :bar, :class) do |o|
|
26
|
-
o.visibility = :private
|
27
|
-
end
|
28
|
-
@other = ModuleObject.new(:root, :SomeMod)
|
29
|
-
MethodObject.new(@other, :mixmethod)
|
30
|
-
MethodObject.new(@other, :xyz)
|
31
|
-
MethodObject.new(@other, :baz, :class)
|
32
|
-
@another = ModuleObject.new(:root, :AnotherMod)
|
33
|
-
MethodObject.new(@another, :fizz)
|
34
|
-
MethodObject.new(@another, :bar)
|
35
|
-
MethodObject.new(@another, :fazz, :class)
|
36
|
-
|
37
|
-
@yard.instance_mixins << @other
|
38
|
-
@yard.class_mixins << @another
|
39
|
-
end
|
40
|
-
|
41
|
-
it "lists all methods (including mixin methods) via #meths" do
|
42
|
-
meths = @yard.meths
|
43
|
-
expect(meths).to include(P("YARD#foo"))
|
44
|
-
expect(meths).to include(P("YARD#foo2"))
|
45
|
-
expect(meths).to include(P("YARD.bar"))
|
46
|
-
expect(meths).to include(P("SomeMod#mixmethod"))
|
47
|
-
expect(meths).to include(P("AnotherMod#fizz"))
|
48
|
-
end
|
49
|
-
|
50
|
-
it "allows :visibility to be set" do
|
51
|
-
meths = @yard.meths(:visibility => :public)
|
52
|
-
expect(meths).not_to include(P("YARD.bar"))
|
53
|
-
meths = @yard.meths(:visibility => [:public, :private])
|
54
|
-
expect(meths).to include(P("YARD#foo"))
|
55
|
-
expect(meths).to include(P("YARD.bar"))
|
56
|
-
expect(meths).not_to include(P("YARD#foo2"))
|
57
|
-
end
|
58
|
-
|
59
|
-
it "only displays class methods for :scope => :class" do
|
60
|
-
meths = @yard.meths(:scope => :class)
|
61
|
-
expect(meths).not_to include(P("YARD#foo"))
|
62
|
-
expect(meths).not_to include(P("YARD#foo2"))
|
63
|
-
expect(meths).not_to include(P("SomeMod#mixmethod"))
|
64
|
-
expect(meths).not_to include(P("SomeMod.baz"))
|
65
|
-
expect(meths).not_to include(P("AnotherMod#fazz"))
|
66
|
-
expect(meths).to include(P("YARD.bar"))
|
67
|
-
expect(meths).to include(P("AnotherMod#fizz"))
|
68
|
-
end
|
69
|
-
|
70
|
-
it "only displays instance methods for :scope => :class" do
|
71
|
-
meths = @yard.meths(:scope => :instance)
|
72
|
-
expect(meths).to include(P("YARD#foo"))
|
73
|
-
expect(meths).to include(P("YARD#foo2"))
|
74
|
-
expect(meths).to include(P("SomeMod#mixmethod"))
|
75
|
-
expect(meths).not_to include(P("YARD.bar"))
|
76
|
-
expect(meths).not_to include(P("AnotherMod#fizz"))
|
77
|
-
end
|
78
|
-
|
79
|
-
it "allows :included to be set" do
|
80
|
-
meths = @yard.meths(:included => false)
|
81
|
-
expect(meths).not_to include(P("SomeMod#mixmethod"))
|
82
|
-
expect(meths).not_to include(P("AnotherMod#fizz"))
|
83
|
-
expect(meths).to include(P("YARD#foo"))
|
84
|
-
expect(meths).to include(P("YARD#foo2"))
|
85
|
-
expect(meths).to include(P("YARD.bar"))
|
86
|
-
end
|
87
|
-
|
88
|
-
it "chooses the method defined in the class over an included module" do
|
89
|
-
meths = @yard.meths
|
90
|
-
expect(meths).not_to include(P("SomeMod#xyz"))
|
91
|
-
expect(meths).to include(P("YARD#xyz"))
|
92
|
-
expect(meths).not_to include(P("AnotherMod#bar"))
|
93
|
-
expect(meths).to include(P("YARD.bar"))
|
94
|
-
|
95
|
-
meths = @other.meths
|
96
|
-
expect(meths).to include(P("SomeMod#xyz"))
|
97
|
-
|
98
|
-
meths = @another.meths
|
99
|
-
expect(meths).to include(P("AnotherMod#bar"))
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "#inheritance_tree" do
|
104
|
-
before do
|
105
|
-
Registry.clear
|
106
|
-
|
107
|
-
@mod1 = ModuleObject.new(:root, :Mod1)
|
108
|
-
@mod2 = ModuleObject.new(:root, :Mod2)
|
109
|
-
@mod3 = ModuleObject.new(:root, :Mod3)
|
110
|
-
@mod4 = ModuleObject.new(:root, :Mod4)
|
111
|
-
@mod5 = ModuleObject.new(:root, :Mod5)
|
112
|
-
|
113
|
-
@mod1.instance_mixins << @mod2
|
114
|
-
@mod2.instance_mixins << @mod3
|
115
|
-
@mod3.instance_mixins << @mod4
|
116
|
-
@mod1.instance_mixins << @mod4
|
117
|
-
|
118
|
-
@proxy = P(:SomeProxyClass)
|
119
|
-
@mod5.instance_mixins << @proxy
|
120
|
-
end
|
121
|
-
|
122
|
-
it "shows only itself for an inheritance tree without included modules" do
|
123
|
-
expect(@mod1.inheritance_tree).to eq [@mod1]
|
124
|
-
end
|
125
|
-
|
126
|
-
it "shows proper inheritance tree when modules are included" do
|
127
|
-
expect(@mod1.inheritance_tree(true)).to eq [@mod1, @mod2, @mod3, @mod4]
|
128
|
-
end
|
129
|
-
|
130
|
-
it "does not list inheritance tree of proxy objects in inheritance tree" do
|
131
|
-
expect(@proxy).not_to receive(:inheritance_tree)
|
132
|
-
expect(@mod5.instance_mixins).to eq [@proxy]
|
133
|
-
end
|
134
|
-
|
135
|
-
it "lists class mixins in inheritance tree" do
|
136
|
-
mod = ModuleObject.new(:root, :ClassMethods)
|
137
|
-
recvmod = ModuleObject.new(:root, :ReceivingModule)
|
138
|
-
recvmod.class_mixins << mod
|
139
|
-
expect(recvmod.inheritance_tree(true)).to eq [recvmod, mod]
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|