Sha256: cd4c18d27cd99155673698a0a4dd70a2cae0a16ed355373553763dd82e4800c4

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

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

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

8 entries across 7 versions & 2 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/yard-0.9.2/spec/core_ext/string_spec.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.1/spec/core_ext/string_spec.rb
yard-0.9.5 spec/core_ext/string_spec.rb
yard-0.9.4 spec/core_ext/string_spec.rb
yard-0.9.3 spec/core_ext/string_spec.rb
yard-0.9.2 spec/core_ext/string_spec.rb
yard-0.9.1 spec/core_ext/string_spec.rb
yard-0.9.0 spec/core_ext/string_spec.rb