-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsexp_lines_spec.rb
76 lines (66 loc) · 2.14 KB
/
sexp_lines_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require "spec_helper"
module CC::Engine::Analyzers
RSpec.describe SexpLines do
describe "violation location" do
it "gets appropriate locations for rescue blocks" do
source = <<-SOURCE
begin
foo
rescue SyntaxError => e
Jekyll.logger.warn "YAML Exception reading \#{File.join(base, name)}: \#{e.message}"
rescue Exception => e
Jekyll.logger.warn "Error reading file \#{File.join(base, name)}: \#{e.message}"
end
SOURCE
locations = locations_from_source(source)
expect(locations.count).to eq 2
expect(locations[0].begin_line).to eq(3)
expect(locations[0].end_line).to eq(7)
expect(locations[1].begin_line).to eq(5)
expect(locations[1].end_line).to eq(7)
end
it "gets appropriate locations for hashes" do
source = <<-SOURCE
{
name: "Bear Vs. Shark",
greatest: true,
city: "Ferndale",
state: "Michigan",
email: "[email protected]",
phone: "9145551234",
}
{
name: "Bars of Gold",
greatest: true,
city: "Ferndale",
state: "Michigan",
email: "[email protected]",
phone: "9145551234",
}
SOURCE
locations = locations_from_source(source, mass: 1)
expect(locations.count).to eq 2
expect([locations[0].begin_line, locations[0].end_line]).to eq([1, 7])
expect([locations[1].begin_line, locations[1].end_line]).to eq([10, 16])
end
end
def locations_from_source(source, flay_opts = {})
flay = CCFlay.new({
diff: false,
mass: 18,
summary: false,
verbose: false,
number: true,
timeout: 10,
liberal: false,
fuzzy: false,
only: nil,
}.merge(flay_opts))
sexp = RubyParser.new.process(source, "file.rb")
flay.process_sexp(sexp)
report = flay.analyze[0] or raise "No analysis"
sexps = flay.hashes[report.structural_hash]
sexps.map { |sexp| SexpLines.new(sexp) }
end
end
end