File: string_builder_spec.cr

package info (click to toggle)
crystal 1.6.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,956 kB
  • sloc: javascript: 1,712; sh: 592; cpp: 541; makefile: 243; ansic: 119; python: 105; xml: 32
file content (43 lines) | stat: -rw-r--r-- 848 bytes parent folder | download
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