1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
require "spec"
describe String::Builder do
it "builds" do
str = String::Builder.build do |builder|
builder << 123
builder << 456
end
str.should eq("123456")
end
it "raises if invokes to_s twice" do
builder = String::Builder.new
builder << 123
builder.to_s.should eq("123")
expect_raises(Exception, "Can only invoke 'to_s' once on String::Builder") { builder.to_s }
end
it "goes back" do
s = String::Builder.build do |str|
str << 12
str.back(1)
end
s.should eq("1")
end
it "goes back all" do
s = String::Builder.build do |str|
str << 12
str.back(2)
end
s.should eq("")
end
describe "#chomp!" do
it "returns self" do
str = String::Builder.new
str << "a,b,c,"
str.chomp!(44).to_s.should eq("a,b,c")
end
end
end
|