Skip to content

Commit

Permalink
Don't indent HEREDOCs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonl committed Aug 21, 2010
1 parent 21e94c9 commit 8deeaa8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/eden/formatters/indenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def self.format( source_file )
return unless options[:adjust_indents]
@current_indent = 0
source_file.each_line do |line|
next if line.tokens[0] && line.tokens[0].is?(:heredoc_body)
calculate_pre_indent(line)
adjust_indent(line)
calculate_post_indent(line)
Expand Down
20 changes: 20 additions & 0 deletions test/indenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ def test_should_use_correct_indent_character_when_indenting
end
end

def test_should_not_indent_heredoc
@sf.stubs(:source).returns(<<-SOURCE)
class Test
def function
rah = <<-HEREDOC
rah234
HEREDOC
end
end
SOURCE
@sf.tokenize!
Indenter.format( @sf )
assert_equal "class Test\n", @sf.lines[0].joined_tokens
assert_equal " def function\n", @sf.lines[1].joined_tokens
assert_equal " rah = <<-HEREDOC\n", @sf.lines[2].joined_tokens
assert_equal "rah234\nHEREDOC\n", @sf.lines[3].joined_tokens
assert_equal " end\n", @sf.lines[4].joined_tokens
assert_equal "end\n", @sf.lines[5].joined_tokens
end

def test_should_indent_function_body
@sf.stubs(:source).returns("def function\nreturn nil\nend\n")
@sf.tokenize!
Expand Down

0 comments on commit 8deeaa8

Please sign in to comment.