starscope 1.5.6 → 1.6.1
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/.gitignore +1 -0
- data/.rubocop.yml +10 -4
- data/CHANGELOG.md +35 -0
- data/README.md +1 -3
- data/Rakefile +5 -2
- data/bin/starscope +54 -51
- data/doc/LANGUAGE_SUPPORT.md +8 -0
- data/doc/USER_GUIDE.md +14 -4
- data/lib/starscope/db.rb +26 -28
- data/lib/starscope/exportable.rb +35 -33
- 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 +26 -7
- data/lib/starscope/langs/vue.rb +32 -0
- 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 +16 -13
- data/test/fixtures/sample_golang.go +1 -1
- data/test/fixtures/sample_ruby.rb +5 -0
- data/test/fixtures/sample_vue.vue +48 -0
- data/test/functional/starscope_test.rb +16 -15
- data/test/test_helper.rb +2 -1
- 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 +46 -27
- data/test/unit/langs/vue_test.rb +28 -0
- data/test/unit/output_test.rb +3 -3
- data/test/unit/queryable_test.rb +29 -29
- metadata +68 -35
- data/.travis.yml +0 -9
@@ -1,43 +1,44 @@
|
|
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 '
|
27
|
-
lines[4].split.first.must_equal '
|
24
|
+
_(lines[1].split.first).must_equal 'date'
|
25
|
+
_(lines[2].split.first).must_equal 'foo-bar'
|
26
|
+
_(lines[3].split.first).must_equal 'marked'
|
27
|
+
_(lines[4].split.first).must_equal 'react-native'
|
28
|
+
_(lines[5].split.first).must_equal 'zlib'
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'must correctly query the database' do
|
31
32
|
`#{EXTRACT} -q calls,add_file`.each_line do |line|
|
32
|
-
line.split[0..2].must_equal %w
|
33
|
+
_(line.split[0..2]).must_equal %w[Starscope DB add_file]
|
33
34
|
end
|
34
35
|
|
35
36
|
`#{EXTRACT} -q lang:ruby,calls,add_file`.each_line do |line|
|
36
|
-
line.split[0..2].must_equal %w
|
37
|
+
_(line.split[0..2]).must_equal %w[Starscope DB add_file]
|
37
38
|
end
|
38
39
|
|
39
40
|
`#{EXTRACT} -q lang:go,calls,add_file`.each_line do |line|
|
40
|
-
line.must_equal "No results found.\n"
|
41
|
+
_(line).must_equal "No results found.\n"
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
@@ -45,7 +46,7 @@ describe 'starscope executable script' do
|
|
45
46
|
file = Tempfile.new('starscope_test')
|
46
47
|
begin
|
47
48
|
`#{EXTRACT} -e cscope,#{file.path}`
|
48
|
-
$?.exitstatus.must_equal 0
|
49
|
+
_($?.exitstatus).must_equal 0
|
49
50
|
ensure
|
50
51
|
file.close
|
51
52
|
file.unlink
|
@@ -56,7 +57,7 @@ describe 'starscope executable script' do
|
|
56
57
|
file = Tempfile.new('starscope_test')
|
57
58
|
begin
|
58
59
|
`#{EXTRACT} -e ctags,#{file.path}`
|
59
|
-
$?.exitstatus.must_equal 0
|
60
|
+
_($?.exitstatus).must_equal 0
|
60
61
|
ensure
|
61
62
|
file.close
|
62
63
|
file.unlink
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'minitest/pride'
|
3
|
-
require 'mocha/
|
3
|
+
require 'mocha/minitest'
|
4
4
|
require_relative '../lib/starscope'
|
5
5
|
|
6
6
|
FIXTURES = 'test/fixtures'.freeze
|
@@ -9,4 +9,5 @@ GOLANG_SAMPLE = "#{FIXTURES}/sample_golang.go".freeze
|
|
9
9
|
JAVASCRIPT_EXAMPLE = "#{FIXTURES}/sample_javascript.js".freeze
|
10
10
|
RUBY_SAMPLE = "#{FIXTURES}/sample_ruby.rb".freeze
|
11
11
|
ERB_SAMPLE = "#{FIXTURES}/sample_erb.erb".freeze
|
12
|
+
VUE_SAMPLE = "#{FIXTURES}/sample_vue.vue".freeze
|
12
13
|
EMPTY_FILE = "#{FIXTURES}/empty".freeze
|
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
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require_relative '../test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
module
|
5
|
-
module
|
6
|
-
module Dummy
|
7
|
-
end
|
3
|
+
module Starscope
|
4
|
+
module Lang
|
5
|
+
module Dummy
|
8
6
|
end
|
9
7
|
end
|
8
|
+
end
|
10
9
|
|
10
|
+
describe Starscope::FragmentExtractor do
|
11
11
|
before do
|
12
12
|
@extractor = Starscope::FragmentExtractor.new(
|
13
13
|
:Dummy,
|
@@ -27,20 +27,20 @@ describe Starscope::FragmentExtractor do
|
|
27
27
|
|
28
28
|
it 'must pass along extractor metadata from the child' do
|
29
29
|
::Starscope::Lang::Dummy.expects(:extract).returns a: 1, b: 3
|
30
|
-
@extractor.extract(:foo, '---').must_equal a: 1, b: 3
|
30
|
+
_(@extractor.extract(:foo, '---')).must_equal a: 1, b: 3
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'must pass along the name from the child' do
|
34
|
-
@extractor.name.must_equal ::Starscope::Lang::Dummy.name
|
34
|
+
_(@extractor.name).must_equal ::Starscope::Lang::Dummy.name
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'must override-merge yielded args based on line number' do
|
38
38
|
::Starscope::Lang::Dummy.expects(:extract).yields(:foo, :bar, line_no: 2, foo: :bar)
|
39
39
|
|
40
40
|
@extractor.extract(:foo, '---') do |tbl, name, args|
|
41
|
-
tbl.must_equal :foo
|
42
|
-
name.must_equal :bar
|
43
|
-
args.must_equal line_no: 15, foo: :bar
|
41
|
+
_(tbl).must_equal :foo
|
42
|
+
_(name).must_equal :bar
|
43
|
+
_(args).must_equal line_no: 15, foo: :bar
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/test/unit/langs/erb_test.rb
CHANGED
@@ -4,33 +4,33 @@ describe Starscope::Lang::ERB do
|
|
4
4
|
before do
|
5
5
|
@frags = []
|
6
6
|
Starscope::Lang::ERB.extract(ERB_SAMPLE, File.read(ERB_SAMPLE)) do |tbl, name, args|
|
7
|
-
tbl.must_equal Starscope::DB::FRAGMENT
|
8
|
-
name.must_equal :Ruby
|
7
|
+
_(tbl).must_equal Starscope::DB::FRAGMENT
|
8
|
+
_(name).must_equal :Ruby
|
9
9
|
@frags << args
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'must match erb files' do
|
14
|
-
Starscope::Lang::ERB.match_file(ERB_SAMPLE).must_equal true
|
14
|
+
_(Starscope::Lang::ERB.match_file(ERB_SAMPLE)).must_equal true
|
15
15
|
end
|
16
16
|
|
17
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
|
18
|
+
_(Starscope::Lang::ERB.match_file(GOLANG_SAMPLE)).must_equal false
|
19
|
+
_(Starscope::Lang::ERB.match_file(EMPTY_FILE)).must_equal false
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'must identify all fragments' do
|
23
|
-
@frags.must_equal [{ frag: ' if foo ', line_no: 1 },
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
35
|
end
|
36
36
|
end
|
@@ -10,89 +10,89 @@ describe Starscope::Lang::Golang do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'must match golang files' do
|
13
|
-
Starscope::Lang::Golang.match_file(GOLANG_SAMPLE).must_equal true
|
13
|
+
_(Starscope::Lang::Golang.match_file(GOLANG_SAMPLE)).must_equal true
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'must not match non-golang files' do
|
17
|
-
Starscope::Lang::Golang.match_file(RUBY_SAMPLE).must_equal false
|
18
|
-
Starscope::Lang::Golang.match_file(EMPTY_FILE).must_equal false
|
17
|
+
_(Starscope::Lang::Golang.match_file(RUBY_SAMPLE)).must_equal false
|
18
|
+
_(Starscope::Lang::Golang.match_file(EMPTY_FILE)).must_equal false
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'must identify definitions' do
|
22
|
-
@db.keys.must_include :defs
|
22
|
+
_(@db.keys).must_include :defs
|
23
23
|
defs = @db[:defs].map { |x| x[:name][-1] }
|
24
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 :
|
35
|
-
defs.must_include :single_const
|
36
|
-
|
37
|
-
defs.wont_include :
|
38
|
-
defs.wont_include :
|
39
|
-
defs.wont_include :
|
40
|
-
defs.wont_include :
|
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_Äunicode
|
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
41
|
end
|
42
42
|
|
43
43
|
it 'must identify endings' do
|
44
|
-
@db.keys.must_include :end
|
45
|
-
@db[:end].count.must_equal 7
|
44
|
+
_(@db.keys).must_include :end
|
45
|
+
_(@db[:end].count).must_equal 7
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'must identify function calls' do
|
49
|
-
@db.keys.must_include :calls
|
49
|
+
_(@db.keys).must_include :calls
|
50
50
|
calls = @db[:calls].group_by { |x| x[:name][-1] }
|
51
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
|
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
63
|
end
|
64
64
|
|
65
65
|
it 'must identify variable assignments' do
|
66
|
-
@db.keys.must_include :assigns
|
66
|
+
_(@db.keys).must_include :assigns
|
67
67
|
assigns = @db[:assigns].group_by { |x| x[:name][-1] }
|
68
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
|
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
81
|
end
|
82
82
|
|
83
83
|
it 'must identify imports' do
|
84
|
-
@db.keys.must_include :imports
|
84
|
+
_(@db.keys).must_include :imports
|
85
85
|
imports = @db[:imports].group_by { |x| x[:name][-1] }
|
86
86
|
|
87
|
-
imports.keys.must_include :fmt
|
87
|
+
_(imports.keys).must_include :fmt
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'must correctly find the end of string constants' do
|
91
|
-
Starscope::Lang::Golang.find_end_of_string('"123"foo', 0).must_equal 4
|
92
|
-
Starscope::Lang::Golang.find_end_of_string('a"123"foo', 0).must_equal 1
|
93
|
-
Starscope::Lang::Golang.find_end_of_string('a"123"foo', 1).must_equal 5
|
94
|
-
Starscope::Lang::Golang.find_end_of_string('"1\""foo', 0).must_equal 4
|
95
|
-
Starscope::Lang::Golang.find_end_of_string('"1\\""foo', 0).must_equal 4
|
96
|
-
Starscope::Lang::Golang.find_end_of_string('"1\\\\\"foo', 0).must_equal 9
|
91
|
+
_(Starscope::Lang::Golang.find_end_of_string('"123"foo', 0)).must_equal 4
|
92
|
+
_(Starscope::Lang::Golang.find_end_of_string('a"123"foo', 0)).must_equal 1
|
93
|
+
_(Starscope::Lang::Golang.find_end_of_string('a"123"foo', 1)).must_equal 5
|
94
|
+
_(Starscope::Lang::Golang.find_end_of_string('"1\""foo', 0)).must_equal 4
|
95
|
+
_(Starscope::Lang::Golang.find_end_of_string('"1\\""foo', 0)).must_equal 4
|
96
|
+
_(Starscope::Lang::Golang.find_end_of_string('"1\\\\\"foo', 0)).must_equal 9
|
97
97
|
end
|
98
98
|
end
|