File: whitespace_spec.rb

package info (click to toggle)
ruby-tty-prompt 0.23.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,452 kB
  • sloc: ruby: 8,847; makefile: 4
file content (51 lines) | stat: -rw-r--r-- 1,429 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
# frozen_string_literal: true

RSpec.describe TTY::Prompt::Question::Modifier, "#whitespace" do
  context "string with whitespaces" do
    let(:string) { "  text\t \n  to\t   modify\r\n" }

    it "trims whitespace" do
      modified = described_class.whitespace(:trim, string)
      expect(modified).to eq("text\t \n  to\t   modify")
    end

    it "chomps whitespace" do
      modified = described_class.whitespace(:chomp, string)
      expect(modified).to eq("  text\t \n  to\t   modify")
    end

    it "collapses text" do
      modified = described_class.whitespace(:collapse, string)
      expect(modified).to eq(" text to modify ")
    end

    it "removes whitespace" do
      modified = described_class.whitespace(:remove, string)
      expect(modified).to eq("texttomodify")
    end
  end

  context "nil (empty user input)" do
    let(:string) { nil }

    example "trim returns nil" do
      modified = described_class.whitespace(:trim, string)
      expect(modified).to be_nil
    end

    example "chomp returns nil" do
      modified = described_class.whitespace(:chomp, string)
      expect(modified).to be_nil
    end

    example "collapse returns nil" do
      modified = described_class.whitespace(:collapse, string)
      expect(modified).to be_nil
    end

    example "remove returns nil" do
      modified = described_class.whitespace(:remove, string)
      expect(modified).to be_nil
    end
  end
end