synt 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/synt/similar.rb +10 -2
- data/lib/synt/version.rb +1 -1
- data/spec/synt_spec.rb +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07d8eb90258e1d9b95e1f14d9d93a0f742426c98
|
4
|
+
data.tar.gz: 48febfb847f4d9031c8b0335c8ffe408728bf8ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d46ef30ae4c429863047b957d1eea15ff1e4c19cde044b93ad785a85d3818904d5df97531c48ac0e56675784fb98237d22a9db9c03c38fbe77badcd6c1714050
|
7
|
+
data.tar.gz: 3f1e5c9381a6d790d6f9da8f52929a1160a77f29f931e348a987cf8614dd27c4f3b12e29bb803466624e4a010b7a47dbf568bfdc500110f9d28584b321595ca4
|
data/lib/synt/similar.rb
CHANGED
@@ -8,12 +8,20 @@ define 'Synt'
|
|
8
8
|
module Synt::Similar
|
9
9
|
extend self
|
10
10
|
|
11
|
+
def determine string_or_file
|
12
|
+
if File.exists? string_or_file
|
13
|
+
IO.read string_or_file
|
14
|
+
else
|
15
|
+
string_or_file || ''
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
11
19
|
def compare opts
|
12
20
|
error 'no compare propery provided' unless opts[:compare]
|
13
21
|
error 'no to propery provided' unless opts[:to]
|
14
22
|
|
15
|
-
src = opts[:compare]
|
16
|
-
cmp = opts[:to]
|
23
|
+
src = determine opts[:compare]
|
24
|
+
cmp = determine opts[:to]
|
17
25
|
algorithm = algorithms[(opts[:algorithm] || 'jaccard').to_sym]
|
18
26
|
n_start, n_end = ngram_range opts[:ngram]
|
19
27
|
src_t = normalize_ripper_tokens Synt::Parser.parse(src)
|
data/lib/synt/version.rb
CHANGED
data/spec/synt_spec.rb
CHANGED
@@ -13,6 +13,32 @@ describe Synt::Similar do
|
|
13
13
|
let(:dissimilar_a_path) { 'spec/fixtures/compare-rb-dissimilar-a.rb' }
|
14
14
|
let(:dissimilar_b_path) { 'spec/fixtures/compare-rb-dissimilar-b.rb' }
|
15
15
|
|
16
|
+
context 'cli' do
|
17
|
+
context 'comparing things' do
|
18
|
+
context 'that are Files' do
|
19
|
+
before do
|
20
|
+
allow(File).to receive(:exists?).and_return(true)
|
21
|
+
expect(IO).to receive(:read).and_return("42").twice
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'read both files from the file system' do
|
25
|
+
subject.compare compare: "file/path.rb", to: "file/path2"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'that are Strings' do
|
30
|
+
before do
|
31
|
+
allow(File).to receive(:exists?).and_return(false)
|
32
|
+
expect(IO).to_not receive(:read)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should not read any files' do
|
36
|
+
subject.compare compare: "file/path.rb", to: "file/path2"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
16
42
|
context 'duplicate code comparison' do
|
17
43
|
let(:dupe) { file_to_s duplicate_path }
|
18
44
|
|