starscope 1.5.7 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby-ci.yml +26 -0
- data/.rubocop.yml +10 -4
- data/CHANGELOG.md +18 -0
- data/README.md +1 -1
- data/Rakefile +5 -2
- data/bin/starscope +53 -51
- data/doc/LANGUAGE_SUPPORT.md +8 -0
- data/doc/USER_GUIDE.md +14 -4
- data/lib/starscope/db.rb +20 -24
- data/lib/starscope/exportable.rb +34 -32
- data/lib/starscope/fragment_extractor.rb +3 -4
- data/lib/starscope/langs/erb.rb +3 -3
- data/lib/starscope/langs/golang.rb +24 -25
- data/lib/starscope/langs/javascript.rb +4 -2
- data/lib/starscope/langs/ruby.rb +4 -2
- data/lib/starscope/matcher.rb +2 -2
- data/lib/starscope/output.rb +6 -3
- data/lib/starscope/queryable.rb +1 -0
- data/lib/starscope/version.rb +1 -1
- data/starscope.gemspec +14 -11
- data/test/fixtures/sample_golang.go +1 -1
- data/test/functional/starscope_test.rb +15 -15
- data/test/unit/db_test.rb +50 -50
- data/test/unit/exportable_test.rb +12 -10
- data/test/unit/fragment_extractor_test.rb +10 -10
- data/test/unit/langs/erb_test.rb +17 -17
- data/test/unit/langs/golang_test.rb +55 -55
- data/test/unit/langs/javascript_test.rb +44 -44
- data/test/unit/langs/ruby_test.rb +27 -27
- data/test/unit/output_test.rb +3 -3
- data/test/unit/queryable_test.rb +29 -29
- metadata +59 -31
- data/.travis.yml +0 -9
data/lib/starscope/langs/erb.rb
CHANGED
@@ -3,8 +3,8 @@ module Starscope
|
|
3
3
|
module ERB
|
4
4
|
VERSION = 1
|
5
5
|
|
6
|
-
ERB_START = /<%(?:-|={1,4})
|
7
|
-
ERB_END = /[-=]
|
6
|
+
ERB_START = /<%(?:-|={1,4})?/.freeze
|
7
|
+
ERB_END = /[-=]?%>/.freeze
|
8
8
|
|
9
9
|
def self.match_file(name)
|
10
10
|
name.end_with?('.erb')
|
@@ -20,7 +20,7 @@ module Starscope
|
|
20
20
|
term = line.index(ERB_END)
|
21
21
|
if term
|
22
22
|
yield Starscope::DB::FRAGMENT, :Ruby, frag: line[0...term], line_no: line_no
|
23
|
-
line = line[term + 1
|
23
|
+
line = line[term + 1..]
|
24
24
|
multiline = false
|
25
25
|
else
|
26
26
|
yield Starscope::DB::FRAGMENT, :Ruby, frag: line, line_no: line_no
|
@@ -3,13 +3,13 @@ module Starscope
|
|
3
3
|
module Golang
|
4
4
|
VERSION = 1
|
5
5
|
|
6
|
-
FUNC_CALL = /([
|
7
|
-
END_OF_BLOCK = /^\s*\}\s
|
8
|
-
END_OF_GROUP = /^\s*\)\s
|
9
|
-
STRING_LITERAL = /".+?"
|
10
|
-
BUILTIN_FUNCS = %w
|
11
|
-
uint uint8 uint16 uint32 uint64 string byte
|
12
|
-
CONTROL_KEYS = %w
|
6
|
+
FUNC_CALL = /([[[:word:]].]*?[[:word:]])\(/.freeze
|
7
|
+
END_OF_BLOCK = /^\s*\}\s*$/.freeze
|
8
|
+
END_OF_GROUP = /^\s*\)\s*$/.freeze
|
9
|
+
STRING_LITERAL = /".+?"/.freeze
|
10
|
+
BUILTIN_FUNCS = %w[new make len close copy delete int int8 int16 int32 int64
|
11
|
+
uint uint8 uint16 uint32 uint64 string byte].freeze
|
12
|
+
CONTROL_KEYS = %w[if for switch case].freeze
|
13
13
|
|
14
14
|
def self.match_file(name)
|
15
15
|
name.end_with?('.go')
|
@@ -36,6 +36,7 @@ module Starscope
|
|
36
36
|
if stack[-1] == :comment
|
37
37
|
match = %r{\*/(.*)}.match(line)
|
38
38
|
next unless match
|
39
|
+
|
39
40
|
line = match[1]
|
40
41
|
stack.pop
|
41
42
|
end
|
@@ -45,7 +46,7 @@ module Starscope
|
|
45
46
|
pos = 0
|
46
47
|
while (match = STRING_LITERAL.match(line, pos))
|
47
48
|
eos = find_end_of_string(line, match.begin(0))
|
48
|
-
line = line[0..match.begin(0)] + line[eos
|
49
|
+
line = line[0..match.begin(0)] + line[eos..]
|
49
50
|
pos = match.begin(0) + 2
|
50
51
|
end
|
51
52
|
end
|
@@ -56,14 +57,14 @@ module Starscope
|
|
56
57
|
case line
|
57
58
|
when END_OF_BLOCK
|
58
59
|
end_block(line_no, scope, stack, &block)
|
59
|
-
when /(.+)\s
|
60
|
+
when /(.+)\s+[[:word:]]+/
|
60
61
|
parse_def(Regexp.last_match(1), line_no, scope, &block)
|
61
62
|
end
|
62
63
|
when :interface
|
63
64
|
case line
|
64
65
|
when END_OF_BLOCK
|
65
66
|
end_block(line_no, scope, stack, &block)
|
66
|
-
when /(
|
67
|
+
when /([[:word:]]+)\(.*\)\s+/
|
67
68
|
yield :defs, scope + [Regexp.last_match(1)], line_no: line_no
|
68
69
|
end
|
69
70
|
when :def
|
@@ -105,45 +106,42 @@ module Starscope
|
|
105
106
|
# handles new lines (when not in the middle of an existing definition)
|
106
107
|
def self.parse_new_line(line, line_no, scope, stack, &block)
|
107
108
|
case line
|
108
|
-
when /^func\s+(
|
109
|
+
when /^func\s+([[:word:]]+)\(/
|
109
110
|
yield :defs, scope + [Regexp.last_match(1)], line_no: line_no, type: :func
|
110
111
|
stack.push(:func)
|
111
|
-
when /^func\s+\(
|
112
|
+
when /^func\s+\([[:word:]]+\s+\*?([[:word:]]+)\)\s*([[:word:]]+)\(/
|
112
113
|
yield :defs, scope + [Regexp.last_match(1), Regexp.last_match(2)], line_no: line_no, type: :func
|
113
114
|
stack.push(:func)
|
114
|
-
when /^package\s+(
|
115
|
+
when /^package\s+([[:word:]]+)/
|
115
116
|
scope.push(Regexp.last_match(1))
|
116
117
|
yield :defs, scope, line_no: line_no, type: :package
|
117
|
-
when /^type\s+(
|
118
|
+
when /^type\s+([[:word:]]+)\s+struct\s*\{/
|
118
119
|
scope.push(Regexp.last_match(1))
|
119
120
|
stack.push(:struct)
|
120
121
|
yield :defs, scope, line_no: line_no, type: :class
|
121
|
-
when /^type\s+(
|
122
|
+
when /^type\s+([[:word:]]+)\s+interface\s*\{/
|
122
123
|
scope.push(Regexp.last_match(1))
|
123
124
|
stack.push(:interface)
|
124
125
|
yield :defs, scope, line_no: line_no, type: :class
|
125
|
-
when /^type\s+(
|
126
|
+
when /^type\s+([[:word:]]+)/
|
126
127
|
yield :defs, scope + [Regexp.last_match(1)], line_no: line_no, type: :type
|
127
128
|
when /^import\s+"(.+)"/
|
128
129
|
name = Regexp.last_match(1).split('/')
|
129
130
|
yield :imports, name, line_no: line_no
|
130
131
|
when /^import\s+\(/
|
131
132
|
stack.push(:import)
|
132
|
-
when /^var\s+\(/
|
133
|
-
stack.push(:def)
|
134
|
-
when /^var\s+(\w+)\s/
|
135
|
-
yield :defs, scope + [Regexp.last_match(1)], line_no: line_no
|
136
|
-
parse_call(line, line_no, scope, &block)
|
137
|
-
when /^const\s+\(/
|
133
|
+
when /^var\s+\(/, /^const\s+\(/
|
138
134
|
stack.push(:def)
|
139
|
-
when /^
|
135
|
+
when /^var\s+([[:word:]]+)\s/, /^const\s+([[:word:]]+)\s/
|
140
136
|
yield :defs, scope + [Regexp.last_match(1)], line_no: line_no
|
141
137
|
parse_call(line, line_no, scope, &block)
|
142
138
|
when /^\s+(.*?) :?=[^=]/
|
143
|
-
Regexp.last_match(1).split
|
139
|
+
Regexp.last_match(1).split.each do |var|
|
144
140
|
next if CONTROL_KEYS.include?(var)
|
141
|
+
|
145
142
|
name = var.delete(',').split('.')
|
146
143
|
next if name[0] == '_' # assigning to _ is a discard in golang
|
144
|
+
|
147
145
|
if name.length == 1
|
148
146
|
yield :assigns, scope + [name[0]], line_no: line_no
|
149
147
|
else
|
@@ -158,9 +156,10 @@ module Starscope
|
|
158
156
|
|
159
157
|
def self.parse_call(line, line_no, scope)
|
160
158
|
line.scan(FUNC_CALL) do |match|
|
161
|
-
name = match[0].split('.').
|
159
|
+
name = match[0].split('.').reject(&:empty?)
|
162
160
|
if name.length == 1
|
163
161
|
next if name[0] == 'func'
|
162
|
+
|
164
163
|
if BUILTIN_FUNCS.include?(name[0])
|
165
164
|
yield :calls, name[0], line_no: line_no
|
166
165
|
else
|
@@ -96,7 +96,8 @@ module Starscope
|
|
96
96
|
next
|
97
97
|
end
|
98
98
|
|
99
|
-
next if found[node.name]
|
99
|
+
next if found[node.name]&.include?(line)
|
100
|
+
|
100
101
|
yield :defs, node.name, line_no: line
|
101
102
|
found[node.name] ||= Set.new
|
102
103
|
found[node.name].add(line)
|
@@ -113,7 +114,8 @@ module Starscope
|
|
113
114
|
line = find_line(node.range.from, map, lines, name)
|
114
115
|
next unless line
|
115
116
|
|
116
|
-
next if found[name]
|
117
|
+
next if found[name]&.include?(line)
|
118
|
+
|
117
119
|
yield :reads, name, line_no: line
|
118
120
|
end
|
119
121
|
end
|
data/lib/starscope/langs/ruby.rb
CHANGED
@@ -16,9 +16,11 @@ module Starscope
|
|
16
16
|
|
17
17
|
def self.match_file(name)
|
18
18
|
return true if name.end_with?('.rb', '.rake')
|
19
|
+
|
19
20
|
File.open(name) do |f|
|
20
21
|
head = f.read(2)
|
21
22
|
return false if head.nil? || !head.start_with?('#!')
|
23
|
+
|
22
24
|
return f.readline.include?('ruby')
|
23
25
|
end
|
24
26
|
end
|
@@ -39,7 +41,7 @@ module Starscope
|
|
39
41
|
extract_node(tree, scope, &block)
|
40
42
|
|
41
43
|
new_scope = []
|
42
|
-
if [
|
44
|
+
if %i[class module].include? tree.type
|
43
45
|
new_scope = scoped_name(tree.children[0], scope)
|
44
46
|
scope += new_scope
|
45
47
|
end
|
@@ -118,7 +120,7 @@ module Starscope
|
|
118
120
|
def self.scoped_name(node, scope)
|
119
121
|
if node.type == :block
|
120
122
|
scoped_name(node.children[0], scope)
|
121
|
-
elsif [
|
123
|
+
elsif %i[lvar ivar cvar gvar const send casgn].include? node.type
|
122
124
|
if node.children[0].is_a? Symbol
|
123
125
|
[node.children[0]]
|
124
126
|
elsif node.children[0].is_a? AST::Node
|
data/lib/starscope/matcher.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Starscope
|
2
2
|
class Matcher
|
3
|
-
MATCH_TYPES = [
|
3
|
+
MATCH_TYPES = %i[literal_match regexp_match].freeze
|
4
4
|
|
5
5
|
def initialize(query)
|
6
6
|
@query = query
|
@@ -15,7 +15,7 @@ module Starscope
|
|
15
15
|
def match(input)
|
16
16
|
if input.end_with?(@query)
|
17
17
|
:literal_match
|
18
|
-
elsif @regexp
|
18
|
+
elsif @regexp&.match(input)
|
19
19
|
:regexp_match
|
20
20
|
end
|
21
21
|
end
|
data/lib/starscope/output.rb
CHANGED
@@ -4,7 +4,7 @@ module Starscope
|
|
4
4
|
class Output
|
5
5
|
PBAR_FORMAT = '%t: %c/%C %E ||%b>%i||'.freeze
|
6
6
|
|
7
|
-
def initialize(level, out =
|
7
|
+
def initialize(level, out = $stdout)
|
8
8
|
@out = out
|
9
9
|
@level = level
|
10
10
|
@pbar = nil
|
@@ -12,27 +12,30 @@ module Starscope
|
|
12
12
|
|
13
13
|
def new_pbar(title, num_items)
|
14
14
|
return if @level == :quiet
|
15
|
+
|
15
16
|
@pbar = ProgressBar.create(title: title, total: num_items,
|
16
17
|
format: PBAR_FORMAT, length: 80,
|
17
18
|
out: @out)
|
18
19
|
end
|
19
20
|
|
20
21
|
def inc_pbar
|
21
|
-
@pbar
|
22
|
+
@pbar&.increment
|
22
23
|
end
|
23
24
|
|
24
25
|
def finish_pbar
|
25
|
-
@pbar
|
26
|
+
@pbar&.finish
|
26
27
|
@pbar = nil
|
27
28
|
end
|
28
29
|
|
29
30
|
def extra(msg)
|
30
31
|
return unless @level == :verbose
|
32
|
+
|
31
33
|
output(msg)
|
32
34
|
end
|
33
35
|
|
34
36
|
def normal(msg)
|
35
37
|
return if @level == :quiet
|
38
|
+
|
36
39
|
output(msg)
|
37
40
|
end
|
38
41
|
|
data/lib/starscope/queryable.rb
CHANGED
data/lib/starscope/version.rb
CHANGED
data/starscope.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('lib/starscope/version.rb', __dir__)
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = 'starscope'
|
5
5
|
gem.version = Starscope::VERSION
|
6
6
|
gem.summary = 'Smart code search and indexing'
|
7
|
-
gem.description = <<-
|
7
|
+
gem.description = <<-DESC
|
8
8
|
Starscope is a code indexer, search and navigation tool for Ruby, Golang, and JavaScript.
|
9
9
|
Inspired by the extremely popular Ctags and Cscope utilities, Starscope can
|
10
10
|
answer a lot of questions about a lot of code.
|
11
|
-
|
11
|
+
DESC
|
12
12
|
gem.authors = ['Evan Huus']
|
13
13
|
gem.homepage = 'https://github.com/eapache/starscope'
|
14
14
|
gem.email = 'eapache@gmail.com'
|
@@ -17,19 +17,22 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
18
|
gem.test_files = `git ls-files -- test/*`.split("\n")
|
19
19
|
gem.require_paths = ['lib']
|
20
|
-
gem.required_ruby_version = '>= 2.
|
20
|
+
gem.required_ruby_version = '>= 2.6'
|
21
21
|
|
22
|
+
gem.add_dependency 'babel-transpiler', '~> 0.7'
|
22
23
|
gem.add_dependency 'oj', '~> 3.7'
|
23
|
-
gem.add_dependency 'parser', '~>
|
24
|
-
gem.add_dependency 'ruby-progressbar', '~> 1.9'
|
24
|
+
gem.add_dependency 'parser', '~> 3.1'
|
25
25
|
gem.add_dependency 'rkelly-remix', '~> 0.0.7'
|
26
|
-
gem.add_dependency '
|
26
|
+
gem.add_dependency 'ruby-progressbar', '~> 1.9'
|
27
27
|
gem.add_dependency 'sourcemap', '~> 0.1'
|
28
28
|
|
29
29
|
gem.add_development_dependency 'bundler', '>= 1.7'
|
30
|
-
gem.add_development_dependency '
|
31
|
-
gem.add_development_dependency 'pry', '~> 0.11'
|
32
|
-
gem.add_development_dependency 'minitest', '~> 5.10'
|
30
|
+
gem.add_development_dependency 'minitest', '~> 5.12'
|
33
31
|
gem.add_development_dependency 'mocha', '~> 1.3'
|
34
|
-
gem.add_development_dependency '
|
32
|
+
gem.add_development_dependency 'pry', '~> 0.11'
|
33
|
+
gem.add_development_dependency 'rake', '~> 13.0'
|
34
|
+
gem.add_development_dependency 'rubocop', '~> 1.25.0'
|
35
|
+
gem.add_development_dependency 'rubocop-minitest', '~> 0.17.1'
|
36
|
+
gem.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
37
|
+
gem.metadata['rubygems_mfa_required'] = 'true'
|
35
38
|
end
|
@@ -1,43 +1,43 @@
|
|
1
1
|
require_relative '../test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
EXTRACT = "#{BASE} --no-read --no-write #{FIXTURES}".freeze
|
3
|
+
BASE = 'bundle exec bin/starscope --quiet'.freeze
|
4
|
+
EXTRACT = "#{BASE} --no-read --no-write #{FIXTURES}".freeze
|
6
5
|
|
6
|
+
describe 'starscope executable script' do
|
7
7
|
it 'must not produce help wider than 80 characters' do
|
8
8
|
`#{BASE} -h`.each_line do |line|
|
9
|
-
line.length.must_be :<=, 80
|
9
|
+
_(line.length).must_be :<=, 80
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'must produce the right version' do
|
14
|
-
`#{BASE} -v`.chomp.must_equal Starscope::VERSION
|
14
|
+
_(`#{BASE} -v`.chomp).must_equal Starscope::VERSION
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'must produce a valid database summary' do
|
18
18
|
lines = `#{EXTRACT} -s`.lines.to_a
|
19
|
-
lines.length.must_equal 8
|
19
|
+
_(lines.length).must_equal 8
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'must produce a valid database dump' do
|
23
23
|
lines = `#{EXTRACT} -d requires`.lines.to_a
|
24
|
-
lines[1].split.first.must_equal 'date'
|
25
|
-
lines[2].split.first.must_equal 'foo-bar'
|
26
|
-
lines[3].split.first.must_equal 'react-native'
|
27
|
-
lines[4].split.first.must_equal 'zlib'
|
24
|
+
_(lines[1].split.first).must_equal 'date'
|
25
|
+
_(lines[2].split.first).must_equal 'foo-bar'
|
26
|
+
_(lines[3].split.first).must_equal 'react-native'
|
27
|
+
_(lines[4].split.first).must_equal 'zlib'
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'must correctly query the database' do
|
31
31
|
`#{EXTRACT} -q calls,add_file`.each_line do |line|
|
32
|
-
line.split[0..2].must_equal %w
|
32
|
+
_(line.split[0..2]).must_equal %w[Starscope DB add_file]
|
33
33
|
end
|
34
34
|
|
35
35
|
`#{EXTRACT} -q lang:ruby,calls,add_file`.each_line do |line|
|
36
|
-
line.split[0..2].must_equal %w
|
36
|
+
_(line.split[0..2]).must_equal %w[Starscope DB add_file]
|
37
37
|
end
|
38
38
|
|
39
39
|
`#{EXTRACT} -q lang:go,calls,add_file`.each_line do |line|
|
40
|
-
line.must_equal "No results found.\n"
|
40
|
+
_(line).must_equal "No results found.\n"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -45,7 +45,7 @@ describe 'starscope executable script' do
|
|
45
45
|
file = Tempfile.new('starscope_test')
|
46
46
|
begin
|
47
47
|
`#{EXTRACT} -e cscope,#{file.path}`
|
48
|
-
$?.exitstatus.must_equal 0
|
48
|
+
_($?.exitstatus).must_equal 0
|
49
49
|
ensure
|
50
50
|
file.close
|
51
51
|
file.unlink
|
@@ -56,7 +56,7 @@ describe 'starscope executable script' do
|
|
56
56
|
file = Tempfile.new('starscope_test')
|
57
57
|
begin
|
58
58
|
`#{EXTRACT} -e ctags,#{file.path}`
|
59
|
-
$?.exitstatus.must_equal 0
|
59
|
+
_($?.exitstatus).must_equal 0
|
60
60
|
ensure
|
61
61
|
file.close
|
62
62
|
file.unlink
|
data/test/unit/db_test.rb
CHANGED
@@ -7,14 +7,14 @@ describe Starscope::DB do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'must raise on invalid tables' do
|
10
|
-
proc { @db.records(:foo) }.must_raise Starscope::DB::NoTableError
|
10
|
+
_(proc { @db.records(:foo) }).must_raise Starscope::DB::NoTableError
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'must add paths' do
|
14
14
|
paths = [GOLANG_SAMPLE, "#{FIXTURES}/**/*"]
|
15
15
|
@db.add_paths(paths)
|
16
16
|
|
17
|
-
@db.metadata(:paths).must_equal paths
|
17
|
+
_(@db.metadata(:paths)).must_equal paths
|
18
18
|
validate(@db)
|
19
19
|
end
|
20
20
|
|
@@ -24,10 +24,10 @@ describe Starscope::DB do
|
|
24
24
|
@db.add_excludes(["#{FIXTURES}/**"])
|
25
25
|
|
26
26
|
files = @db.metadata(:files).keys
|
27
|
-
files.wont_include RUBY_SAMPLE
|
28
|
-
files.wont_include GOLANG_SAMPLE
|
29
|
-
@db.records(:defs).must_be_empty
|
30
|
-
@db.records(:end).must_be_empty
|
27
|
+
_(files).wont_include RUBY_SAMPLE
|
28
|
+
_(files).wont_include GOLANG_SAMPLE
|
29
|
+
_(@db.records(:defs)).must_be_empty
|
30
|
+
_(@db.records(:end)).must_be_empty
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'must pick up new files in old paths' do
|
@@ -40,23 +40,23 @@ describe Starscope::DB do
|
|
40
40
|
it 'must remove old files in existing paths' do
|
41
41
|
@db.load("#{FIXTURES}/db_removed_files.json")
|
42
42
|
@db.update
|
43
|
-
@db.metadata(:files).keys.wont_include "#{FIXTURES}/foo"
|
43
|
+
_(@db.metadata(:files).keys).wont_include "#{FIXTURES}/foo"
|
44
44
|
end
|
45
45
|
|
46
46
|
it "must update stale existing files when extractor hasn't changed" do
|
47
47
|
@db.load("#{FIXTURES}/db_out_of_date.json")
|
48
|
-
@db.metadata(:langs)[:Golang].must_be :>=, Starscope::DB::LANGS[:Golang]
|
48
|
+
_(@db.metadata(:langs)[:Golang]).must_be :>=, Starscope::DB::LANGS[:Golang]
|
49
49
|
|
50
50
|
cur_mtime = @db.metadata(:files)[GOLANG_SAMPLE][:last_updated]
|
51
51
|
File.expects(:mtime).twice.returns(cur_mtime + 1)
|
52
52
|
@db.update
|
53
53
|
|
54
54
|
file = @db.metadata(:files)[GOLANG_SAMPLE]
|
55
|
-
file[:last_updated].must_equal cur_mtime + 1
|
56
|
-
file[:lang].must_equal :Golang
|
57
|
-
file[:lines].wont_be_empty
|
58
|
-
@db.records(:defs).wont_be_empty
|
59
|
-
@db.records(:calls).wont_be_empty
|
55
|
+
_(file[:last_updated]).must_equal cur_mtime + 1
|
56
|
+
_(file[:lang]).must_equal :Golang
|
57
|
+
_(file[:lines]).wont_be_empty
|
58
|
+
_(@db.records(:defs)).wont_be_empty
|
59
|
+
_(@db.records(:calls)).wont_be_empty
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'must update unchanged existing files with old extractor versions' do
|
@@ -67,11 +67,11 @@ describe Starscope::DB do
|
|
67
67
|
@db.update
|
68
68
|
|
69
69
|
file = @db.metadata(:files)[GOLANG_SAMPLE]
|
70
|
-
file[:last_updated].must_equal cur_mtime
|
71
|
-
file[:lang].must_equal :Golang
|
72
|
-
file[:lines].wont_be_empty
|
73
|
-
@db.records(:defs).wont_be_empty
|
74
|
-
@db.records(:calls).wont_be_empty
|
70
|
+
_(file[:last_updated]).must_equal cur_mtime
|
71
|
+
_(file[:lang]).must_equal :Golang
|
72
|
+
_(file[:lines]).wont_be_empty
|
73
|
+
_(@db.records(:defs)).wont_be_empty
|
74
|
+
_(@db.records(:calls)).wont_be_empty
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'must update unchanged existing files with old sublang extractor versions' do
|
@@ -82,12 +82,12 @@ describe Starscope::DB do
|
|
82
82
|
@db.update
|
83
83
|
|
84
84
|
file = @db.metadata(:files)[GOLANG_SAMPLE]
|
85
|
-
file[:last_updated].must_equal cur_mtime
|
86
|
-
file[:lang].must_equal :Golang
|
87
|
-
file[:sublangs].must_be_empty
|
88
|
-
file[:lines].wont_be_empty
|
89
|
-
@db.records(:defs).wont_be_empty
|
90
|
-
@db.records(:calls).wont_be_empty
|
85
|
+
_(file[:last_updated]).must_equal cur_mtime
|
86
|
+
_(file[:lang]).must_equal :Golang
|
87
|
+
_(file[:sublangs]).must_be_empty
|
88
|
+
_(file[:lines]).wont_be_empty
|
89
|
+
_(@db.records(:defs)).wont_be_empty
|
90
|
+
_(@db.records(:calls)).wont_be_empty
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'must update unchanged existing files when the extractor has been removed' do
|
@@ -98,11 +98,11 @@ describe Starscope::DB do
|
|
98
98
|
@db.update
|
99
99
|
|
100
100
|
file = @db.metadata(:files)[GOLANG_SAMPLE]
|
101
|
-
file[:last_updated].must_equal cur_mtime
|
102
|
-
file[:lang].must_equal :Golang
|
103
|
-
file[:lines].wont_be_empty
|
104
|
-
@db.records(:defs).wont_be_empty
|
105
|
-
@db.records(:calls).wont_be_empty
|
101
|
+
_(file[:last_updated]).must_equal cur_mtime
|
102
|
+
_(file[:lang]).must_equal :Golang
|
103
|
+
_(file[:lines]).wont_be_empty
|
104
|
+
_(@db.records(:defs)).wont_be_empty
|
105
|
+
_(@db.records(:calls)).wont_be_empty
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'must not update file with up-to-date time and extractor' do
|
@@ -110,13 +110,13 @@ describe Starscope::DB do
|
|
110
110
|
@db.update
|
111
111
|
|
112
112
|
file = @db.metadata(:files)[GOLANG_SAMPLE]
|
113
|
-
file[:last_updated].must_equal 10_000_000_000
|
114
|
-
@db.tables.must_be_empty
|
113
|
+
_(file[:last_updated]).must_equal 10_000_000_000
|
114
|
+
_(@db.tables).must_be_empty
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'must load an old DB file' do
|
118
118
|
@db.load("#{FIXTURES}/db_old.json.gz")
|
119
|
-
@db.metadata(:paths).must_equal ["#{FIXTURES}/**/*"]
|
119
|
+
_(@db.metadata(:paths)).must_equal ["#{FIXTURES}/**/*"]
|
120
120
|
validate(@db)
|
121
121
|
end
|
122
122
|
|
@@ -136,26 +136,26 @@ describe Starscope::DB do
|
|
136
136
|
|
137
137
|
it 'must run queries' do
|
138
138
|
@db.add_paths([FIXTURES])
|
139
|
-
@db.query(:calls, 'abc').must_equal []
|
140
|
-
@db.query(:defs, 'xyz').must_equal []
|
141
|
-
@db.query(:calls, 'add_file').length.must_equal 3
|
139
|
+
_(@db.query(:calls, 'abc')).must_equal []
|
140
|
+
_(@db.query(:defs, 'xyz')).must_equal []
|
141
|
+
_(@db.query(:calls, 'add_file').length).must_equal 3
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'must run queries on multiple tables' do
|
145
145
|
@db.add_paths([FIXTURES])
|
146
|
-
ret = @db.query([
|
147
|
-
ret.length.must_equal 4
|
148
|
-
ret.first[:name].last.must_equal :foo
|
146
|
+
ret = @db.query(%i[calls defs], 'foo')
|
147
|
+
_(ret.length).must_equal 4
|
148
|
+
_(ret.first[:name].last).must_equal :foo
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'must symbolize compound name' do
|
152
152
|
rec = Starscope::DB.normalize_record(:foo, ['a', :b], {})
|
153
|
-
rec[:name].must_equal [
|
153
|
+
_(rec[:name]).must_equal %i[a b]
|
154
154
|
end
|
155
155
|
|
156
156
|
it 'must symbolize and array-wrap simple name' do
|
157
157
|
rec = Starscope::DB.normalize_record(:foo, 'a', {})
|
158
|
-
rec[:name].must_equal [:a]
|
158
|
+
_(rec[:name]).must_equal [:a]
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'must store extractor metadata returned from the `extract` call' do
|
@@ -167,21 +167,21 @@ describe Starscope::DB do
|
|
167
167
|
|
168
168
|
@db.add_paths([GOLANG_SAMPLE])
|
169
169
|
|
170
|
-
@db.metadata(:files)[GOLANG_SAMPLE][:a].must_equal 1
|
170
|
+
_(@db.metadata(:files)[GOLANG_SAMPLE][:a]).must_equal 1
|
171
171
|
end
|
172
172
|
|
173
173
|
private
|
174
174
|
|
175
175
|
def validate(db)
|
176
176
|
files = db.metadata(:files)
|
177
|
-
files.keys.must_include GOLANG_SAMPLE
|
178
|
-
files.keys.must_include RUBY_SAMPLE
|
179
|
-
files[GOLANG_SAMPLE][:last_updated].must_equal File.mtime(GOLANG_SAMPLE).to_i
|
180
|
-
files[RUBY_SAMPLE][:last_updated].must_equal File.mtime(RUBY_SAMPLE).to_i
|
181
|
-
|
182
|
-
db.records(:defs).wont_be_empty
|
183
|
-
db.records(:calls).wont_be_empty
|
184
|
-
db.records(:imports).wont_be_empty
|
185
|
-
db.records(:requires).wont_be_empty
|
177
|
+
_(files.keys).must_include GOLANG_SAMPLE
|
178
|
+
_(files.keys).must_include RUBY_SAMPLE
|
179
|
+
_(files[GOLANG_SAMPLE][:last_updated]).must_equal File.mtime(GOLANG_SAMPLE).to_i
|
180
|
+
_(files[RUBY_SAMPLE][:last_updated]).must_equal File.mtime(RUBY_SAMPLE).to_i
|
181
|
+
|
182
|
+
_(db.records(:defs)).wont_be_empty
|
183
|
+
_(db.records(:calls)).wont_be_empty
|
184
|
+
_(db.records(:imports)).wont_be_empty
|
185
|
+
_(db.records(:requires)).wont_be_empty
|
186
186
|
end
|
187
187
|
end
|
@@ -11,7 +11,7 @@ describe Starscope::Exportable do
|
|
11
11
|
@db.export_to(:ctags, @buf, '.')
|
12
12
|
@buf.rewind
|
13
13
|
lines = @buf.each_line.to_a
|
14
|
-
lines.must_include(
|
14
|
+
_(lines).must_include(
|
15
15
|
"NoTableError\t" \
|
16
16
|
"./#{FIXTURES}/sample_ruby.rb\t" \
|
17
17
|
"/^ class NoTableError < StandardError; end$/;\"\t" \
|
@@ -24,7 +24,7 @@ describe Starscope::Exportable do
|
|
24
24
|
@db.export_to(:ctags, @buf, '../foo')
|
25
25
|
@buf.rewind
|
26
26
|
lines = @buf.each_line.to_a
|
27
|
-
lines.must_include(
|
27
|
+
_(lines).must_include(
|
28
28
|
"NoTableError\t" \
|
29
29
|
"../foo/#{FIXTURES}/sample_ruby.rb\t" \
|
30
30
|
"/^ class NoTableError < StandardError; end$/;\"\t" \
|
@@ -38,14 +38,16 @@ describe Starscope::Exportable do
|
|
38
38
|
@buf.rewind
|
39
39
|
lines = @buf.each_line.to_a
|
40
40
|
|
41
|
-
lines.must_include "\t@#{FIXTURES}/sample_golang.go\n"
|
42
|
-
lines.must_include "\tgSunday\n"
|
43
|
-
lines.must_include "\t`add_file\n"
|
44
|
-
lines.must_include "\t}}\n"
|
45
|
-
lines.must_include "13 class \n"
|
41
|
+
_(lines).must_include "\t@#{FIXTURES}/sample_golang.go\n"
|
42
|
+
_(lines).must_include "\tgSunday\n"
|
43
|
+
_(lines).must_include "\t`add_file\n"
|
44
|
+
_(lines).must_include "\t}}\n"
|
45
|
+
_(lines).must_include "13 class \n"
|
46
|
+
_(lines).must_include "\tgsingle_var_unicode\n"
|
46
47
|
|
47
|
-
lines.wont_include "
|
48
|
-
lines.wont_include "
|
49
|
-
lines.wont_include "
|
48
|
+
_(lines).wont_include "\tgsingle_var_Äunicode\n"
|
49
|
+
_(lines).wont_include "= [\n"
|
50
|
+
_(lines).wont_include "4 LANGS = [\n"
|
51
|
+
_(lines).wont_include "116 tmpdb[entry[:file]][entry[:line_no]] ||= []\n"
|
50
52
|
end
|
51
53
|
end
|