Class: RubyIndexer::InstanceVariableTest

Inherits:
TestCase
  • Object
show all
Defined in:
lib/ruby_indexer/test/instance_variables_test.rb

Instance Method Summary collapse

Methods inherited from TestCase

#setup

Instance Method Details

#test_class_instance_variablesObject



128
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
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 128

def test_class_instance_variables
  index("    module Foo\n      class Bar\n        @a = 123\n\n        class << self\n          def hello\n            @b = 123\n          end\n\n          @c = 123\n        end\n      end\n    end\n  RUBY\n\n  assert_entry(\"@a\", Entry::InstanceVariable, \"/fake/path/foo.rb:2-4:2-6\")\n\n  entry = T.must(@index[\"@a\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::SingletonClass, owner)\n  assert_equal(\"Foo::Bar::<Class:Bar>\", owner.name)\n\n  assert_entry(\"@b\", Entry::InstanceVariable, \"/fake/path/foo.rb:6-8:6-10\")\n\n  entry = T.must(@index[\"@b\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::SingletonClass, owner)\n  assert_equal(\"Foo::Bar::<Class:Bar>\", owner.name)\n\n  assert_entry(\"@c\", Entry::InstanceVariable, \"/fake/path/foo.rb:9-6:9-8\")\n\n  entry = T.must(@index[\"@c\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::SingletonClass, owner)\n  assert_equal(\"Foo::Bar::<Class:Bar>::<Class:<Class:Bar>>\", owner.name)\nend\n")

#test_class_instance_variables_inside_self_methodObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 176

def test_class_instance_variables_inside_self_method
  index("    class Foo\n      def self.bar\n        @a = 123\n      end\n    end\n  RUBY\n\n  entry = T.must(@index[\"@a\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::SingletonClass, owner)\n  assert_equal(\"Foo::<Class:Foo>\", owner.name)\nend\n")

#test_empty_name_instance_variablesObject



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 114

def test_empty_name_instance_variables
  index("    module Foo\n      class Bar\n        def initialize\n          @ = 123\n        end\n      end\n    end\n  RUBY\n\n  refute_entry(\"@\")\nend\n")

#test_instance_variable_and_writeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 28

def test_instance_variable_and_write
  index("    module Foo\n      class Bar\n        def initialize\n          # Hello\n          @a &&= value\n        end\n      end\n    end\n  RUBY\n\n  assert_entry(\"@a\", Entry::InstanceVariable, \"/fake/path/foo.rb:4-6:4-8\")\n\n  entry = T.must(@index[\"@a\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::Class, owner)\n  assert_equal(\"Foo::Bar\", owner.name)\nend\n")

#test_instance_variable_inside_dynamic_method_declarationObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 191

def test_instance_variable_inside_dynamic_method_declaration
  index("    class Foo\n      def something.bar\n        @a = 123\n      end\n    end\n  RUBY\n\n  # If the surrounding method is beind defined on any dynamic value that isn't `self`, then we attribute the\n  # instance variable to the wrong owner since there's no way to understand that statically\n  entry = T.must(@index[\"@a\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::Class, owner)\n  assert_equal(\"Foo\", owner.name)\nend\n")

#test_instance_variable_operator_writeObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 48

def test_instance_variable_operator_write
  index("    module Foo\n      class Bar\n        def initialize\n          # Hello\n          @a += value\n        end\n      end\n    end\n  RUBY\n\n  assert_entry(\"@a\", Entry::InstanceVariable, \"/fake/path/foo.rb:4-6:4-8\")\n\n  entry = T.must(@index[\"@a\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::Class, owner)\n  assert_equal(\"Foo::Bar\", owner.name)\nend\n")

#test_instance_variable_or_writeObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 68

def test_instance_variable_or_write
  index("    module Foo\n      class Bar\n        def initialize\n          # Hello\n          @a ||= value\n        end\n      end\n    end\n  RUBY\n\n  assert_entry(\"@a\", Entry::InstanceVariable, \"/fake/path/foo.rb:4-6:4-8\")\n\n  entry = T.must(@index[\"@a\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::Class, owner)\n  assert_equal(\"Foo::Bar\", owner.name)\nend\n")

#test_instance_variable_targetObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 88

def test_instance_variable_target
  index("    module Foo\n      class Bar\n        def initialize\n          # Hello\n          @a, @b = [1, 2]\n        end\n      end\n    end\n  RUBY\n\n  assert_entry(\"@a\", Entry::InstanceVariable, \"/fake/path/foo.rb:4-6:4-8\")\n  assert_entry(\"@b\", Entry::InstanceVariable, \"/fake/path/foo.rb:4-10:4-12\")\n\n  entry = T.must(@index[\"@a\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::Class, owner)\n  assert_equal(\"Foo::Bar\", owner.name)\n\n  entry = T.must(@index[\"@b\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::Class, owner)\n  assert_equal(\"Foo::Bar\", owner.name)\nend\n")

#test_instance_variable_writeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 8

def test_instance_variable_write
  index("    module Foo\n      class Bar\n        def initialize\n          # Hello\n          @a = 1\n        end\n      end\n    end\n  RUBY\n\n  assert_entry(\"@a\", Entry::InstanceVariable, \"/fake/path/foo.rb:4-6:4-8\")\n\n  entry = T.must(@index[\"@a\"]&.first)\n  owner = T.must(entry.owner)\n  assert_instance_of(Entry::Class, owner)\n  assert_equal(\"Foo::Bar\", owner.name)\nend\n")

#test_top_level_instance_variablesObject



167
168
169
170
171
172
173
174
# File 'lib/ruby_indexer/test/instance_variables_test.rb', line 167

def test_top_level_instance_variables
  index("    @a = 123\n  RUBY\n\n  entry = T.must(@index[\"@a\"]&.first)\n  assert_nil(entry.owner)\nend\n")