synt 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -0
- data/Gemfile +4 -3
- data/Gemfile.lock +14 -0
- data/bin/lint +1 -1
- data/bin/synt +0 -11
- data/bin/test +2 -0
- data/bin/test-cov +3 -0
- data/lib/synt/cli.rb +16 -17
- data/lib/synt/similar.rb +11 -16
- data/lib/synt/version.rb +1 -1
- data/readme.md +12 -4
- data/spec/fixtures/compare-rb-dissimilar-a.rb +7 -0
- data/spec/fixtures/compare-rb-dissimilar-b.rb +11 -0
- data/spec/fixtures/compare-rb-duplicate.rb +3 -0
- data/spec/fixtures/compare-rb-similar-a.rb +10 -0
- data/spec/fixtures/compare-rb-similar-b.rb +10 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/synt_spec.rb +63 -0
- data/synt.gemspec +3 -2
- metadata +20 -6
- data/spec/synt.spec +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db6a29021a6d20069699409309b0d876e895cfe6
|
4
|
+
data.tar.gz: 2917519bf768b6f16d51eab71811716f7aef5297
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 616a83ae7baf88e13f25c1fd11677e3cad5781808029e560a2e3d0808bb570cd4aaf531908331d8a0b50a1bf2b47a4cfc6b57854685aafb928facef93b37a8e0
|
7
|
+
data.tar.gz: e7d885f8d603edbb1e93def360a851537ff6ebd9075a1bd0ff5eed613890340401b2ece433119acdda8a52bdbbc79a585ebbd9cd8fc04e8327094d6681d14297
|
data/.rubocop.yml
CHANGED
@@ -2,3 +2,23 @@ Style/Documentation:
|
|
2
2
|
Enabled: false
|
3
3
|
Style/Encoding:
|
4
4
|
Enabled: false
|
5
|
+
Style/MethodDefParentheses:
|
6
|
+
Enabled: false
|
7
|
+
Style/ModuleFunction:
|
8
|
+
Enabled: false
|
9
|
+
Style/StringLiterals:
|
10
|
+
Enabled: false
|
11
|
+
Style/GuardClause:
|
12
|
+
Enabled: false
|
13
|
+
Style/ClassAndModuleChildren:
|
14
|
+
Enabled: false
|
15
|
+
Style/Blocks:
|
16
|
+
Enabled: false
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Max: 18
|
19
|
+
Metrics/CyclomaticComplexity:
|
20
|
+
Max: 7
|
21
|
+
Style/FileName:
|
22
|
+
Enabled: false
|
23
|
+
Style/WordArray:
|
24
|
+
MinSize: 2
|
data/Gemfile
CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'slop', '3.6.0'
|
4
4
|
gem 'manowar', '0.0.1'
|
5
|
-
gem '
|
6
|
-
gem '
|
7
|
-
gem 'simplecov
|
5
|
+
gem 'rspec', '3.0.0', require: false, group: :development
|
6
|
+
gem 'rubocop', '0.25.0', require: false, group: :development
|
7
|
+
gem 'simplecov', '0.9.0', require: false, group: :development
|
8
|
+
gem 'simplecov-lcov', require: false, group: :development
|
data/Gemfile.lock
CHANGED
@@ -2,6 +2,7 @@ GEM
|
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
4
|
ast (2.0.0)
|
5
|
+
diff-lcs (1.2.5)
|
5
6
|
docile (1.1.5)
|
6
7
|
manowar (0.0.1)
|
7
8
|
multi_json (1.10.1)
|
@@ -10,6 +11,18 @@ GEM
|
|
10
11
|
slop (~> 3.4, >= 3.4.5)
|
11
12
|
powerpack (0.0.9)
|
12
13
|
rainbow (2.0.0)
|
14
|
+
rspec (3.0.0)
|
15
|
+
rspec-core (~> 3.0.0)
|
16
|
+
rspec-expectations (~> 3.0.0)
|
17
|
+
rspec-mocks (~> 3.0.0)
|
18
|
+
rspec-core (3.0.3)
|
19
|
+
rspec-support (~> 3.0.0)
|
20
|
+
rspec-expectations (3.0.3)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.0.0)
|
23
|
+
rspec-mocks (3.0.3)
|
24
|
+
rspec-support (~> 3.0.0)
|
25
|
+
rspec-support (3.0.3)
|
13
26
|
rubocop (0.25.0)
|
14
27
|
parser (>= 2.2.0.pre.4, < 3.0)
|
15
28
|
powerpack (~> 0.0.6)
|
@@ -29,6 +42,7 @@ PLATFORMS
|
|
29
42
|
|
30
43
|
DEPENDENCIES
|
31
44
|
manowar (= 0.0.1)
|
45
|
+
rspec (= 3.0.0)
|
32
46
|
rubocop (= 0.25.0)
|
33
47
|
simplecov (= 0.9.0)
|
34
48
|
simplecov-lcov
|
data/bin/lint
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
#!/usr/bin/env sh
|
2
|
-
bundle exec rubocop
|
2
|
+
bundle exec rubocop lib spec -f e
|
data/bin/synt
CHANGED
@@ -1,14 +1,3 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
if ENV.has_key? 'TEST_COV'
|
4
|
-
require 'simplecov'
|
5
|
-
require 'simplecov-lcov'
|
6
|
-
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
7
|
-
SimpleCov.start do
|
8
|
-
add_filter "/fixtures/"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
2
|
require_relative '../lib/synt'
|
13
|
-
|
14
3
|
Synt.new
|
data/bin/test
ADDED
data/bin/test-cov
ADDED
data/lib/synt/cli.rb
CHANGED
@@ -8,27 +8,26 @@ module Synt::CLI
|
|
8
8
|
extend self
|
9
9
|
|
10
10
|
def parse
|
11
|
-
Slop.parse help: true, &
|
11
|
+
Slop.parse help: true, &API
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
banner 'Usage: synt.rb [options]'
|
16
|
+
API = proc {
|
17
|
+
banner 'Usage: synt.rb [options]'
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
on 't=', 'tokenize=', 'file or string to tokenize'
|
20
|
+
on 'c=', 'compare=', 'File or String to compare to something.'
|
21
|
+
on 't=', 'to=', 'File or String to compare against.'
|
22
|
+
on 'a=', 'algorithm=', 'Similarity algorithm [default=jaccard,tanimoto].'
|
23
|
+
on 'n=', 'ngram=', 'Specify what ngrams are generated and used for
|
24
|
+
comparing token sequences.
|
25
|
+
[default=1,2,4..5,10,...,all]'
|
26
|
+
on 'd=', 'threshold=', 'Similarity threshold and exit with error.'
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
28
|
+
on '-v', 'version', 'Print the version.' do
|
29
|
+
puts Synt::VERSION
|
30
|
+
exit 0
|
31
|
+
end
|
32
|
+
}
|
34
33
|
end
|
data/lib/synt/similar.rb
CHANGED
@@ -9,15 +9,13 @@ module Synt::Similar
|
|
9
9
|
extend self
|
10
10
|
|
11
11
|
def compare opts
|
12
|
-
error 'no compare propery provided'
|
13
|
-
error 'no to propery provided'
|
12
|
+
error 'no compare propery provided' unless opts[:compare]
|
13
|
+
error 'no to propery provided' unless opts[:to]
|
14
14
|
|
15
15
|
src = opts[:compare] || ''
|
16
16
|
cmp = opts[:to] || ''
|
17
|
-
algorithm = algorithms[opts[:algorithm] || 'jaccard']
|
18
|
-
src_t = cmp_t = nil
|
17
|
+
algorithm = algorithms[(opts[:algorithm] || 'jaccard').to_sym]
|
19
18
|
n_start, n_end = ngram_range opts[:ngram]
|
20
|
-
|
21
19
|
src_t = normalize_ripper_tokens Synt::Parser.parse(src)
|
22
20
|
cmp_t = normalize_ripper_tokens Synt::Parser.parse(cmp)
|
23
21
|
|
@@ -32,29 +30,26 @@ module Synt::Similar
|
|
32
30
|
private
|
33
31
|
|
34
32
|
def algorithms
|
35
|
-
{
|
33
|
+
{ jaccard: Jaccard, tanimoto: Tanimoto }
|
36
34
|
end
|
37
35
|
|
38
36
|
def generate_ngrams arr, start, nend
|
39
|
-
nend = arr.length
|
40
|
-
start = 1
|
37
|
+
nend = arr.length unless nend
|
38
|
+
start = 1 unless start
|
41
39
|
|
42
40
|
if nend > arr.length
|
43
|
-
|
41
|
+
start = nend = 1
|
42
|
+
puts 'ngram end value exceeds max length- setting start/end to: 1'
|
44
43
|
end
|
45
44
|
|
46
|
-
if start == nend && start == 1 # short circuit
|
47
|
-
return arr
|
48
|
-
end
|
45
|
+
return arr if start == nend && start == 1 # short circuit
|
49
46
|
|
50
47
|
sets = []
|
51
48
|
|
52
49
|
(start..nend).to_a.each_index do |n_len|
|
53
|
-
arr.
|
50
|
+
arr.each_index do |index|
|
54
51
|
s_len = index + n_len
|
55
|
-
if s_len <= arr.length
|
56
|
-
sets.push arr[index, s_len].join('')
|
57
|
-
end
|
52
|
+
sets.push arr[index, s_len].join('') if s_len <= arr.length
|
58
53
|
end
|
59
54
|
end
|
60
55
|
|
data/lib/synt/version.rb
CHANGED
data/readme.md
CHANGED
@@ -10,8 +10,16 @@ This is the Ruby implementation of Synt.
|
|
10
10
|
|
11
11
|
For more languages, see the top level [Synt](http://github.com/brentlintner/synt) project.
|
12
12
|
|
13
|
-
###
|
13
|
+
### Installation
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
gem install synt
|
16
|
+
|
17
|
+
### Usage
|
18
|
+
|
19
|
+
synt -h
|
20
|
+
|
21
|
+
### Using In Code
|
22
|
+
|
23
|
+
This is a TODO. :-)
|
24
|
+
|
25
|
+
In the meantime, please figure out at your own risk, or use the top level project.
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
if ENV.key? 'TEST_COV'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'simplecov-lcov'
|
4
|
+
|
5
|
+
SimpleCov::Formatter::LcovFormatter.report_with_single_file = true
|
6
|
+
|
7
|
+
SimpleCov.formatters = [
|
8
|
+
SimpleCov::Formatter::LcovFormatter,
|
9
|
+
SimpleCov::Formatter::HTMLFormatter
|
10
|
+
]
|
11
|
+
|
12
|
+
SimpleCov.start do
|
13
|
+
add_filter "/fixtures/"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_to_s path
|
18
|
+
IO.readlines(path).join
|
19
|
+
end
|
data/spec/synt_spec.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative './spec_helper'
|
2
|
+
require_relative './../lib/synt/similar'
|
3
|
+
|
4
|
+
describe Synt::Similar do
|
5
|
+
subject { Synt::Similar }
|
6
|
+
|
7
|
+
algorithms = ['jaccard', 'tanimoto']
|
8
|
+
ngram_types = [1, '1..3', 'all']
|
9
|
+
|
10
|
+
let(:duplicate_path) { 'spec/fixtures/compare-rb-duplicate.rb' }
|
11
|
+
let(:similar_a_path) { 'spec/fixtures/compare-rb-similar-a.rb' }
|
12
|
+
let(:similar_b_path) { 'spec/fixtures/compare-rb-similar-b.rb' }
|
13
|
+
let(:dissimilar_a_path) { 'spec/fixtures/compare-rb-dissimilar-a.rb' }
|
14
|
+
let(:dissimilar_b_path) { 'spec/fixtures/compare-rb-dissimilar-b.rb' }
|
15
|
+
|
16
|
+
context 'duplicate code comparison' do
|
17
|
+
let(:dupe) { file_to_s duplicate_path }
|
18
|
+
|
19
|
+
algorithms.each do |algorithm|
|
20
|
+
context "using the #{algorithm} algorithm" do
|
21
|
+
ngram_types.each do |ngram|
|
22
|
+
context "with an ngram of #{ngram}" do
|
23
|
+
it 'is 100%' do
|
24
|
+
sim = subject.compare compare: dupe, to: dupe,
|
25
|
+
ngram: ngram, algorithm: algorithm
|
26
|
+
expect(sim).to eq 100
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'similar code comparison' do
|
35
|
+
let(:sim_a) { file_to_s similar_a_path }
|
36
|
+
let(:sim_b) { file_to_s similar_b_path }
|
37
|
+
|
38
|
+
algorithms.each do |algorithm|
|
39
|
+
context "using the #{algorithm} algorithm" do
|
40
|
+
it 'is ~81%' do
|
41
|
+
sim = subject.compare compare: sim_a, to: sim_b,
|
42
|
+
algorithm: algorithm
|
43
|
+
expect(80..82).to cover(sim)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'dissimilar code comparison' do
|
50
|
+
let(:dissim_a) { file_to_s dissimilar_a_path }
|
51
|
+
let(:dissim_b) { file_to_s dissimilar_b_path }
|
52
|
+
|
53
|
+
algorithms.each do |algorithm|
|
54
|
+
context "using the #{algorithm} algorithm" do
|
55
|
+
it 'is ~22%' do
|
56
|
+
sim = subject.compare compare: dissim_a, to: dissim_b,
|
57
|
+
algorithm: algorithm
|
58
|
+
expect(21..23).to cover(sim)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/synt.gemspec
CHANGED
@@ -10,14 +10,15 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["brent.lintner@gmail.com"]
|
11
11
|
spec.summary = "Similar code analysis."
|
12
12
|
spec.description = "Calculate the percentage of difference between code."
|
13
|
-
spec.homepage = "https://github.com/brentlintner/synt
|
13
|
+
spec.homepage = "https://github.com/brentlintner/synt"
|
14
14
|
spec.license = "ISC"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split("\n")
|
17
17
|
spec.executables = ["synt"]
|
18
|
-
spec.test_files = spec.files.grep(
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.required_ruby_version = '>= 1.9'
|
21
22
|
spec.add_runtime_dependency 'manowar', '0.0.1'
|
22
23
|
spec.add_runtime_dependency 'slop', '3.6.0'
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.7"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brent Lintner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: manowar
|
@@ -65,6 +65,8 @@ files:
|
|
65
65
|
- Gemfile.lock
|
66
66
|
- bin/lint
|
67
67
|
- bin/synt
|
68
|
+
- bin/test
|
69
|
+
- bin/test-cov
|
68
70
|
- lib/synt.rb
|
69
71
|
- lib/synt/cli.rb
|
70
72
|
- lib/synt/parser.rb
|
@@ -73,9 +75,15 @@ files:
|
|
73
75
|
- lib/synt/similar/tanimoto.rb
|
74
76
|
- lib/synt/version.rb
|
75
77
|
- readme.md
|
76
|
-
- spec/
|
78
|
+
- spec/fixtures/compare-rb-dissimilar-a.rb
|
79
|
+
- spec/fixtures/compare-rb-dissimilar-b.rb
|
80
|
+
- spec/fixtures/compare-rb-duplicate.rb
|
81
|
+
- spec/fixtures/compare-rb-similar-a.rb
|
82
|
+
- spec/fixtures/compare-rb-similar-b.rb
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
- spec/synt_spec.rb
|
77
85
|
- synt.gemspec
|
78
|
-
homepage: https://github.com/brentlintner/synt
|
86
|
+
homepage: https://github.com/brentlintner/synt
|
79
87
|
licenses:
|
80
88
|
- ISC
|
81
89
|
metadata: {}
|
@@ -87,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
95
|
requirements:
|
88
96
|
- - ">="
|
89
97
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
98
|
+
version: '1.9'
|
91
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
100
|
requirements:
|
93
101
|
- - ">="
|
@@ -100,4 +108,10 @@ signing_key:
|
|
100
108
|
specification_version: 4
|
101
109
|
summary: Similar code analysis.
|
102
110
|
test_files:
|
103
|
-
- spec/
|
111
|
+
- spec/fixtures/compare-rb-dissimilar-a.rb
|
112
|
+
- spec/fixtures/compare-rb-dissimilar-b.rb
|
113
|
+
- spec/fixtures/compare-rb-duplicate.rb
|
114
|
+
- spec/fixtures/compare-rb-similar-a.rb
|
115
|
+
- spec/fixtures/compare-rb-similar-b.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/synt_spec.rb
|
data/spec/synt.spec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# TODO
|