# Please keep in mind that any hash signs ("#") in the heredoc strings are # placed on purpose. Without these editors might remove the whitespace on empty # lines. describe Pry::Indent do before do @indent = Pry::Indent.new end it 'should indent an array' do input = "array = [\n10,\n15\n]" output = "array = [\n 10,\n 15\n]" expect(@indent.indent(input)).to eq output end it 'should indent a hash' do input = "hash = {\n:name => 'Ruby'\n}" output = "hash = {\n :name => 'Ruby'\n}" expect(@indent.indent(input)).to eq output end it 'should indent a function' do input = "def\nreturn 10\nend" output = "def\n return 10\nend" expect(@indent.indent(input)).to eq output end it 'should indent a module and class' do input = "module Foo\n# Hello world\nend" output = "module Foo\n # Hello world\nend" input_class = "class Foo\n# Hello world\nend" output_class = "class Foo\n # Hello world\nend" expect(@indent.indent(input)).to eq output expect(@indent.indent(input_class)).to eq output_class end it 'should indent separate lines' do expect(@indent.indent('def foo')).to eq 'def foo' expect(@indent.indent('return 10')).to eq ' return 10' expect(@indent.indent('end')).to eq 'end' end it 'should not indent single line statements' do input = < do" do input = "while 5 do\n5\nend" expect(@indent.indent(input)).to eq "while 5 do\n 5\nend" end it "should ident case statements" do input = <\n[]}]\n]")).to eq( "[[{\n [] =>\n []}]\n]" ) end it "should not indent single-line ifs" do expect(@indent.indent("foo if bar\n#")).to eq "foo if bar\n#" expect(@indent.reset.indent("foo() if bar\n#")).to eq "foo() if bar\n#" expect(@indent.reset.indent("foo 'hi' if bar\n#")).to eq "foo 'hi' if bar\n#" expect(@indent.reset.indent("foo 1 while bar\n#")).to eq "foo 1 while bar\n#" expect(@indent.reset.indent("$foo if false\n#")).to eq "$foo if false\n#" expect(@indent.reset.indent("@foo if false\n#")).to eq "@foo if false\n#" expect(@indent.reset.indent("@@foo if false\n#")).to eq "@@foo if false\n#" expect(@indent.reset.indent("super if true\n#")).to eq "super if true\n#" expect(@indent.reset.indent("true if false\n#")).to eq "true if false\n#" expect(@indent.reset.indent("String if false\n#")).to eq "String if false\n#" end it "should indent cunningly disguised ifs" do expect(@indent.indent("{1 => if bar\n#")).to eq "{1 => if bar\n #" expect(@indent.reset.indent("foo(if bar\n#")).to eq "foo(if bar\n #" expect(@indent.reset.indent("bar(baz, if bar\n#")).to eq "bar(baz, if bar\n #" expect(@indent.reset.indent("[if bar\n#")).to eq "[if bar\n #" expect(@indent.reset.indent("true; while bar\n#")).to eq "true; while bar\n #" end it "should differentiate single/multi-line unless" do expect(@indent.indent("foo unless bar\nunless foo\nbar\nend")).to eq( "foo unless bar\nunless foo\n bar\nend" ) end it "should not indent single/multi-line until" do expect(@indent.indent("%w{baz} until bar\nuntil foo\nbar\nend")).to eq( "%w{baz} until bar\nuntil foo\n bar\nend" ) end it "should indent begin rescue end" do input = < :wrong rescue => e doit :right end INPUT output = < :wrong rescue => e doit :right end OUTPUT expect(@indent.indent(input)).to eq output end it "should not indent single-line rescue" do input = <