Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

42 lines (33 sloc) 1.254 kb
require File.dirname(__FILE__) + '/../spec_helper'
#described_in_docs String, '#camelcase'
#described_in_docs String, '#underscore'
describe String do
describe '#shell_split' do
it "should split simple non-quoted text" do
"a b c".shell_split.should == %w(a b c)
end
it "should split double quoted text into single token" do
'a "b c d" e'.shell_split.should == ["a", "b c d", "e"]
end
it "should split single quoted text into single token" do
"a 'b c d' e".shell_split.should == ["a", "b c d", "e"]
end
it "should handle escaped quotations in quotes" do
"'a \\' b'".shell_split.should == ["a ' b"]
end
it "should handle escaped quotations outside quotes" do
"\\'a 'b'".shell_split.should == %w('a b)
end
it "should handle escaped backslash" do
"\\\\'a b c'".shell_split.should == ['\a b c']
end
it "should handle any whitespace as space" do
text = "foo\tbar\nbaz\r\nfoo2 bar2"
text.shell_split.should == %w(foo bar baz foo2 bar2)
end
it "should handle complex input" do
text = "hello \\\"world \"1 2\\\" 3\" a 'b \"\\\\\\'' c"
text.shell_split.should == ["hello", "\"world", "1 2\" 3", "a", "b \"\\'", "c"]
end
end
end
Jump to Line
Something went wrong with that request. Please try again.