diff options
Diffstat (limited to 'spec/ruby/language/heredoc_spec.rb')
| -rw-r--r-- | spec/ruby/language/heredoc_spec.rb | 94 |
1 files changed, 63 insertions, 31 deletions
diff --git a/spec/ruby/language/heredoc_spec.rb b/spec/ruby/language/heredoc_spec.rb index a57a7b0bb9..535f18cba8 100644 --- a/spec/ruby/language/heredoc_spec.rb +++ b/spec/ruby/language/heredoc_spec.rb @@ -1,6 +1,6 @@ # -*- encoding: us-ascii -*- -require File.expand_path('../../spec_helper', __FILE__) +require_relative '../spec_helper' describe "Heredoc string" do @@ -13,6 +13,7 @@ describe "Heredoc string" do foo bar#{@ip} HERE s.should == "foo barxxx\n" + s.encoding.should == Encoding::US_ASCII end it 'allow HEREDOC with <<"identifier", interpolated' do @@ -20,6 +21,7 @@ HERE foo bar#{@ip} HERE s.should == "foo barxxx\n" + s.encoding.should == Encoding::US_ASCII end it "allows HEREDOC with <<'identifier', no interpolation" do @@ -27,6 +29,7 @@ HERE foo bar#{@ip} HERE s.should == 'foo bar#{@ip}' + "\n" + s.encoding.should == Encoding::US_ASCII end it "allows HEREDOC with <<-identifier, allowing to indent identifier, interpolated" do @@ -35,6 +38,7 @@ HERE HERE s.should == " foo barxxx\n" + s.encoding.should == Encoding::US_ASCII end it 'allows HEREDOC with <<-"identifier", allowing to indent identifier, interpolated' do @@ -43,6 +47,7 @@ HERE HERE s.should == " foo barxxx\n" + s.encoding.should == Encoding::US_ASCII end it "allows HEREDOC with <<-'identifier', allowing to indent identifier, no interpolation" do @@ -51,37 +56,64 @@ HERE HERE s.should == ' foo bar#{@ip}' + "\n" + s.encoding.should == Encoding::US_ASCII end - ruby_version_is "2.3" do - it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do - require File.expand_path('../fixtures/squiggly_heredoc', __FILE__) - SquigglyHeredocSpecs.message.should == "character density, n.:\n The number of very weird people in the office.\n" - end - - it "trims trailing newline character for blank HEREDOC with <<~'identifier'" do - require File.expand_path('../fixtures/squiggly_heredoc', __FILE__) - SquigglyHeredocSpecs.blank.should == "" - end - - it 'allows HEREDOC with <<~identifier, interpolated' do - require File.expand_path('../fixtures/squiggly_heredoc', __FILE__) - SquigglyHeredocSpecs.unquoted.should == "unquoted interpolated\n" - end - - it 'allows HEREDOC with <<~"identifier", interpolated' do - require File.expand_path('../fixtures/squiggly_heredoc', __FILE__) - SquigglyHeredocSpecs.doublequoted.should == "doublequoted interpolated\n" - end - - it "allows HEREDOC with <<~'identifier', no interpolation" do - require File.expand_path('../fixtures/squiggly_heredoc', __FILE__) - SquigglyHeredocSpecs.singlequoted.should == "singlequoted \#{\"interpolated\"}\n" - end - - it "selects the least-indented line and removes its indentation from all the lines" do - require File.expand_path('../fixtures/squiggly_heredoc', __FILE__) - SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n" - end + it 'raises SyntaxError if quoted HEREDOC identifier is ending not on same line' do + -> { + eval %{<<"HERE\n"\nraises syntax error\nHERE} + }.should.raise(SyntaxError) + end + + it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.message.should == "character density, n.:\n The number of very weird people in the office.\n" + end + + it "trims trailing newline character for blank HEREDOC with <<~'identifier'" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.blank.should == "" + end + + it 'allows HEREDOC with <<~identifier, interpolated' do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.unquoted.should == "unquoted interpolated\n" + end + + it 'allows HEREDOC with <<~"identifier", interpolated' do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.doublequoted.should == "doublequoted interpolated\n" + end + + it "allows HEREDOC with <<~'identifier', no interpolation" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.singlequoted.should == "singlequoted \#{\"interpolated\"}\n" + end + + it "allows HEREDOC with <<~'identifier', no interpolation, with backslash" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.backslash.should == "a\nbc\n" + end + + it "selects the least-indented line and removes its indentation from all the lines" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.least_indented_on_the_first_line.should == "a\n b\n c\n" + SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n" + end + + it "selects the least-indented line and removes its indentation from all the lines for <<~'identifier'" do + require_relative 'fixtures/squiggly_heredoc' + SquigglyHeredocSpecs.least_indented_on_the_first_line_single.should == "a\n b\n c\n" + SquigglyHeredocSpecs.least_indented_on_the_last_line_single.should == " a\n b\nc\n" + end + + it "reports line numbers inside HEREDOC with method call" do + -> { + <<-HERE.chomp + a + b + #{c} + HERE + }.should.raise(NameError) { |e| e.backtrace[0].should.start_with?("#{__FILE__}:#{__LINE__ - 2}") } end end |
