Class: RubyIndexer::MethodTest
- Defined in:
- lib/ruby_indexer/test/method_test.rb
Instance Method Summary collapse
- #test_ignores_attributes_invoked_on_constant ⇒ Object
- #test_keeps_track_of_attributes ⇒ Object
- #test_keeps_track_of_method_owner ⇒ Object
- #test_method_with_anonymous_rest_parameters ⇒ Object
- #test_method_with_block_parameters ⇒ Object
- #test_method_with_destructed_parameters ⇒ Object
- #test_method_with_destructured_rest_parameters ⇒ Object
- #test_method_with_forbidden_keyword_splat_parameter ⇒ Object
- #test_method_with_keyword_parameters ⇒ Object
- #test_method_with_no_parameters ⇒ Object
- #test_method_with_optional_parameters ⇒ Object
- #test_method_with_parameters ⇒ Object
- #test_method_with_post_parameters ⇒ Object
- #test_method_with_rest_and_keyword_rest_parameters ⇒ Object
- #test_singleton_method_using_other_receiver_is_not_indexed ⇒ Object
- #test_singleton_method_using_self_receiver ⇒ Object
Methods inherited from TestCase
Instance Method Details
#test_ignores_attributes_invoked_on_constant ⇒ Object
278 279 280 281 282 283 284 285 286 287 |
# File 'lib/ruby_indexer/test/method_test.rb', line 278 def test_ignores_attributes_invoked_on_constant index(<<~RUBY) class Foo end Foo.attr_reader :bar RUBY assert_no_entry("bar") end |
#test_keeps_track_of_attributes ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/ruby_indexer/test/method_test.rb', line 259 def test_keeps_track_of_attributes index(<<~RUBY) class Foo # Hello there attr_reader :bar, :other attr_writer :baz attr_accessor :qux end RUBY assert_entry("bar", Entry::Accessor, "/fake/path/foo.rb:2-15:2-18") assert_equal("Hello there", @index["bar"].first.comments.join("\n")) assert_entry("other", Entry::Accessor, "/fake/path/foo.rb:2-21:2-26") assert_equal("Hello there", @index["other"].first.comments.join("\n")) assert_entry("baz=", Entry::Accessor, "/fake/path/foo.rb:3-15:3-18") assert_entry("qux", Entry::Accessor, "/fake/path/foo.rb:4-17:4-20") assert_entry("qux=", Entry::Accessor, "/fake/path/foo.rb:4-17:4-20") end |
#test_keeps_track_of_method_owner ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/ruby_indexer/test/method_test.rb', line 245 def test_keeps_track_of_method_owner index(<<~RUBY) class Foo def bar end end RUBY entry = T.must(@index["bar"].first) owner_name = T.must(entry.owner).name assert_equal("Foo", owner_name) end |
#test_method_with_anonymous_rest_parameters ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/ruby_indexer/test/method_test.rb', line 212 def test_method_with_anonymous_rest_parameters index(<<~RUBY) class Foo def bar(*, **) end end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") entry = T.must(@index["bar"].first) assert_equal(2, entry.parameters.length) first, second = entry.parameters assert_equal(Entry::RestParameter::DEFAULT_NAME, first.name) assert_instance_of(Entry::RestParameter, first) assert_equal(Entry::KeywordRestParameter::DEFAULT_NAME, second.name) assert_instance_of(Entry::KeywordRestParameter, second) end |
#test_method_with_block_parameters ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/ruby_indexer/test/method_test.rb', line 188 def test_method_with_block_parameters index(<<~RUBY) class Foo def bar(&block) end def baz(&) end end RUBY entry = T.must(@index["bar"].first) param = entry.parameters.first assert_equal(:block, param.name) assert_instance_of(Entry::BlockParameter, param) entry = T.must(@index["baz"].first) assert_equal(1, entry.parameters.length) param = entry.parameters.first assert_equal(Entry::BlockParameter::DEFAULT_NAME, param.name) assert_instance_of(Entry::BlockParameter, param) end |
#test_method_with_destructed_parameters ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby_indexer/test/method_test.rb', line 57 def test_method_with_destructed_parameters index(<<~RUBY) class Foo def bar((a, (b, ))) end end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") entry = T.must(@index["bar"].first) assert_equal(1, entry.parameters.length) parameter = entry.parameters.first assert_equal(:"(a, (b, ))", parameter.name) assert_instance_of(Entry::RequiredParameter, parameter) end |
#test_method_with_destructured_rest_parameters ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/ruby_indexer/test/method_test.rb', line 171 def test_method_with_destructured_rest_parameters index(<<~RUBY) class Foo def bar((a, *b)) end end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") entry = T.must(@index["bar"].first) assert_equal(1, entry.parameters.length) param = entry.parameters.first assert_equal(:"(a, *b)", param.name) assert_instance_of(Entry::RequiredParameter, param) end |
#test_method_with_forbidden_keyword_splat_parameter ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/ruby_indexer/test/method_test.rb', line 232 def test_method_with_forbidden_keyword_splat_parameter index(<<~RUBY) class Foo def bar(**nil) end end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") entry = T.must(@index["bar"].first) assert_empty(entry.parameters) end |
#test_method_with_keyword_parameters ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ruby_indexer/test/method_test.rb', line 89 def test_method_with_keyword_parameters index(<<~RUBY) class Foo def bar(a:, b: 123) end end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") entry = T.must(@index["bar"].first) assert_equal(2, entry.parameters.length) a, b = entry.parameters assert_equal(:a, a.name) assert_instance_of(Entry::KeywordParameter, a) assert_equal(:b, b.name) assert_instance_of(Entry::OptionalKeywordParameter, b) end |
#test_method_with_no_parameters ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby_indexer/test/method_test.rb', line 8 def test_method_with_no_parameters index(<<~RUBY) class Foo def bar end end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") end |
#test_method_with_optional_parameters ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ruby_indexer/test/method_test.rb', line 73 def test_method_with_optional_parameters index(<<~RUBY) class Foo def bar(a = 123) end end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") entry = T.must(@index["bar"].first) assert_equal(1, entry.parameters.length) parameter = entry.parameters.first assert_equal(:a, parameter.name) assert_instance_of(Entry::OptionalParameter, parameter) end |
#test_method_with_parameters ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ruby_indexer/test/method_test.rb', line 41 def test_method_with_parameters index(<<~RUBY) class Foo def bar(a) end end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") entry = T.must(@index["bar"].first) assert_equal(1, entry.parameters.length) parameter = entry.parameters.first assert_equal(:a, parameter.name) assert_instance_of(Entry::RequiredParameter, parameter) end |
#test_method_with_post_parameters ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ruby_indexer/test/method_test.rb', line 129 def test_method_with_post_parameters index(<<~RUBY) class Foo def bar(*a, b) end def baz(**a, b) end def qux(*a, (b, c)) end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") entry = T.must(@index["bar"].first) assert_equal(2, entry.parameters.length) a, b = entry.parameters assert_equal(:a, a.name) assert_instance_of(Entry::RestParameter, a) assert_equal(:b, b.name) assert_instance_of(Entry::RequiredParameter, b) entry = T.must(@index["baz"].first) assert_equal(2, entry.parameters.length) a, b = entry.parameters assert_equal(:a, a.name) assert_instance_of(Entry::KeywordRestParameter, a) assert_equal(:b, b.name) assert_instance_of(Entry::RequiredParameter, b) entry = T.must(@index["qux"].first) assert_equal(2, entry.parameters.length) _a, second = entry.parameters assert_equal(:"(b, c)", second.name) assert_instance_of(Entry::RequiredParameter, second) end |
#test_method_with_rest_and_keyword_rest_parameters ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ruby_indexer/test/method_test.rb', line 109 def test_method_with_rest_and_keyword_rest_parameters index(<<~RUBY) class Foo def bar(*a, **b) end end RUBY assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5") entry = T.must(@index["bar"].first) assert_equal(2, entry.parameters.length) a, b = entry.parameters assert_equal(:a, a.name) assert_instance_of(Entry::RestParameter, a) assert_equal(:b, b.name) assert_instance_of(Entry::KeywordRestParameter, b) end |
#test_singleton_method_using_other_receiver_is_not_indexed ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_indexer/test/method_test.rb', line 30 def test_singleton_method_using_other_receiver_is_not_indexed index(<<~RUBY) class Foo def String.bar end end RUBY assert_no_entry("bar") end |
#test_singleton_method_using_self_receiver ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_indexer/test/method_test.rb', line 19 def test_singleton_method_using_self_receiver index(<<~RUBY) class Foo def self.bar end end RUBY assert_entry("bar", Entry::SingletonMethod, "/fake/path/foo.rb:1-2:2-5") end |