Class: RubyIndexer::ClassesAndModulesTest

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

Instance Method Summary collapse

Methods inherited from TestCase

#setup

Instance Method Details

#test_class_with_statementsObject



17
18
19
20
21
22
23
24
25
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 17

def test_class_with_statements
  index("    class Foo\n      def something; end\n    end\n  RUBY\n\n  assert_entry(\"Foo\", Index::Entry::Class, \"/fake/path/foo.rb:0-0:2-2\")\nend\n")

#test_colon_colon_classObject



27
28
29
30
31
32
33
34
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 27

def test_colon_colon_class
  index("    class ::Foo\n    end\n  RUBY\n\n  assert_entry(\"Foo\", Index::Entry::Class, \"/fake/path/foo.rb:0-0:1-2\")\nend\n")

#test_colon_colon_class_inside_classObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 36

def test_colon_colon_class_inside_class
  index("    class Bar\n      class ::Foo\n      end\n    end\n  RUBY\n\n  assert_entry(\"Bar\", Index::Entry::Class, \"/fake/path/foo.rb:0-0:3-2\")\n  assert_entry(\"Foo\", Index::Entry::Class, \"/fake/path/foo.rb:1-2:2-4\")\nend\n")

#test_colon_colon_moduleObject



85
86
87
88
89
90
91
92
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 85

def test_colon_colon_module
  index("    module ::Foo\n    end\n  RUBY\n\n  assert_entry(\"Foo\", Index::Entry::Module, \"/fake/path/foo.rb:0-0:1-2\")\nend\n")

#test_comments_can_be_attached_to_a_classObject



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/classes_and_modules_test.rb', line 147

def test_comments_can_be_attached_to_a_class
  index("    # This is method comment\n    def foo; end\n    # This is a Foo comment\n    # This is another Foo comment\n    class Foo\n      # This should not be attached\n    end\n\n    # Ignore me\n\n    # This Bar comment has 1 line padding\n\n    class Bar; end\n  RUBY\n\n  foo_entry = @index[\"Foo\"].first\n  assert_equal(\"This is a Foo comment\\nThis is another Foo comment\", foo_entry.comments.join(\"\\n\"))\n\n  bar_entry = @index[\"Bar\"].first\n  assert_equal(\"This Bar comment has 1 line padding\", bar_entry.comments.join(\"\\n\"))\nend\n")

#test_comments_can_be_attached_to_a_namespaced_classObject



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 171

def test_comments_can_be_attached_to_a_namespaced_class
  index("    # This is a Foo comment\n    # This is another Foo comment\n    class Foo\n      # This is a Bar comment\n      class Bar; end\n    end\n  RUBY\n\n  foo_entry = @index[\"Foo\"].first\n  assert_equal(\"This is a Foo comment\\nThis is another Foo comment\", foo_entry.comments.join(\"\\n\"))\n\n  bar_entry = @index[\"Foo::Bar\"].first\n  assert_equal(\"This is a Bar comment\", bar_entry.comments.join(\"\\n\"))\nend\n")

#test_comments_can_be_attached_to_a_reopened_classObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 188

def test_comments_can_be_attached_to_a_reopened_class
  index("    # This is a Foo comment\n    class Foo; end\n\n    # This is another Foo comment\n    class Foo; end\n  RUBY\n\n  first_foo_entry = @index[\"Foo\"][0]\n  assert_equal(\"This is a Foo comment\", first_foo_entry.comments.join(\"\\n\"))\n\n  second_foo_entry = @index[\"Foo\"][1]\n  assert_equal(\"This is another Foo comment\", second_foo_entry.comments.join(\"\\n\"))\nend\n")

#test_comments_removes_the_leading_pound_and_spaceObject



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 204

def test_comments_removes_the_leading_pound_and_space
  index("    # This is a Foo comment\n    class Foo; end\n\n    #This is a Bar comment\n    class Bar; end\n  RUBY\n\n  first_foo_entry = @index[\"Foo\"][0]\n  assert_equal(\"This is a Foo comment\", first_foo_entry.comments.join(\"\\n\"))\n\n  second_foo_entry = @index[\"Bar\"][0]\n  assert_equal(\"This is a Bar comment\", second_foo_entry.comments.join(\"\\n\"))\nend\n")

#test_deleting_from_index_based_on_file_pathObject



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 134

def test_deleting_from_index_based_on_file_path
  index("    class Foo\n    end\n  RUBY\n\n  assert_entry(\"Foo\", Index::Entry::Class, \"/fake/path/foo.rb:0-0:1-2\")\n\n  @index.delete(\"/fake/path/foo.rb\")\n  refute_entry(\"Foo\")\n  assert_empty(@index.instance_variable_get(:@files_to_entries))\nend\n")

#test_dynamically_namespaced_classObject



57
58
59
60
61
62
63
64
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 57

def test_dynamically_namespaced_class
  index("    class self::Bar\n    end\n  RUBY\n\n  refute_entry(\"self::Bar\")\nend\n")

#test_dynamically_namespaced_moduleObject



103
104
105
106
107
108
109
110
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 103

def test_dynamically_namespaced_module
  index("    module self::Bar\n    end\n  RUBY\n\n  refute_entry(\"self::Bar\")\nend\n")

#test_empty_statements_classObject



8
9
10
11
12
13
14
15
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 8

def test_empty_statements_class
  index("    class Foo\n    end\n  RUBY\n\n  assert_entry(\"Foo\", Index::Entry::Class, \"/fake/path/foo.rb:0-0:1-2\")\nend\n")

#test_empty_statements_moduleObject



66
67
68
69
70
71
72
73
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 66

def test_empty_statements_module
  index("    module Foo\n    end\n  RUBY\n\n  assert_entry(\"Foo\", Index::Entry::Module, \"/fake/path/foo.rb:0-0:1-2\")\nend\n")

#test_module_with_statementsObject



75
76
77
78
79
80
81
82
83
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 75

def test_module_with_statements
  index("    module Foo\n      def something; end\n    end\n  RUBY\n\n  assert_entry(\"Foo\", Index::Entry::Module, \"/fake/path/foo.rb:0-0:2-2\")\nend\n")

#test_namespaced_classObject



48
49
50
51
52
53
54
55
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 48

def test_namespaced_class
  index("    class Foo::Bar\n    end\n  RUBY\n\n  assert_entry(\"Foo::Bar\", Index::Entry::Class, \"/fake/path/foo.rb:0-0:1-2\")\nend\n")

#test_namespaced_moduleObject



94
95
96
97
98
99
100
101
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 94

def test_namespaced_module
  index("    module Foo::Bar\n    end\n  RUBY\n\n  assert_entry(\"Foo::Bar\", Index::Entry::Module, \"/fake/path/foo.rb:0-0:1-2\")\nend\n")

#test_nested_modules_and_classesObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ruby_indexer/test/classes_and_modules_test.rb', line 112

def test_nested_modules_and_classes
  index("    module Foo\n      class Bar\n      end\n\n      module Baz\n        class Qux\n          class Something\n          end\n        end\n      end\n    end\n  RUBY\n\n  assert_entry(\"Foo\", Index::Entry::Module, \"/fake/path/foo.rb:0-0:10-2\")\n  assert_entry(\"Foo::Bar\", Index::Entry::Class, \"/fake/path/foo.rb:1-2:2-4\")\n  assert_entry(\"Foo::Baz\", Index::Entry::Module, \"/fake/path/foo.rb:4-2:9-4\")\n  assert_entry(\"Foo::Baz::Qux\", Index::Entry::Class, \"/fake/path/foo.rb:5-4:8-6\")\n  assert_entry(\"Foo::Baz::Qux::Something\", Index::Entry::Class, \"/fake/path/foo.rb:6-6:7-8\")\nend\n")