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
@@ -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
|
@@ -10,78 +10,78 @@ describe Starscope::Lang::Javascript do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'must match js files' do
|
13
|
-
Starscope::Lang::Javascript.match_file(JAVASCRIPT_EXAMPLE).must_equal true
|
13
|
+
_(Starscope::Lang::Javascript.match_file(JAVASCRIPT_EXAMPLE)).must_equal true
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'must not match non-js files' do
|
17
|
-
Starscope::Lang::Javascript.match_file(RUBY_SAMPLE).must_equal false
|
18
|
-
Starscope::Lang::Javascript.match_file(EMPTY_FILE).must_equal false
|
17
|
+
_(Starscope::Lang::Javascript.match_file(RUBY_SAMPLE)).must_equal false
|
18
|
+
_(Starscope::Lang::Javascript.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 :Component
|
26
|
-
defs.must_include :StyleSheet
|
27
|
-
defs.must_include :styles
|
28
|
-
defs.must_include :NavigatorRouteMapper
|
29
|
-
defs.must_include :LeftButton
|
30
|
-
defs.must_include :RightButton
|
31
|
-
defs.must_include :_tabItem
|
32
|
-
defs.must_include :render
|
33
|
-
defs.must_include :setRef
|
34
|
-
defs.must_include :route
|
35
|
-
defs.must_include :foo
|
36
|
-
defs.must_include :MyStat
|
37
|
-
defs.must_include :myStatFunc
|
38
|
-
defs.must_include :bracelessMethod
|
25
|
+
_(defs).must_include :Component
|
26
|
+
_(defs).must_include :StyleSheet
|
27
|
+
_(defs).must_include :styles
|
28
|
+
_(defs).must_include :NavigatorRouteMapper
|
29
|
+
_(defs).must_include :LeftButton
|
30
|
+
_(defs).must_include :RightButton
|
31
|
+
_(defs).must_include :_tabItem
|
32
|
+
_(defs).must_include :render
|
33
|
+
_(defs).must_include :setRef
|
34
|
+
_(defs).must_include :route
|
35
|
+
_(defs).must_include :foo
|
36
|
+
_(defs).must_include :MyStat
|
37
|
+
_(defs).must_include :myStatFunc
|
38
|
+
_(defs).must_include :bracelessMethod
|
39
39
|
|
40
|
-
defs.wont_include :setStyle
|
41
|
-
defs.wont_include :setState
|
42
|
-
defs.wont_include :fontFamily
|
43
|
-
defs.wont_include :navigator
|
44
|
-
defs.wont_include :madness
|
45
|
-
defs.wont_include :React
|
40
|
+
_(defs).wont_include :setStyle
|
41
|
+
_(defs).wont_include :setState
|
42
|
+
_(defs).wont_include :fontFamily
|
43
|
+
_(defs).wont_include :navigator
|
44
|
+
_(defs).wont_include :madness
|
45
|
+
_(defs).wont_include :React
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'must only tag static classes once' do
|
49
|
-
@db[:defs].count { |x| x[:name][-1] == :MyStat }.must_equal 1
|
49
|
+
_(@db[:defs].count { |x| x[:name][-1] == :MyStat }).must_equal 1
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'must identify endings' do
|
53
|
-
@db.keys.must_include :end
|
54
|
-
@db[:end].count.must_equal 12
|
53
|
+
_(@db.keys).must_include :end
|
54
|
+
_(@db[:end].count).must_equal 12
|
55
55
|
|
56
56
|
# bracelessMethod doesn't have a taggable end token so
|
57
57
|
# we have to do a little dancing with an empty name and a precise column
|
58
|
-
@db[:end][0][:name].must_equal [:'']
|
59
|
-
@db[:end][0][:col].must_equal 27
|
58
|
+
_(@db[:end][0][:name]).must_equal [:'']
|
59
|
+
_(@db[:end][0][:col]).must_equal 27
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'must identify function calls' do
|
63
|
-
@db.keys.must_include :calls
|
63
|
+
_(@db.keys).must_include :calls
|
64
64
|
calls = @db[:calls].group_by { |x| x[:name][-1] }
|
65
65
|
|
66
|
-
calls.keys.must_include :create
|
67
|
-
calls.keys.must_include :setStyle
|
68
|
-
calls.keys.must_include :pop
|
69
|
-
calls.keys.must_include :fetchData
|
70
|
-
calls.keys.must_include :setState
|
71
|
-
calls.keys.must_include :func1
|
66
|
+
_(calls.keys).must_include :create
|
67
|
+
_(calls.keys).must_include :setStyle
|
68
|
+
_(calls.keys).must_include :pop
|
69
|
+
_(calls.keys).must_include :fetchData
|
70
|
+
_(calls.keys).must_include :setState
|
71
|
+
_(calls.keys).must_include :func1
|
72
72
|
|
73
|
-
calls[:pop].count.must_equal 1
|
74
|
-
calls[:_tabItem].count.must_equal 3
|
73
|
+
_(calls[:pop].count).must_equal 1
|
74
|
+
_(calls[:_tabItem].count).must_equal 3
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'must identify module requires' do
|
78
|
-
@db.keys.must_include :requires
|
78
|
+
_(@db.keys).must_include :requires
|
79
79
|
requires = @db[:requires].group_by { |x| x[:name][-1] }
|
80
80
|
|
81
|
-
requires.keys.must_include :'foo-bar'
|
82
|
-
requires.keys.must_include :'react-native'
|
83
|
-
requires.keys.wont_include :NOPE
|
84
|
-
requires.keys.wont_include
|
85
|
-
requires.keys.wont_include
|
81
|
+
_(requires.keys).must_include :'foo-bar'
|
82
|
+
_(requires.keys).must_include :'react-native'
|
83
|
+
_(requires.keys).wont_include :NOPE
|
84
|
+
_(requires.keys).wont_include true
|
85
|
+
_(requires.keys).wont_include false
|
86
86
|
end
|
87
87
|
end
|
@@ -10,57 +10,57 @@ describe Starscope::Lang::Ruby do
|
|
10
10
|
end
|
11
11
|
|
12
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
|
13
|
+
_(Starscope::Lang::Ruby.match_file(RUBY_SAMPLE)).must_equal true
|
14
|
+
_(Starscope::Lang::Ruby.match_file('bin/starscope')).must_equal true
|
15
15
|
end
|
16
16
|
|
17
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
|
18
|
+
_(Starscope::Lang::Ruby.match_file(GOLANG_SAMPLE)).must_equal false
|
19
|
+
_(Starscope::Lang::Ruby.match_file(EMPTY_FILE)).must_equal false
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'must identify function definitions' do
|
23
|
-
@db.keys.must_include :defs
|
23
|
+
_(@db.keys).must_include :defs
|
24
24
|
defs = @db[:defs].map { |x| x[:name][-1] }
|
25
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
|
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
31
|
end
|
32
32
|
|
33
33
|
it 'must identify constant definitions' do
|
34
|
-
@db[:defs].map { |x| x[:name][-1] }.must_include :PBAR_FORMAT
|
34
|
+
_(@db[:defs].map { |x| x[:name][-1] }).must_include :PBAR_FORMAT
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'must identify endings' do
|
38
|
-
@db.keys.must_include :end
|
39
|
-
@db[:end].count.must_equal 13
|
38
|
+
_(@db.keys).must_include :end
|
39
|
+
_(@db[:end].count).must_equal 13
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'must identify function calls' do
|
43
|
-
@db.keys.must_include :calls
|
43
|
+
_(@db.keys).must_include :calls
|
44
44
|
calls = @db[:calls].group_by { |x| x[:name][-1] }
|
45
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
|
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
50
|
end
|
51
51
|
|
52
52
|
it 'must identify variable assignments' do
|
53
|
-
@db.keys.must_include :assigns
|
53
|
+
_(@db.keys).must_include :assigns
|
54
54
|
assigns = @db[:assigns].group_by { |x| x[:name][-1] }
|
55
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
|
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
62
|
|
63
|
-
assigns.keys.wont_include '='
|
64
|
-
assigns.keys.wont_include
|
63
|
+
_(assigns.keys).wont_include :'='
|
64
|
+
_(assigns.keys).wont_include :<
|
65
65
|
end
|
66
66
|
end
|
data/test/unit/output_test.rb
CHANGED
@@ -6,7 +6,7 @@ describe Starscope::Output do
|
|
6
6
|
out = Starscope::Output.new(:quiet, buf)
|
7
7
|
out.normal('foo')
|
8
8
|
out.extra('foo')
|
9
|
-
buf.size.must_equal 0
|
9
|
+
_(buf.size).must_equal 0
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'must be normal' do
|
@@ -14,7 +14,7 @@ describe Starscope::Output do
|
|
14
14
|
out = Starscope::Output.new(:normal, buf)
|
15
15
|
out.normal('foo')
|
16
16
|
out.extra('foo')
|
17
|
-
buf.size.must_equal 4
|
17
|
+
_(buf.size).must_equal 4
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'must be verbose' do
|
@@ -22,6 +22,6 @@ describe Starscope::Output do
|
|
22
22
|
out = Starscope::Output.new(:verbose, buf)
|
23
23
|
out.normal('foo')
|
24
24
|
out.extra('foo')
|
25
|
-
buf.size.must_equal 8
|
25
|
+
_(buf.size).must_equal 8
|
26
26
|
end
|
27
27
|
end
|
data/test/unit/queryable_test.rb
CHANGED
@@ -1,61 +1,61 @@
|
|
1
1
|
require_relative '../test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
lang: :ruby
|
21
|
-
}
|
3
|
+
SAMPLE_RECORDS = [
|
4
|
+
{ name: [:'[abc'], foo: 'baz' },
|
5
|
+
{ name: [:'not a match'], foo: 'bar', x: 'y' },
|
6
|
+
{ name: %i[a b c d], file: :somefile }
|
7
|
+
].freeze
|
8
|
+
|
9
|
+
class MockQuerable
|
10
|
+
include Starscope::Queryable
|
11
|
+
def initialize
|
12
|
+
@tables = {
|
13
|
+
mytable: SAMPLE_RECORDS,
|
14
|
+
empty_table: []
|
15
|
+
}
|
16
|
+
@meta = {
|
17
|
+
files: {
|
18
|
+
somefile: {
|
19
|
+
lang: :ruby
|
22
20
|
}
|
23
21
|
}
|
24
|
-
|
22
|
+
}
|
25
23
|
end
|
24
|
+
end
|
26
25
|
|
26
|
+
describe Starscope::Queryable do
|
27
27
|
before do
|
28
28
|
@mock = MockQuerable.new
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'must handle empty input' do
|
32
|
-
@mock.query(:empty_table, 'foo').must_be_empty
|
32
|
+
_(@mock.query(:empty_table, 'foo')).must_be_empty
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'must handle scoped queries' do
|
36
|
-
@mock.query(:mytable, 'a::b::').must_equal [SAMPLE_RECORDS[2]]
|
36
|
+
_(@mock.query(:mytable, 'a::b::')).must_equal [SAMPLE_RECORDS[2]]
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'must handle regex queries' do
|
40
|
-
@mock.query(:mytable, 'a[bc]{2}').must_equal [SAMPLE_RECORDS[0]]
|
40
|
+
_(@mock.query(:mytable, 'a[bc]{2}')).must_equal [SAMPLE_RECORDS[0]]
|
41
41
|
|
42
|
-
@mock.query(:mytable, 'a.*d').must_equal [SAMPLE_RECORDS[2]]
|
42
|
+
_(@mock.query(:mytable, 'a.*d')).must_equal [SAMPLE_RECORDS[2]]
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'must handle malformed regexes' do
|
46
|
-
@mock.query(:mytable, '[abc').must_equal [SAMPLE_RECORDS[0]]
|
46
|
+
_(@mock.query(:mytable, '[abc')).must_equal [SAMPLE_RECORDS[0]]
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'must handle simple filters' do
|
50
|
-
@mock.query(:mytable, '.*', foo: 'bar').must_equal [SAMPLE_RECORDS[1]]
|
50
|
+
_(@mock.query(:mytable, '.*', foo: 'bar')).must_equal [SAMPLE_RECORDS[1]]
|
51
51
|
end
|
52
52
|
|
53
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
|
54
|
+
_(@mock.query(:mytable, '.*', foo: 'bar', x: 'y')).must_equal [SAMPLE_RECORDS[1]]
|
55
|
+
_(@mock.query(:mytable, '.*', foo: 'bar', x: 'nope')).must_be_empty
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'must handle filters on file properties' do
|
59
|
-
@mock.query(:mytable, '.*', lang: 'ruby').must_equal [SAMPLE_RECORDS[2]]
|
59
|
+
_(@mock.query(:mytable, '.*', lang: 'ruby')).must_equal [SAMPLE_RECORDS[2]]
|
60
60
|
end
|
61
61
|
end
|