starscope 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,98 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ describe Starscope::Lang::Go do
4
+ before do
5
+ @db = {}
6
+ Starscope::Lang::Go.extract(GOLANG_SAMPLE) do |tbl, name, args|
7
+ @db[tbl] ||= []
8
+ @db[tbl] << Starscope::DB.normalize_record(GOLANG_SAMPLE, name, args)
9
+ end
10
+ end
11
+
12
+ it "must match golang files" do
13
+ Starscope::Lang::Go.match_file(GOLANG_SAMPLE).must_equal true
14
+ end
15
+
16
+ it "must not match non-golang files" do
17
+ Starscope::Lang::Go.match_file(RUBY_SAMPLE).must_equal false
18
+ Starscope::Lang::Go.match_file(EMPTY_FILE).must_equal false
19
+ end
20
+
21
+ it "must identify definitions" do
22
+ @db.keys.must_include :defs
23
+ defs = @db[:defs].map {|x| x[:name][-1]}
24
+
25
+ defs.must_include :a
26
+ defs.must_include :b
27
+ defs.must_include :c
28
+ defs.must_include :ttt
29
+ defs.must_include :main
30
+ defs.must_include :v1
31
+ defs.must_include :v2
32
+ defs.must_include :Sunday
33
+ defs.must_include :Monday
34
+ defs.must_include :single_var
35
+ defs.must_include :single_const
36
+
37
+ defs.wont_include :"0x00"
38
+ defs.wont_include :"0x01"
39
+ defs.wont_include :"0x02"
40
+ defs.wont_include :"0x03"
41
+ end
42
+
43
+ it "must identify endings" do
44
+ @db.keys.must_include :end
45
+ @db[:end].count.must_equal 7
46
+ end
47
+
48
+ it "must identify function calls" do
49
+ @db.keys.must_include :calls
50
+ calls = @db[:calls].group_by {|x| x[:name][-1]}
51
+
52
+ calls.keys.must_include :a
53
+ calls.keys.must_include :b
54
+ calls.keys.must_include :c
55
+ calls.keys.must_include :ttt
56
+ calls.keys.must_include :Errorf
57
+
58
+ calls[:a].count.must_equal 3
59
+ calls[:b].count.must_equal 4
60
+ calls[:c].count.must_equal 4
61
+ calls[:ttt].count.must_equal 2
62
+ calls[:Errorf].count.must_equal 1
63
+ end
64
+
65
+ it "must identify variable assignments" do
66
+ @db.keys.must_include :assigns
67
+ assigns = @db[:assigns].group_by {|x| x[:name][-1]}
68
+
69
+ assigns.keys.must_include :x
70
+ assigns.keys.must_include :y
71
+ assigns.keys.must_include :z
72
+ assigns.keys.must_include :n
73
+ assigns.keys.must_include :m
74
+ assigns.keys.must_include :msg
75
+
76
+ assigns[:x].count.must_equal 2
77
+ assigns[:y].count.must_equal 1
78
+ assigns[:z].count.must_equal 1
79
+ assigns[:n].count.must_equal 1
80
+ assigns[:m].count.must_equal 2
81
+ end
82
+
83
+ it "must identify imports" do
84
+ @db.keys.must_include :imports
85
+ imports = @db[:imports].group_by {|x| x[:name][-1]}
86
+
87
+ imports.keys.must_include :fmt
88
+ end
89
+
90
+ it "must correctly find the end of string constants" do
91
+ Starscope::Lang::Go.find_end_of_string('"123"foo', 0).must_equal 4
92
+ Starscope::Lang::Go.find_end_of_string('a"123"foo', 0).must_equal 1
93
+ Starscope::Lang::Go.find_end_of_string('a"123"foo', 1).must_equal 5
94
+ Starscope::Lang::Go.find_end_of_string('"1\""foo', 0).must_equal 4
95
+ Starscope::Lang::Go.find_end_of_string('"1\\""foo', 0).must_equal 4
96
+ Starscope::Lang::Go.find_end_of_string('"1\\\\\"foo', 0).must_equal 9
97
+ end
98
+ end
@@ -0,0 +1,66 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ describe Starscope::Lang::Ruby do
4
+ before do
5
+ @db = {}
6
+ Starscope::Lang::Ruby.extract(RUBY_SAMPLE) do |tbl, name, args|
7
+ @db[tbl] ||= []
8
+ @db[tbl] << Starscope::DB.normalize_record(RUBY_SAMPLE, name, args)
9
+ end
10
+ end
11
+
12
+ it "must match ruby files" do
13
+ Starscope::Lang::Ruby.match_file(RUBY_SAMPLE).must_equal true
14
+ Starscope::Lang::Ruby.match_file('bin/starscope').must_equal true
15
+ end
16
+
17
+ it "must not match non-ruby files" do
18
+ Starscope::Lang::Ruby.match_file(GOLANG_SAMPLE).must_equal false
19
+ Starscope::Lang::Ruby.match_file(EMPTY_FILE).must_equal false
20
+ end
21
+
22
+ it "must identify function definitions" do
23
+ @db.keys.must_include :defs
24
+ defs = @db[:defs].map {|x| x[:name][-1]}
25
+
26
+ defs.must_include :DB
27
+ defs.must_include :NoTableError
28
+ defs.must_include :load
29
+ defs.must_include :update
30
+ defs.must_include :files_from_path
31
+ end
32
+
33
+ it "must identify constant definitions" do
34
+ @db[:defs].map {|x| x[:name][-1]}.must_include :PBAR_FORMAT
35
+ end
36
+
37
+ it "must identify endings" do
38
+ @db.keys.must_include :end
39
+ @db[:end].count.must_equal 13
40
+ end
41
+
42
+ it "must identify function calls" do
43
+ @db.keys.must_include :calls
44
+ calls = @db[:calls].group_by {|x| x[:name][-1]}
45
+
46
+ calls.keys.must_include :add_file
47
+ calls.keys.must_include :each
48
+ calls[:add_file].count.must_equal 3
49
+ calls[:each].count.must_equal 8
50
+ end
51
+
52
+ it "must identify variable assignments" do
53
+ @db.keys.must_include :assigns
54
+ assigns = @db[:assigns].group_by {|x| x[:name][-1]}
55
+
56
+ assigns.keys.must_include :pbar
57
+ assigns.keys.must_include :PBAR_FORMAT
58
+ assigns.keys.must_include :foo
59
+ assigns[:pbar].count.must_equal 2
60
+ assigns[:PBAR_FORMAT].count.must_equal 1
61
+ assigns[:foo].count.must_equal 1
62
+
63
+ assigns.keys.wont_include "=".to_sym
64
+ assigns.keys.wont_include "<".to_sym
65
+ end
66
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
- describe StarScope::Matcher do
3
+ describe Starscope::Matcher do
4
4
 
5
5
  SAMPLE_RECORDS = [
6
6
  {:name => [:"[abc"]},
@@ -9,25 +9,25 @@ describe StarScope::Matcher do
9
9
  ]
10
10
 
11
11
  it "must handle empty input" do
12
- matcher = StarScope::Matcher.new("foo", [])
12
+ matcher = Starscope::Matcher.new("foo", [])
13
13
  matcher.query.must_be_empty
14
14
  end
15
15
 
16
16
  it "must handle scoped queries" do
17
- matcher = StarScope::Matcher.new("a::b::", SAMPLE_RECORDS)
17
+ matcher = Starscope::Matcher.new("a::b::", SAMPLE_RECORDS)
18
18
  matcher.query.must_equal [SAMPLE_RECORDS[2]]
19
19
  end
20
20
 
21
21
  it "must handle regex queries" do
22
- matcher = StarScope::Matcher.new("a[bc]{2}", SAMPLE_RECORDS)
22
+ matcher = Starscope::Matcher.new("a[bc]{2}", SAMPLE_RECORDS)
23
23
  matcher.query.must_equal [SAMPLE_RECORDS[0]]
24
24
 
25
- matcher = StarScope::Matcher.new("a.*d", SAMPLE_RECORDS)
25
+ matcher = Starscope::Matcher.new("a.*d", SAMPLE_RECORDS)
26
26
  matcher.query.must_equal [SAMPLE_RECORDS[2]]
27
27
  end
28
28
 
29
29
  it "must handle malformed regexes" do
30
- matcher = StarScope::Matcher.new("[abc", SAMPLE_RECORDS)
30
+ matcher = Starscope::Matcher.new("[abc", SAMPLE_RECORDS)
31
31
  matcher.query.must_equal [SAMPLE_RECORDS[0]]
32
32
  end
33
33
 
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe Starscope::Output do
4
+
5
+ it "must be quiet" do
6
+ buf = StringIO.new
7
+ out = Starscope::Output.new(:quiet, buf)
8
+ out.normal("foo")
9
+ out.extra("foo")
10
+ buf.size.must_equal 0
11
+ end
12
+
13
+ it "must be normal" do
14
+ buf = StringIO.new
15
+ out = Starscope::Output.new(:normal, buf)
16
+ out.normal("foo")
17
+ out.extra("foo")
18
+ buf.size.must_equal 4
19
+ end
20
+
21
+ it "must be verbose" do
22
+ buf = StringIO.new
23
+ out = Starscope::Output.new(:verbose, buf)
24
+ out.normal("foo")
25
+ out.extra("foo")
26
+ buf.size.must_equal 8
27
+ end
28
+
29
+ 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.1.2
4
+ version: 1.2.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: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: mocha
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: A tool like the venerable cscope, but for ruby, golang and other languages
112
126
  email: eapache@gmail.com
113
127
  executables:
@@ -129,25 +143,31 @@ files:
129
143
  - doc/USER_GUIDE.md
130
144
  - lib/starscope.rb
131
145
  - lib/starscope/db.rb
146
+ - lib/starscope/export.rb
132
147
  - lib/starscope/langs/coffeescript.rb
133
148
  - lib/starscope/langs/go.rb
134
149
  - lib/starscope/langs/ruby.rb
135
150
  - lib/starscope/matcher.rb
136
151
  - lib/starscope/output.rb
137
- - lib/starscope/record.rb
138
152
  - lib/starscope/version.rb
139
153
  - starscope.gemspec
154
+ - test/fixtures/db_added_files.json
140
155
  - test/fixtures/db_old.json.gz
156
+ - test/fixtures/db_old_extractor.json
157
+ - test/fixtures/db_out_of_date.json
158
+ - test/fixtures/db_removed_files.json
159
+ - test/fixtures/db_up_to_date.json
141
160
  - test/fixtures/empty
142
161
  - test/fixtures/sample_golang.go
143
162
  - test/fixtures/sample_ruby.rb
144
- - test/functional/test_starscope.rb
163
+ - test/functional/starscope_test.rb
145
164
  - test/test_helper.rb
146
- - test/unit/test_db.rb
147
- - test/unit/test_golang.rb
148
- - test/unit/test_matcher.rb
149
- - test/unit/test_record.rb
150
- - test/unit/test_ruby.rb
165
+ - test/unit/db_test.rb
166
+ - test/unit/export_test.rb
167
+ - test/unit/langs/golang_test.rb
168
+ - test/unit/langs/ruby_test.rb
169
+ - test/unit/matcher_test.rb
170
+ - test/unit/output_test.rb
151
171
  homepage: https://github.com/eapache/starscope
152
172
  licenses:
153
173
  - MIT
@@ -173,14 +193,20 @@ signing_key:
173
193
  specification_version: 4
174
194
  summary: A code indexer and analyzer
175
195
  test_files:
196
+ - test/fixtures/db_added_files.json
176
197
  - test/fixtures/db_old.json.gz
198
+ - test/fixtures/db_old_extractor.json
199
+ - test/fixtures/db_out_of_date.json
200
+ - test/fixtures/db_removed_files.json
201
+ - test/fixtures/db_up_to_date.json
177
202
  - test/fixtures/empty
178
203
  - test/fixtures/sample_golang.go
179
204
  - test/fixtures/sample_ruby.rb
180
- - test/functional/test_starscope.rb
205
+ - test/functional/starscope_test.rb
181
206
  - test/test_helper.rb
182
- - test/unit/test_db.rb
183
- - test/unit/test_golang.rb
184
- - test/unit/test_matcher.rb
185
- - test/unit/test_record.rb
186
- - test/unit/test_ruby.rb
207
+ - test/unit/db_test.rb
208
+ - test/unit/export_test.rb
209
+ - test/unit/langs/golang_test.rb
210
+ - test/unit/langs/ruby_test.rb
211
+ - test/unit/matcher_test.rb
212
+ - test/unit/output_test.rb
@@ -1,98 +0,0 @@
1
- class StarScope::Record
2
-
3
- @@cachedFile = nil
4
- @@cachedLines = nil
5
-
6
- def self.build(file, name, args)
7
- args[:file] = file
8
-
9
- if name.is_a? Array
10
- args[:name] = name.map {|x| x.to_sym}
11
- else
12
- args[:name] = [name.to_sym]
13
- end
14
-
15
- if args[:line_no]
16
- if @@cachedFile != file
17
- @@cachedFile = file
18
- @@cachedLines = File.readlines(file)
19
- end
20
-
21
- args[:line] = @@cachedLines[args[:line_no]-1].chomp
22
- end
23
-
24
- args
25
- end
26
-
27
- def self.format(rec)
28
- "#{rec[:name].join " "} -- #{rec[:file]}:#{rec[:line_no]} (#{rec[:line].strip})"
29
- end
30
-
31
- def self.ctag_line(rec, file)
32
- ret = "#{rec[:name][-1]}\t#{rec[:file]}\t/^#{rec[:line]}$/"
33
-
34
- ext = self.ctag_ext_tags(rec, file)
35
- if not ext.empty?
36
- ret << ";\""
37
- ext.sort.each do |k, v|
38
- ret << "\t#{k}:#{v}"
39
- end
40
- end
41
-
42
- ret
43
- end
44
-
45
- def self.ctag_ext_tags(rec, file)
46
- tag = {}
47
-
48
- # these extensions are documented at http://ctags.sourceforge.net/FORMAT
49
- case rec[:type]
50
- when :func
51
- tag["kind"] = "f"
52
- when :module, :class
53
- tag["kind"] = "c"
54
- end
55
-
56
- tag["language"] = file[:lang]
57
-
58
- tag
59
- end
60
-
61
- def self.cscope_mark(tbl, rec)
62
- case tbl
63
- when :end
64
- case rec[:type]
65
- when :func
66
- ret = "}"
67
- else
68
- return ""
69
- end
70
- when :file
71
- ret = "@"
72
- when :defs
73
- case rec[:type]
74
- when :func
75
- ret = "$"
76
- when :class, :module
77
- ret = "c"
78
- when :type
79
- ret = "t"
80
- else
81
- ret = "g"
82
- end
83
- when :calls
84
- ret = "`"
85
- when :requires
86
- ret = "~\""
87
- when :imports
88
- ret = "~<"
89
- when :assigns
90
- ret = "="
91
- else
92
- return ""
93
- end
94
-
95
- return "\t" + ret
96
- end
97
-
98
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- class TestStarScope < Minitest::Test
4
-
5
- BASE = "bundle exec bin/starscope --quiet"
6
- EXTRACT = "#{BASE} --no-read --no-write #{FIXTURES}"
7
-
8
- def test_help
9
- `#{BASE} -h`.each_line do |line|
10
- assert line.length <= 80
11
- end
12
- end
13
-
14
- def test_version
15
- assert_equal StarScope::VERSION, `#{BASE} -v`.chomp
16
- end
17
-
18
- def test_summary
19
- lines = `#{EXTRACT} -s`.lines.to_a
20
- assert_equal lines.length, 6
21
- end
22
-
23
- def test_dump
24
- lines = `#{EXTRACT} -d requires`.lines.to_a
25
- assert_equal 'date', lines[1].split.first
26
- assert_equal 'zlib', lines[2].split.first
27
- end
28
-
29
- def test_query
30
- `#{EXTRACT} -q calls,add_file`.each_line do |line|
31
- assert_equal ["StarScope", "DB", "add_file"], line.split[0..2]
32
- end
33
- end
34
-
35
- end