Skip to content

Commit

Permalink
Only return the re-indented line if it changed.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/DietRB/trunk@4852 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
alloy committed Oct 31, 2010
1 parent 3546712 commit 052972f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/irb/formatter.rb
Expand Up @@ -33,12 +33,12 @@ def indentation(level)

def prompt(context, indent = false)
prompt = case @prompt
when :default then DEFAULT_PROMPT % [context.object.inspect, context.line, context.source.level]
when :default then DEFAULT_PROMPT % [context.object.inspect, context.line, context.level]
when :simple then SIMPLE_PROMPT
else
NO_PROMPT
end
indent ? (prompt + indentation(context.source.level)) : prompt
indent ? (prompt + indentation(context.level)) : prompt
end

def inspect_object(object)
Expand All @@ -60,9 +60,10 @@ def minimal_inspect_object(object)
def reindent_last_line_in_source(source)
old_level = source.level
yield
line = source.buffer[-1]
new_line = indentation(source.level < old_level ? source.level : old_level)
new_line += source.buffer[-1].lstrip
source.buffer[-1] = new_line
new_line += line.lstrip
source.buffer[-1] = new_line unless new_line == line
end

def result(object)
Expand Down
9 changes: 7 additions & 2 deletions spec/formatter_spec.rb
Expand Up @@ -12,8 +12,8 @@
@formatter.prompt(@context).should == "irb(main):001:0> "
@context.instance_variable_set(:@line, 23)
@formatter.prompt(@context).should == "irb(main):023:0> "
@context.source << "def foo"
@formatter.prompt(@context).should == "irb(main):023:1> "
@context.process_line("def foo")
@formatter.prompt(@context).should == "irb(main):024:1> "
end

it "describes the context's object in the prompt" do
Expand Down Expand Up @@ -103,4 +103,9 @@ def object.__id__; 2158110700; end
end
source.to_s.should == lines.map(&:last).join("\n")
end

it "returns nil if the last line was not reindented" do
@context.source << "class A"
@formatter.reindent_last_line_in_source(@context.source) { @context.source << " def foo" }.should == nil
end
end

0 comments on commit 052972f

Please sign in to comment.