Sha256: c650b3d339ab4d22e8b21ceef8057eec5673120eb458984db74ea5c58abddfbf

Contents?: true

Size: 1.2 KB

Versions: 21

Compression:

Stored size: 1.2 KB

Contents

# 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

Version data entries

21 entries across 20 versions & 4 rubygems

Version Path
yard-0.9.24 spec/core_ext/string_spec.rb
yard-0.9.23 spec/core_ext/string_spec.rb
yard-0.9.22 spec/core_ext/string_spec.rb
yard-0.9.21 spec/core_ext/string_spec.rb
yard-0.9.20 spec/core_ext/string_spec.rb
yard-0.9.19 spec/core_ext/string_spec.rb
yard-0.9.16 spec/core_ext/string_spec.rb
yard-0.9.15 spec/core_ext/string_spec.rb
yard-0.9.14 spec/core_ext/string_spec.rb
yard-0.9.13 spec/core_ext/string_spec.rb
yard-0.9.12 spec/core_ext/string_spec.rb
yard-0.9.11 spec/core_ext/string_spec.rb
yard-0.9.10 spec/core_ext/string_spec.rb
yard-0.9.9 spec/core_ext/string_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/spec/core_ext/string_spec.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/spec/core_ext/string_spec.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/spec/core_ext/string_spec.rb
yard-0.9.8 spec/core_ext/string_spec.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.7/spec/core_ext/string_spec.rb
yard-0.9.7 spec/core_ext/string_spec.rb