spec/line_wrap_spec.rb in prawn-1.0.0.rc2 vs spec/line_wrap_spec.rb in prawn-1.0.0
- old
+ new
@@ -3,12 +3,12 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
describe "Core::Text::Formatted::LineWrap#wrap_line" do
before(:each) do
create_pdf
- @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
+ @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
@one_word_width = 50
end
it "should strip leading and trailing spaces" do
array = [{ :text => " hello world, " },
{ :text => "goodbye ", :style => [:bold] }]
@@ -111,15 +111,15 @@
@arranger.format_array = array
string = @line_wrap.wrap_line(:arranger => @arranger,
:width => @one_word_width,
:document => @pdf)
expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
- expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
+ expected.force_encoding(Encoding::UTF_8)
string.should == expected
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
string = "hello#{Prawn::Text::SHY}world"
array = [{ :text => string }]
@arranger.format_array = array
string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -136,11 +136,11 @@
:width => 300,
:document => @pdf)
string.should == "helloworld"
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
string = "hello#{Prawn::Text::SHY}world"
array = [{ :text => string }]
@arranger.format_array = array
string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -165,11 +165,11 @@
:width => enough_width_for_hello_world,
:document => @pdf)
string.should == "hello"
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
enough_width_for_hello_world = 68
array = [{ :text => "hello world" }]
@arranger.format_array = array
string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -200,15 +200,15 @@
@arranger.format_array = array
string = @line_wrap.wrap_line(:arranger => @arranger,
:width => @one_word_width,
:document => @pdf)
expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
- expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
+ expected.force_encoding(Encoding::UTF_8)
string.should == expected
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
string = "hello#{Prawn::Text::SHY}-"
array = [{ :text => string }]
@arranger.format_array = array
string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -222,17 +222,28 @@
string = @line_wrap.wrap_line(:arranger => @arranger,
:width => @one_word_width,
:document => @pdf)
string.should == "hello#{Prawn::Text::SHY}"
end
+
+ it "should process UTF-8 chars", :unresolved, :issue => 693 do
+ array = [{ :text => "Test" }]
+ @arranger.format_array = array
+
+ # Should not raise an encoding error
+ string = @line_wrap.wrap_line(:arranger => @arranger,
+ :width => 300,
+ :document => @pdf)
+ string.should == "Test"
+ end
end
describe "Core::Text::Formatted::LineWrap#space_count" do
before(:each) do
create_pdf
- @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
+ @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
end
it "should return the number of spaces in the last wrapped line" do
array = [{ :text => "hello world, " },
{ :text => "goodbye", :style => [:bold] }]
@arranger.format_array = array
@@ -253,21 +264,21 @@
end
describe "Core::Text::Formatted::LineWrap" do
before(:each) do
create_pdf
- @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
+ @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
array = [{ :text => "hello\nworld\n\n\nhow are you?" },
{ :text => "\n" },
{ :text => "\n" },
{ :text => "" },
{ :text => "fine, thanks. " * 4 },
{ :text => "" },
{ :text => "\n" },
{ :text => "" }]
@arranger.format_array = array
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
end
it "should only return an empty string if nothing fit or there" +
"was nothing to wrap" do
8.times do
line = @line_wrap.wrap_line(:arranger => @arranger,
@@ -283,11 +294,11 @@
end
describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
before(:each) do
create_pdf
- @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
+ @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
@one_word_width = 50
end
it "should be_false when the last printed line is not the end of the paragraph" do
array = [{ :text => "hello world" }]
@arranger.format_array = array