2017-05-07 08:04:49 -04:00
|
|
|
# -*- encoding: us-ascii -*-
|
|
|
|
|
2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../spec_helper'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "Heredoc string" do
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
@ip = 'xxx' # used for interpolation
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows HEREDOC with <<identifier, interpolated" do
|
|
|
|
s = <<HERE
|
|
|
|
foo bar#{@ip}
|
|
|
|
HERE
|
|
|
|
s.should == "foo barxxx\n"
|
2019-02-21 10:38:59 -05:00
|
|
|
s.encoding.should == Encoding::US_ASCII
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allow HEREDOC with <<"identifier", interpolated' do
|
|
|
|
s = <<"HERE"
|
|
|
|
foo bar#{@ip}
|
|
|
|
HERE
|
|
|
|
s.should == "foo barxxx\n"
|
2019-02-21 10:38:59 -05:00
|
|
|
s.encoding.should == Encoding::US_ASCII
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows HEREDOC with <<'identifier', no interpolation" do
|
|
|
|
s = <<'HERE'
|
|
|
|
foo bar#{@ip}
|
|
|
|
HERE
|
|
|
|
s.should == 'foo bar#{@ip}' + "\n"
|
2019-02-21 10:38:59 -05:00
|
|
|
s.encoding.should == Encoding::US_ASCII
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows HEREDOC with <<-identifier, allowing to indent identifier, interpolated" do
|
|
|
|
s = <<-HERE
|
|
|
|
foo bar#{@ip}
|
|
|
|
HERE
|
|
|
|
|
|
|
|
s.should == " foo barxxx\n"
|
2019-02-21 10:38:59 -05:00
|
|
|
s.encoding.should == Encoding::US_ASCII
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows HEREDOC with <<-"identifier", allowing to indent identifier, interpolated' do
|
|
|
|
s = <<-"HERE"
|
|
|
|
foo bar#{@ip}
|
|
|
|
HERE
|
|
|
|
|
|
|
|
s.should == " foo barxxx\n"
|
2019-02-21 10:38:59 -05:00
|
|
|
s.encoding.should == Encoding::US_ASCII
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows HEREDOC with <<-'identifier', allowing to indent identifier, no interpolation" do
|
|
|
|
s = <<-'HERE'
|
|
|
|
foo bar#{@ip}
|
|
|
|
HERE
|
|
|
|
|
|
|
|
s.should == ' foo bar#{@ip}' + "\n"
|
2019-02-21 10:38:59 -05:00
|
|
|
s.encoding.should == Encoding::US_ASCII
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2020-10-24 09:52:37 -04:00
|
|
|
ruby_version_is "2.7" do
|
|
|
|
it 'raises SyntaxError if quoted HEREDOC identifier is ending not on same line' do
|
|
|
|
-> {
|
|
|
|
eval %{<<"HERE\n"\nraises syntax error\nHERE}
|
|
|
|
}.should raise_error(SyntaxError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ruby_version_is ""..."2.7" do
|
|
|
|
it 'prints a warning if quoted HEREDOC identifier is ending not on same line' do
|
|
|
|
-> {
|
|
|
|
eval %{<<"HERE\n"\nit warns\nHERE}
|
|
|
|
}.should complain(/here document identifier ends with a newline/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
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
|
|
|
|
|
2021-01-28 11:08:57 -05:00
|
|
|
it "allows HEREDOC with <<~'identifier', no interpolation, with backslash" do
|
|
|
|
require_relative 'fixtures/squiggly_heredoc'
|
|
|
|
SquigglyHeredocSpecs.backslash.should == "a\nbc\n"
|
|
|
|
end
|
|
|
|
|
2018-04-28 15:50:06 -04:00
|
|
|
it "selects the least-indented line and removes its indentation from all the lines" do
|
|
|
|
require_relative 'fixtures/squiggly_heredoc'
|
2020-05-31 12:22:49 -04:00
|
|
|
SquigglyHeredocSpecs.least_indented_on_the_first_line.should == "a\n b\n c\n"
|
2018-04-28 15:50:06 -04:00
|
|
|
SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n"
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
2020-05-31 12:22:49 -04:00
|
|
|
|
|
|
|
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
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|