starscope 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -2
- data/Gemfile.lock +5 -1
- data/README.md +5 -7
- data/Rakefile +1 -1
- data/bin/starscope +56 -48
- data/doc/DB_FORMAT.md +4 -4
- data/doc/LANGUAGE_SUPPORT.md +8 -4
- data/doc/USER_GUIDE.md +36 -9
- data/lib/starscope/db.rb +150 -265
- data/lib/starscope/export.rb +256 -0
- data/lib/starscope/langs/coffeescript.rb +2 -1
- data/lib/starscope/langs/go.rb +20 -2
- data/lib/starscope/langs/ruby.rb +60 -71
- data/lib/starscope/matcher.rb +1 -1
- data/lib/starscope/output.rb +9 -7
- data/lib/starscope/version.rb +2 -2
- data/starscope.gemspec +2 -1
- data/test/fixtures/db_added_files.json +8 -0
- data/test/fixtures/db_old_extractor.json +15 -0
- data/test/fixtures/db_out_of_date.json +15 -0
- data/test/fixtures/db_removed_files.json +12 -0
- data/test/fixtures/db_up_to_date.json +15 -0
- data/test/fixtures/sample_ruby.rb +21 -21
- data/test/functional/starscope_test.rb +57 -0
- data/test/test_helper.rb +1 -0
- data/test/unit/db_test.rb +141 -0
- data/test/unit/export_test.rb +34 -0
- data/test/unit/langs/golang_test.rb +98 -0
- data/test/unit/langs/ruby_test.rb +66 -0
- data/test/unit/{test_matcher.rb → matcher_test.rb} +6 -6
- data/test/unit/output_test.rb +29 -0
- metadata +41 -15
- data/lib/starscope/record.rb +0 -98
- data/test/functional/test_starscope.rb +0 -35
- data/test/unit/test_db.rb +0 -136
- data/test/unit/test_golang.rb +0 -80
- data/test/unit/test_record.rb +0 -35
- data/test/unit/test_ruby.rb +0 -60
data/test/unit/test_db.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'tempfile'
|
3
|
-
|
4
|
-
describe StarScope::DB do
|
5
|
-
|
6
|
-
def validate(db)
|
7
|
-
files = db.instance_eval('@meta[:files]')
|
8
|
-
files.keys.must_include GOLANG_SAMPLE
|
9
|
-
files.keys.must_include RUBY_SAMPLE
|
10
|
-
files[GOLANG_SAMPLE][:last_updated].must_equal File.mtime(GOLANG_SAMPLE).to_i
|
11
|
-
files[RUBY_SAMPLE][:last_updated].must_equal File.mtime(RUBY_SAMPLE).to_i
|
12
|
-
|
13
|
-
tbls = db.instance_eval('@tables')
|
14
|
-
defs = tbls[:defs].map {|x| x[:name][-1]}
|
15
|
-
assert defs.include? :DB
|
16
|
-
assert defs.include? :NoTableError
|
17
|
-
assert defs.include? :load
|
18
|
-
assert defs.include? :update
|
19
|
-
assert defs.include? :files_from_path
|
20
|
-
assert defs.include? :single_var
|
21
|
-
assert defs.include? :single_const
|
22
|
-
end
|
23
|
-
|
24
|
-
before do
|
25
|
-
@db = StarScope::DB.new(:quiet)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "must raise on invalid tables" do
|
29
|
-
proc {@db.dump_table(:foo)}.must_raise StarScope::DB::NoTableError
|
30
|
-
end
|
31
|
-
|
32
|
-
it "must add paths" do
|
33
|
-
paths = [GOLANG_SAMPLE, "#{FIXTURES}/**/*"]
|
34
|
-
@db.add_paths(paths)
|
35
|
-
@db.instance_eval('@meta[:paths]').must_equal paths
|
36
|
-
validate(@db)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "must add excludes" do
|
40
|
-
paths = [GOLANG_SAMPLE, "#{FIXTURES}/**/*"]
|
41
|
-
@db.add_paths(paths)
|
42
|
-
@db.add_excludes(["#{FIXTURES}/**"])
|
43
|
-
files = @db.instance_eval('@meta[:files]').keys
|
44
|
-
files.wont_include RUBY_SAMPLE
|
45
|
-
files.wont_include GOLANG_SAMPLE
|
46
|
-
tbls = @db.instance_eval('@tables')
|
47
|
-
tbls[:defs].must_be_empty
|
48
|
-
tbls[:end].must_be_empty
|
49
|
-
end
|
50
|
-
|
51
|
-
it "must pick up new files in old paths" do
|
52
|
-
@db.instance_eval("@meta[:paths] = [\"#{FIXTURES}/**/*\"]")
|
53
|
-
@db.update
|
54
|
-
validate(@db)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "must remove old files in existing paths" do
|
58
|
-
@db.instance_eval("@meta[:paths] = [\"#{FIXTURES}/**/*\"]")
|
59
|
-
@db.instance_eval("@meta[:files] = {\"#{FIXTURES}/foo\" => {:last_updated=>1}}")
|
60
|
-
@db.update
|
61
|
-
@db.instance_eval("@meta[:files]").keys.wont_include "#{FIXTURES}/foo"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "must update stale existing files" do
|
65
|
-
@db.instance_eval("@meta[:paths] = [\"#{FIXTURES}/**/*\"]")
|
66
|
-
@db.instance_eval("@meta[:files] = {\"#{GOLANG_SAMPLE}\" => {:last_updated=>1}}")
|
67
|
-
@db.instance_eval("@tables[:defs] = [{:file => \"#{GOLANG_SAMPLE}\"}]")
|
68
|
-
@db.update
|
69
|
-
validate(@db)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "must load an old DB file" do
|
73
|
-
@db.load("#{FIXTURES}/db_old.json.gz")
|
74
|
-
@db.instance_eval('@meta[:paths]').must_equal ["#{FIXTURES}/**/*"]
|
75
|
-
validate(@db)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "must round-trip a database" do
|
79
|
-
file = Tempfile.new('starscope_test')
|
80
|
-
begin
|
81
|
-
@db.add_paths(["#{FIXTURES}"])
|
82
|
-
@db.save(file.path)
|
83
|
-
tmp = StarScope::DB.new(:quiet)
|
84
|
-
tmp.load(file.path)
|
85
|
-
validate(tmp)
|
86
|
-
ensure
|
87
|
-
file.close
|
88
|
-
file.unlink
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it "must export to ctags" do
|
93
|
-
file = Tempfile.new('starscope_test')
|
94
|
-
begin
|
95
|
-
@db.add_paths(["#{FIXTURES}"])
|
96
|
-
@db.export_ctags(file)
|
97
|
-
file.rewind
|
98
|
-
lines = file.lines.to_a
|
99
|
-
lines.must_include "NoTableError\t#{FIXTURES}/sample_ruby.rb\t/^ class NoTableError < StandardError; end$/;\"\tkind:c\tlanguage:Ruby\n"
|
100
|
-
ensure
|
101
|
-
file.close
|
102
|
-
file.unlink
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
it "must export to cscope" do
|
107
|
-
file = Tempfile.new('starscope_test')
|
108
|
-
begin
|
109
|
-
@db.add_paths(["#{FIXTURES}"])
|
110
|
-
@db.export_cscope(file)
|
111
|
-
file.rewind
|
112
|
-
lines = file.lines.to_a
|
113
|
-
|
114
|
-
lines.must_include "\t@#{FIXTURES}/sample_golang.go\n"
|
115
|
-
lines.must_include "\tgSunday\n"
|
116
|
-
lines.must_include "\t`add_file\n"
|
117
|
-
lines.must_include "\t}}\n"
|
118
|
-
lines.must_include "13 class \n"
|
119
|
-
|
120
|
-
lines.wont_include "= [\n"
|
121
|
-
lines.wont_include "4 LANGS = [\n"
|
122
|
-
lines.wont_include "116 tmpdb[entry[:file]][entry[:line_no]] ||= []\n"
|
123
|
-
ensure
|
124
|
-
file.close
|
125
|
-
file.unlink
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
it "must run queries" do
|
130
|
-
@db.add_paths(["#{FIXTURES}"])
|
131
|
-
@db.query(:calls, "abc").must_equal []
|
132
|
-
@db.query(:defs, "xyz").must_equal []
|
133
|
-
@db.query(:calls, "add_file").length.must_equal 3
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
data/test/unit/test_golang.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class TestGolang < Minitest::Test
|
4
|
-
def setup
|
5
|
-
@db = {}
|
6
|
-
StarScope::Lang::Go.extract(GOLANG_SAMPLE) do |tbl, name, args|
|
7
|
-
@db[tbl] ||= []
|
8
|
-
@db[tbl] << StarScope::Record.build(GOLANG_SAMPLE, name, args)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_recognition
|
13
|
-
assert StarScope::Lang::Go.match_file(GOLANG_SAMPLE)
|
14
|
-
refute StarScope::Lang::Go.match_file(RUBY_SAMPLE)
|
15
|
-
refute StarScope::Lang::Go.match_file(EMPTY_FILE)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_defs
|
19
|
-
assert @db.keys.include? :defs
|
20
|
-
defs = @db[:defs].map {|x| x[:name][-1]}
|
21
|
-
assert defs.include? :a
|
22
|
-
assert defs.include? :b
|
23
|
-
assert defs.include? :c
|
24
|
-
assert defs.include? :ttt
|
25
|
-
assert defs.include? :main
|
26
|
-
assert defs.include? :v1
|
27
|
-
assert defs.include? :v2
|
28
|
-
assert defs.include? :Sunday
|
29
|
-
assert defs.include? :Monday
|
30
|
-
assert defs.include? :single_var
|
31
|
-
assert defs.include? :single_const
|
32
|
-
|
33
|
-
refute defs.include? :"0x00"
|
34
|
-
refute defs.include? :"0x01"
|
35
|
-
refute defs.include? :"0x02"
|
36
|
-
refute defs.include? :"0x03"
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_ends
|
40
|
-
assert @db.keys.include? :end
|
41
|
-
assert @db[:end].count == 7
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_function_calls
|
45
|
-
assert @db.keys.include? :calls
|
46
|
-
calls = @db[:calls].group_by {|x| x[:name][-1]}
|
47
|
-
assert calls.keys.include? :a
|
48
|
-
assert calls.keys.include? :b
|
49
|
-
assert calls.keys.include? :c
|
50
|
-
assert calls.keys.include? :ttt
|
51
|
-
assert calls.keys.include? :Errorf
|
52
|
-
assert calls[:a].count == 3
|
53
|
-
assert calls[:b].count == 4
|
54
|
-
assert calls[:c].count == 4
|
55
|
-
assert calls[:ttt].count == 2
|
56
|
-
assert calls[:Errorf].count == 1
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_variable_assigns
|
60
|
-
assert @db.keys.include? :assigns
|
61
|
-
assigns = @db[:assigns].group_by {|x| x[:name][-1]}
|
62
|
-
assert assigns.keys.include? :x
|
63
|
-
assert assigns.keys.include? :y
|
64
|
-
assert assigns.keys.include? :z
|
65
|
-
assert assigns.keys.include? :n
|
66
|
-
assert assigns.keys.include? :m
|
67
|
-
assert assigns.keys.include? :msg
|
68
|
-
assert assigns[:x].count == 2
|
69
|
-
assert assigns[:y].count == 1
|
70
|
-
assert assigns[:z].count == 1
|
71
|
-
assert assigns[:n].count == 1
|
72
|
-
assert assigns[:m].count == 2
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_imports
|
76
|
-
assert @db.keys.include? :imports
|
77
|
-
imports = @db[:imports].group_by {|x| x[:name][-1]}
|
78
|
-
assert imports.keys.include? :fmt
|
79
|
-
end
|
80
|
-
end
|
data/test/unit/test_record.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
describe StarScope::Record do
|
4
|
-
|
5
|
-
it "must symbolize compound name" do
|
6
|
-
rec = StarScope::Record.build(:foo, ["a", :b], {})
|
7
|
-
rec[:name].must_equal [:a, :b]
|
8
|
-
end
|
9
|
-
|
10
|
-
it "must symbolize and array-wrap simple name" do
|
11
|
-
rec = StarScope::Record.build(:foo, "a", {})
|
12
|
-
rec[:name].must_equal [:a]
|
13
|
-
end
|
14
|
-
|
15
|
-
it "must read correct line from file" do
|
16
|
-
|
17
|
-
# we interleave the files here to test the cache
|
18
|
-
|
19
|
-
rec = StarScope::Record.build(GOLANG_SAMPLE, :a, {:line_no => 1})
|
20
|
-
rec[:line].must_equal "package main"
|
21
|
-
|
22
|
-
rec = StarScope::Record.build(GOLANG_SAMPLE, :a, {:line_no => 71})
|
23
|
-
rec[:line].must_equal "\tfmt.Println(t)"
|
24
|
-
|
25
|
-
rec = StarScope::Record.build(RUBY_SAMPLE, :a, {:line_no => 1})
|
26
|
-
rec[:line].must_equal "require 'date'"
|
27
|
-
|
28
|
-
rec = StarScope::Record.build(RUBY_SAMPLE, :a, {:line_no => 164})
|
29
|
-
rec[:line].must_equal "end"
|
30
|
-
|
31
|
-
rec = StarScope::Record.build(GOLANG_SAMPLE, :a, {:line_no => 44})
|
32
|
-
rec[:line].must_equal "}"
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/test/unit/test_ruby.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class TestRuby < Minitest::Test
|
4
|
-
def setup
|
5
|
-
@db = {}
|
6
|
-
StarScope::Lang::Ruby.extract(RUBY_SAMPLE) do |tbl, name, args|
|
7
|
-
@db[tbl] ||= []
|
8
|
-
@db[tbl] << StarScope::Record.build(RUBY_SAMPLE, name, args)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_recognition
|
13
|
-
assert StarScope::Lang::Ruby.match_file(RUBY_SAMPLE)
|
14
|
-
assert StarScope::Lang::Ruby.match_file('bin/starscope')
|
15
|
-
refute StarScope::Lang::Ruby.match_file(GOLANG_SAMPLE)
|
16
|
-
refute StarScope::Lang::Ruby.match_file(EMPTY_FILE)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_function_defs
|
20
|
-
assert @db.keys.include? :defs
|
21
|
-
defs = @db[:defs].map {|x| x[:name][-1]}
|
22
|
-
assert defs.include? :DB
|
23
|
-
assert defs.include? :NoTableError
|
24
|
-
assert defs.include? :load
|
25
|
-
assert defs.include? :update
|
26
|
-
assert defs.include? :files_from_path
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_constant_defs
|
30
|
-
assert @db[:defs].map {|x| x[:name][-1]}.include? :PBAR_FORMAT
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_ends
|
34
|
-
assert @db.keys.include? :end
|
35
|
-
assert @db[:end].count == 13
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_function_calls
|
39
|
-
assert @db.keys.include? :calls
|
40
|
-
calls = @db[:calls].group_by {|x| x[:name][-1]}
|
41
|
-
assert calls.keys.include? :add_file
|
42
|
-
assert calls.keys.include? :each
|
43
|
-
assert calls[:add_file].count == 3
|
44
|
-
assert calls[:each].count == 8
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_variable_assigns
|
48
|
-
assert @db.keys.include? :assigns
|
49
|
-
assigns = @db[:assigns].group_by {|x| x[:name][-1]}
|
50
|
-
assert assigns.keys.include? :pbar
|
51
|
-
assert assigns.keys.include? :PBAR_FORMAT
|
52
|
-
assert assigns.keys.include? :foo
|
53
|
-
assert assigns[:pbar].count == 2
|
54
|
-
assert assigns[:PBAR_FORMAT].count == 1
|
55
|
-
assert assigns[:foo].count == 1
|
56
|
-
|
57
|
-
refute assigns.keys.include? "=".to_sym
|
58
|
-
refute assigns.keys.include? "<".to_sym
|
59
|
-
end
|
60
|
-
end
|