File: truncator_spec.rb

package info (click to toggle)
ruby-tty-command 0.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 452 kB
  • sloc: ruby: 1,990; makefile: 4; sh: 4
file content (73 lines) | stat: -rw-r--r-- 1,738 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# frozen_string_literal: true

RSpec.describe TTY::Command::Truncator do
  it "writes nil content" do
    truncator = described_class.new(max_size: 2)

    truncator.write(nil)

    expect(truncator.read).to eq("")
  end

  it "writes content within maximum size" do
    truncator = described_class.new(max_size: 2)

    truncator.write("a")

    expect(truncator.read).to eq("a")
  end

  it "writes both prefix and suffix" do
    truncator = described_class.new(max_size: 2)

    truncator.write("abc")
    truncator.write("d")

    expect(truncator.read).to eq("abcd")
  end

  it "writes more bytes letter" do
    truncator = described_class.new(max_size: 1000)
    multibytes_string = "’test’"

    truncator.write(multibytes_string)

    expect(truncator.read).to eq(multibytes_string)
  end

  it "overflows prefix and suffix " do
    truncator = described_class.new(max_size: 2)

    truncator.write("abc")
    truncator.write("d")
    truncator.write("e")

    expect(truncator.read).to eq("ab\n... omitting 1 bytes ...\nde")
  end

  it "omits bytes " do
    truncator = described_class.new(max_size: 2)

    truncator.write("abc___________________yz")

    expect(truncator.read).to eq("ab\n... omitting 20 bytes ...\nyz")
  end

  it "reflows suffix with less content" do
    truncator = described_class.new(max_size: 2)

    truncator.write("abc____________________y")
    truncator.write("z")

    expect(truncator.read).to eq("ab\n... omitting 21 bytes ...\nyz")
  end

  it "reflows suffix with more content" do
    truncator = described_class.new(max_size: 2)

    truncator.write("abc____________________y")
    truncator.write("zwx")

    expect(truncator.read).to eq("ab\n... omitting 23 bytes ...\nwx")
  end
end