Skip to content

Commit

Permalink
+ Fixed reporting / recording of methods in singleton class blocks. (…
Browse files Browse the repository at this point in the history
…mihu)

[git-p4: depot-paths = "//src/flog/dev/": change = 8024]
  • Loading branch information
zenspider committed Nov 28, 2012
1 parent 11f8fd5 commit af45b88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/flog.rb
Expand Up @@ -79,7 +79,7 @@ class Flog < SexpProcessor
@@no_method = :none

attr_accessor :multiplier
attr_reader :calls, :option, :class_stack, :method_stack, :mass
attr_reader :calls, :option, :class_stack, :method_stack, :mass, :sclass
attr_reader :method_locations

def self.plugins
Expand Down Expand Up @@ -324,6 +324,7 @@ def in_method(name, file, line)
def initialize option = {}
super()
@option = option
@sclass = nil
@class_stack = []
@method_stack = []
@method_locations = {}
Expand Down Expand Up @@ -621,7 +622,8 @@ def process_dasgn_curr(exp) # FIX: remove
alias :process_lasgn :process_dasgn_curr

def process_defn(exp)
in_method exp.shift, exp.file, exp.line do
name = @sclass ? "::#{exp.shift}" : exp.shift
in_method name, exp.file, exp.line do
process_until_empty exp
end
s()
Expand Down Expand Up @@ -736,10 +738,12 @@ def process_module(exp)
end

def process_sclass(exp)
@sclass = true
penalize_by 0.5 do
process exp.shift # recv
process_until_empty exp
end
@sclass = nil

add_to_score :sclass
s()
Expand Down
15 changes: 15 additions & 0 deletions test/test_flog.rb
Expand Up @@ -399,6 +399,21 @@ def test_process_defn
util_process sexp, 0.275, :lit_fixnum => 0.275
end

def test_process_defn_in_self
sexp = s(:sclass, s(:self),
s(:defn, :x,
s(:args, :y),
s(:lit, 42)))

setup
@flog.process sexp

exp = {'main::x' => {:lit_fixnum => 0.375}, 'main#none' => {:sclass => 5.0}}
assert_equal exp, @flog.calls

assert_in_delta 5.375, @flog.total
end

def test_process_defs
@meth = "::x" # HACK, I don't like this

Expand Down

0 comments on commit af45b88

Please sign in to comment.