starscope 1.3.3 → 1.4.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.
@@ -1,21 +1,20 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  describe Starscope::Exportable do
4
-
5
4
  before do
6
5
  @db = Starscope::DB.new(Starscope::Output.new(:quiet))
7
6
  @db.add_paths([FIXTURES])
8
7
  @buf = StringIO.new
9
8
  end
10
9
 
11
- it "must export to ctags" do
10
+ it 'must export to ctags' do
12
11
  @db.export_to(:ctags, @buf)
13
12
  @buf.rewind
14
13
  lines = @buf.lines.to_a
15
14
  lines.must_include "NoTableError\t#{FIXTURES}/sample_ruby.rb\t/^ class NoTableError < StandardError; end$/;\"\tkind:c\tlanguage:Ruby\n"
16
15
  end
17
16
 
18
- it "must export to cscope" do
17
+ it 'must export to cscope' do
19
18
  @db.export_to(:cscope, @buf)
20
19
  @buf.rewind
21
20
  lines = @buf.lines.to_a
@@ -24,11 +23,10 @@ describe Starscope::Exportable do
24
23
  lines.must_include "\tgSunday\n"
25
24
  lines.must_include "\t`add_file\n"
26
25
  lines.must_include "\t}}\n"
27
- lines.must_include "13 class \n"
26
+ lines.must_include "12 class \n"
28
27
 
29
28
  lines.wont_include "= [\n"
30
29
  lines.wont_include "4 LANGS = [\n"
31
30
  lines.wont_include "116 tmpdb[entry[:file]][entry[:line_no]] ||= []\n"
32
31
  end
33
-
34
32
  end
@@ -0,0 +1,38 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe Starscope::FragmentExtractor do
4
+ module ::Starscope::Lang::Dummy; end
5
+
6
+ before do
7
+ @extractor = Starscope::FragmentExtractor.new(:Dummy, [
8
+ { :frag => "def foo; end\n", :line_no => 12 },
9
+ { :frag => "def bar\n", :line_no => 15 },
10
+ { :frag => "end\n", :line_no => 29 }
11
+ ])
12
+ @reconstructed = "def foo; end\ndef bar\nend"
13
+ end
14
+
15
+ it 'must pass reconstructed text to the child' do
16
+ ::Starscope::Lang::Dummy.expects(:extract).with(:foo, @reconstructed)
17
+ @extractor.extract(:foo, '---')
18
+ end
19
+
20
+ it 'must pass along extractor metadata from the child' do
21
+ ::Starscope::Lang::Dummy.expects(:extract).returns :a => 1, :b => 3
22
+ @extractor.extract(:foo, '---').must_equal :a => 1, :b => 3
23
+ end
24
+
25
+ it 'must pass along the name from the child' do
26
+ @extractor.name.must_equal ::Starscope::Lang::Dummy.name
27
+ end
28
+
29
+ it 'must override-merge yielded args based on line number' do
30
+ ::Starscope::Lang::Dummy.expects(:extract).yields(:foo, :bar, :line_no => 2, :foo => :bar)
31
+
32
+ @extractor.extract(:foo, '---') do |tbl, name, args|
33
+ tbl.must_equal :foo
34
+ name.must_equal :bar
35
+ args.must_equal :line_no => 15, :foo => :bar
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ describe Starscope::Lang::ERB do
4
+ before do
5
+ @frags = []
6
+ Starscope::Lang::ERB.extract(ERB_SAMPLE, File.read(ERB_SAMPLE)) do |tbl, name, args|
7
+ tbl.must_equal FRAGMENT
8
+ name.must_equal :Ruby
9
+ @frags << args
10
+ end
11
+ end
12
+
13
+ it 'must match erb files' do
14
+ Starscope::Lang::ERB.match_file(ERB_SAMPLE).must_equal true
15
+ end
16
+
17
+ it 'must not match non-erb files' do
18
+ Starscope::Lang::ERB.match_file(GOLANG_SAMPLE).must_equal false
19
+ Starscope::Lang::ERB.match_file(EMPTY_FILE).must_equal false
20
+ end
21
+
22
+ it 'must identify all fragments' do
23
+ @frags.must_equal [{ :frag => ' if foo ', :line_no => 1 },
24
+ { :frag => ' elsif bar ', :line_no => 3 },
25
+ { :frag => ' end ', :line_no => 5 },
26
+ { :frag => ' case x', :line_no => 8 },
27
+ { :frag => 'when :bar ', :line_no => 9 },
28
+ { :frag => ' magic ', :line_no => 9 },
29
+ { :frag => ' when :baz', :line_no => 9 },
30
+ { :frag => 'when :foo ', :line_no => 10 },
31
+ { :frag => ' end ', :line_no => 12 },
32
+ { :frag => ' foo ', :line_no => 14 },
33
+ { :frag => ' bar ', :line_no => 14 },
34
+ { :frag => ' baz ', :line_no => 14 }]
35
+ end
36
+ end
@@ -3,24 +3,24 @@ require File.expand_path('../../../test_helper', __FILE__)
3
3
  describe Starscope::Lang::Go do
4
4
  before do
5
5
  @db = {}
6
- Starscope::Lang::Go.extract(GOLANG_SAMPLE) do |tbl, name, args|
6
+ Starscope::Lang::Go.extract(GOLANG_SAMPLE, File.read(GOLANG_SAMPLE)) do |tbl, name, args|
7
7
  @db[tbl] ||= []
8
8
  @db[tbl] << Starscope::DB.normalize_record(GOLANG_SAMPLE, name, args)
9
9
  end
10
10
  end
11
11
 
12
- it "must match golang files" do
12
+ it 'must match golang files' do
13
13
  Starscope::Lang::Go.match_file(GOLANG_SAMPLE).must_equal true
14
14
  end
15
15
 
16
- it "must not match non-golang files" do
16
+ it 'must not match non-golang files' do
17
17
  Starscope::Lang::Go.match_file(RUBY_SAMPLE).must_equal false
18
18
  Starscope::Lang::Go.match_file(EMPTY_FILE).must_equal false
19
19
  end
20
20
 
21
- it "must identify definitions" do
21
+ it 'must identify definitions' do
22
22
  @db.keys.must_include :defs
23
- defs = @db[:defs].map {|x| x[:name][-1]}
23
+ defs = @db[:defs].map { |x| x[:name][-1] }
24
24
 
25
25
  defs.must_include :a
26
26
  defs.must_include :b
@@ -40,14 +40,14 @@ describe Starscope::Lang::Go do
40
40
  defs.wont_include :"0x03"
41
41
  end
42
42
 
43
- it "must identify endings" do
43
+ it 'must identify endings' do
44
44
  @db.keys.must_include :end
45
45
  @db[:end].count.must_equal 7
46
46
  end
47
47
 
48
- it "must identify function calls" do
48
+ it 'must identify function calls' do
49
49
  @db.keys.must_include :calls
50
- calls = @db[:calls].group_by {|x| x[:name][-1]}
50
+ calls = @db[:calls].group_by { |x| x[:name][-1] }
51
51
 
52
52
  calls.keys.must_include :a
53
53
  calls.keys.must_include :b
@@ -62,9 +62,9 @@ describe Starscope::Lang::Go do
62
62
  calls[:Errorf].count.must_equal 1
63
63
  end
64
64
 
65
- it "must identify variable assignments" do
65
+ it 'must identify variable assignments' do
66
66
  @db.keys.must_include :assigns
67
- assigns = @db[:assigns].group_by {|x| x[:name][-1]}
67
+ assigns = @db[:assigns].group_by { |x| x[:name][-1] }
68
68
 
69
69
  assigns.keys.must_include :x
70
70
  assigns.keys.must_include :y
@@ -80,14 +80,14 @@ describe Starscope::Lang::Go do
80
80
  assigns[:m].count.must_equal 2
81
81
  end
82
82
 
83
- it "must identify imports" do
83
+ it 'must identify imports' do
84
84
  @db.keys.must_include :imports
85
- imports = @db[:imports].group_by {|x| x[:name][-1]}
85
+ imports = @db[:imports].group_by { |x| x[:name][-1] }
86
86
 
87
87
  imports.keys.must_include :fmt
88
88
  end
89
89
 
90
- it "must correctly find the end of string constants" do
90
+ it 'must correctly find the end of string constants' do
91
91
  Starscope::Lang::Go.find_end_of_string('"123"foo', 0).must_equal 4
92
92
  Starscope::Lang::Go.find_end_of_string('a"123"foo', 0).must_equal 1
93
93
  Starscope::Lang::Go.find_end_of_string('a"123"foo', 1).must_equal 5
@@ -3,25 +3,25 @@ require File.expand_path('../../../test_helper', __FILE__)
3
3
  describe Starscope::Lang::Ruby do
4
4
  before do
5
5
  @db = {}
6
- Starscope::Lang::Ruby.extract(RUBY_SAMPLE) do |tbl, name, args|
6
+ Starscope::Lang::Ruby.extract(RUBY_SAMPLE, File.read(RUBY_SAMPLE)) do |tbl, name, args|
7
7
  @db[tbl] ||= []
8
8
  @db[tbl] << Starscope::DB.normalize_record(RUBY_SAMPLE, name, args)
9
9
  end
10
10
  end
11
11
 
12
- it "must match ruby files" do
12
+ it 'must match ruby files' do
13
13
  Starscope::Lang::Ruby.match_file(RUBY_SAMPLE).must_equal true
14
14
  Starscope::Lang::Ruby.match_file('bin/starscope').must_equal true
15
15
  end
16
16
 
17
- it "must not match non-ruby files" do
17
+ it 'must not match non-ruby files' do
18
18
  Starscope::Lang::Ruby.match_file(GOLANG_SAMPLE).must_equal false
19
19
  Starscope::Lang::Ruby.match_file(EMPTY_FILE).must_equal false
20
20
  end
21
21
 
22
- it "must identify function definitions" do
22
+ it 'must identify function definitions' do
23
23
  @db.keys.must_include :defs
24
- defs = @db[:defs].map {|x| x[:name][-1]}
24
+ defs = @db[:defs].map { |x| x[:name][-1] }
25
25
 
26
26
  defs.must_include :DB
27
27
  defs.must_include :NoTableError
@@ -30,18 +30,18 @@ describe Starscope::Lang::Ruby do
30
30
  defs.must_include :files_from_path
31
31
  end
32
32
 
33
- it "must identify constant definitions" do
34
- @db[:defs].map {|x| x[:name][-1]}.must_include :PBAR_FORMAT
33
+ it 'must identify constant definitions' do
34
+ @db[:defs].map { |x| x[:name][-1] }.must_include :PBAR_FORMAT
35
35
  end
36
36
 
37
- it "must identify endings" do
37
+ it 'must identify endings' do
38
38
  @db.keys.must_include :end
39
39
  @db[:end].count.must_equal 13
40
40
  end
41
41
 
42
- it "must identify function calls" do
42
+ it 'must identify function calls' do
43
43
  @db.keys.must_include :calls
44
- calls = @db[:calls].group_by {|x| x[:name][-1]}
44
+ calls = @db[:calls].group_by { |x| x[:name][-1] }
45
45
 
46
46
  calls.keys.must_include :add_file
47
47
  calls.keys.must_include :each
@@ -49,9 +49,9 @@ describe Starscope::Lang::Ruby do
49
49
  calls[:each].count.must_equal 8
50
50
  end
51
51
 
52
- it "must identify variable assignments" do
52
+ it 'must identify variable assignments' do
53
53
  @db.keys.must_include :assigns
54
- assigns = @db[:assigns].group_by {|x| x[:name][-1]}
54
+ assigns = @db[:assigns].group_by { |x| x[:name][-1] }
55
55
 
56
56
  assigns.keys.must_include :pbar
57
57
  assigns.keys.must_include :PBAR_FORMAT
@@ -60,7 +60,7 @@ describe Starscope::Lang::Ruby do
60
60
  assigns[:PBAR_FORMAT].count.must_equal 1
61
61
  assigns[:foo].count.must_equal 1
62
62
 
63
- assigns.keys.wont_include "=".to_sym
64
- assigns.keys.wont_include "<".to_sym
63
+ assigns.keys.wont_include '='.to_sym
64
+ assigns.keys.wont_include '<'.to_sym
65
65
  end
66
66
  end
@@ -1,29 +1,27 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  describe Starscope::Output do
4
-
5
- it "must be quiet" do
4
+ it 'must be quiet' do
6
5
  buf = StringIO.new
7
6
  out = Starscope::Output.new(:quiet, buf)
8
- out.normal("foo")
9
- out.extra("foo")
7
+ out.normal('foo')
8
+ out.extra('foo')
10
9
  buf.size.must_equal 0
11
10
  end
12
11
 
13
- it "must be normal" do
12
+ it 'must be normal' do
14
13
  buf = StringIO.new
15
14
  out = Starscope::Output.new(:normal, buf)
16
- out.normal("foo")
17
- out.extra("foo")
15
+ out.normal('foo')
16
+ out.extra('foo')
18
17
  buf.size.must_equal 4
19
18
  end
20
19
 
21
- it "must be verbose" do
20
+ it 'must be verbose' do
22
21
  buf = StringIO.new
23
22
  out = Starscope::Output.new(:verbose, buf)
24
- out.normal("foo")
25
- out.extra("foo")
23
+ out.normal('foo')
24
+ out.extra('foo')
26
25
  buf.size.must_equal 8
27
26
  end
28
-
29
27
  end
@@ -1,11 +1,10 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  describe Starscope::Queryable do
4
-
5
4
  SAMPLE_RECORDS = [
6
- {:name => [:"[abc"], :foo => "baz"},
7
- {:name => [:"not a match"], :foo => "bar", :x => "y"},
8
- {:name => [:a, :b, :c, :d], :file => :somefile},
5
+ { :name => [:"[abc"], :foo => 'baz' },
6
+ { :name => [:"not a match"], :foo => 'bar', :x => 'y' },
7
+ { :name => [:a, :b, :c, :d], :file => :somefile }
9
8
  ]
10
9
 
11
10
  class MockQuerable
@@ -29,34 +28,34 @@ describe Starscope::Queryable do
29
28
  @mock = MockQuerable.new
30
29
  end
31
30
 
32
- it "must handle empty input" do
33
- @mock.query(:empty_table, "foo").must_be_empty
31
+ it 'must handle empty input' do
32
+ @mock.query(:empty_table, 'foo').must_be_empty
34
33
  end
35
34
 
36
- it "must handle scoped queries" do
37
- @mock.query(:mytable, "a::b::").must_equal [SAMPLE_RECORDS[2]]
35
+ it 'must handle scoped queries' do
36
+ @mock.query(:mytable, 'a::b::').must_equal [SAMPLE_RECORDS[2]]
38
37
  end
39
38
 
40
- it "must handle regex queries" do
41
- @mock.query(:mytable, "a[bc]{2}").must_equal [SAMPLE_RECORDS[0]]
39
+ it 'must handle regex queries' do
40
+ @mock.query(:mytable, 'a[bc]{2}').must_equal [SAMPLE_RECORDS[0]]
42
41
 
43
- @mock.query(:mytable, "a.*d").must_equal [SAMPLE_RECORDS[2]]
42
+ @mock.query(:mytable, 'a.*d').must_equal [SAMPLE_RECORDS[2]]
44
43
  end
45
44
 
46
- it "must handle malformed regexes" do
47
- @mock.query(:mytable, "[abc").must_equal [SAMPLE_RECORDS[0]]
45
+ it 'must handle malformed regexes' do
46
+ @mock.query(:mytable, '[abc').must_equal [SAMPLE_RECORDS[0]]
48
47
  end
49
48
 
50
- it "must handle simple filters" do
51
- @mock.query(:mytable, ".*", :foo => "bar").must_equal [SAMPLE_RECORDS[1]]
49
+ it 'must handle simple filters' do
50
+ @mock.query(:mytable, '.*', :foo => 'bar').must_equal [SAMPLE_RECORDS[1]]
52
51
  end
53
52
 
54
- it "must handle multiple filters" do
55
- @mock.query(:mytable, ".*", :foo => "bar", :x => "y").must_equal [SAMPLE_RECORDS[1]]
56
- @mock.query(:mytable, ".*", :foo => "bar", :x => "nope").must_be_empty
53
+ it 'must handle multiple filters' do
54
+ @mock.query(:mytable, '.*', :foo => 'bar', :x => 'y').must_equal [SAMPLE_RECORDS[1]]
55
+ @mock.query(:mytable, '.*', :foo => 'bar', :x => 'nope').must_be_empty
57
56
  end
58
57
 
59
- it "must handle filters on file properties" do
60
- @mock.query(:mytable, ".*", :lang => "ruby").must_equal [SAMPLE_RECORDS[2]]
58
+ it 'must handle filters on file properties' do
59
+ @mock.query(:mytable, '.*', :lang => 'ruby').must_equal [SAMPLE_RECORDS[2]]
61
60
  end
62
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Huus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-08 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.2.0.3
33
+ version: 2.2.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.2.0.3
40
+ version: 2.2.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ruby-progressbar
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +144,7 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".gitignore"
147
+ - ".rubocop.yml"
147
148
  - ".travis.yml"
148
149
  - CHANGELOG.md
149
150
  - Gemfile
@@ -158,7 +159,8 @@ files:
158
159
  - lib/starscope.rb
159
160
  - lib/starscope/db.rb
160
161
  - lib/starscope/exportable.rb
161
- - lib/starscope/langs/coffeescript.rb
162
+ - lib/starscope/fragment_extractor.rb
163
+ - lib/starscope/langs/erb.rb
162
164
  - lib/starscope/langs/go.rb
163
165
  - lib/starscope/langs/ruby.rb
164
166
  - lib/starscope/matcher.rb
@@ -167,18 +169,23 @@ files:
167
169
  - lib/starscope/version.rb
168
170
  - starscope.gemspec
169
171
  - test/fixtures/db_added_files.json
172
+ - test/fixtures/db_missing_language.json
170
173
  - test/fixtures/db_old.json.gz
171
174
  - test/fixtures/db_old_extractor.json
175
+ - test/fixtures/db_old_subextractor.json
172
176
  - test/fixtures/db_out_of_date.json
173
177
  - test/fixtures/db_removed_files.json
174
178
  - test/fixtures/db_up_to_date.json
175
179
  - test/fixtures/empty
180
+ - test/fixtures/sample_erb.erb
176
181
  - test/fixtures/sample_golang.go
177
182
  - test/fixtures/sample_ruby.rb
178
183
  - test/functional/starscope_test.rb
179
184
  - test/test_helper.rb
180
185
  - test/unit/db_test.rb
181
186
  - test/unit/exportable_test.rb
187
+ - test/unit/fragment_extractor_test.rb
188
+ - test/unit/langs/erb_test.rb
182
189
  - test/unit/langs/golang_test.rb
183
190
  - test/unit/langs/ruby_test.rb
184
191
  - test/unit/output_test.rb
@@ -203,24 +210,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
210
  version: '0'
204
211
  requirements: []
205
212
  rubyforge_project:
206
- rubygems_version: 2.2.2
213
+ rubygems_version: 2.2.3
207
214
  signing_key:
208
215
  specification_version: 4
209
216
  summary: A code indexer and analyzer
210
217
  test_files:
211
218
  - test/fixtures/db_added_files.json
219
+ - test/fixtures/db_missing_language.json
212
220
  - test/fixtures/db_old.json.gz
213
221
  - test/fixtures/db_old_extractor.json
222
+ - test/fixtures/db_old_subextractor.json
214
223
  - test/fixtures/db_out_of_date.json
215
224
  - test/fixtures/db_removed_files.json
216
225
  - test/fixtures/db_up_to_date.json
217
226
  - test/fixtures/empty
227
+ - test/fixtures/sample_erb.erb
218
228
  - test/fixtures/sample_golang.go
219
229
  - test/fixtures/sample_ruby.rb
220
230
  - test/functional/starscope_test.rb
221
231
  - test/test_helper.rb
222
232
  - test/unit/db_test.rb
223
233
  - test/unit/exportable_test.rb
234
+ - test/unit/fragment_extractor_test.rb
235
+ - test/unit/langs/erb_test.rb
224
236
  - test/unit/langs/golang_test.rb
225
237
  - test/unit/langs/ruby_test.rb
226
238
  - test/unit/output_test.rb