/
string_spec.rb
42 lines (33 loc) · 1.25 KB
/
string_spec.rb
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
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