File: string_spec.rb

package info (click to toggle)
yard 0.9.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,720 kB
  • sloc: ruby: 31,354; javascript: 7,608; makefile: 21
file content (42 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download | duplicates (5)
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
# frozen_string_literal: true

# described_in_docs String, '#camelcase'
# described_in_docs String, '#underscore'

RSpec.describe String do
  describe "#shell_split" do
    it "splits simple non-quoted text" do
      expect("a b c".shell_split).to eq %w(a b c)
    end

    it "splits double quoted text into single token" do
      expect('a "b c d" e'.shell_split).to eq ["a", "b c d", "e"]
    end

    it "splits single quoted text into single token" do
      expect("a 'b c d' e".shell_split).to eq ["a", "b c d", "e"]
    end

    it "handles escaped quotations in quotes" do
      expect("'a \\' b'".shell_split).to eq ["a ' b"]
    end

    it "handles escaped quotations outside quotes" do
      expect("\\'a 'b'".shell_split).to eq %w('a b)
    end

    it "handles escaped backslash" do
      expect("\\\\'a b c'".shell_split).to eq ['\a b c']
    end

    it "handles any whitespace as space" do
      text = "foo\tbar\nbaz\r\nfoo2 bar2"
      expect(text.shell_split).to eq %w(foo bar baz foo2 bar2)
    end

    it "handles complex input" do
      text = "hello \\\"world \"1 2\\\" 3\" a 'b \"\\\\\\'' c"
      expect(text.shell_split).to eq ["hello", "\"world", "1 2\" 3", "a", "b \"\\'", "c"]
    end
  end
end