spec/formatting/text/string_spec.rb in ronin-0.2.4 vs spec/formatting/text/string_spec.rb in ronin-0.3.0
- old
+ new
@@ -23,16 +23,112 @@
it "should format each character in the String" do
@string.format_chars { |c|
"_#{c}"
}.should == "_h_e_l_l_o"
end
+
+ it "should format specific bytes in a String" do
+ @string.format_chars(:included => [104, 108]) { |c|
+ c.upcase
+ }.should == 'HeLLo'
+ end
+
+ it "should not format specific bytes in a String" do
+ @string.format_chars(:excluded => [101, 111]) { |c|
+ c.upcase
+ }.should == 'HeLLo'
+ end
+
+ it "should format ranges of bytes in a String" do
+ @string.format_chars(:included => (104..108)) { |c|
+ c.upcase
+ }.should == 'HeLLo'
+ end
+
+ it "should not format ranges of bytes in a String" do
+ @string.format_chars(:excluded => (104..108)) { |c|
+ c.upcase
+ }.should == 'hEllO'
+ end
+
+ it "should format specific chars in a String" do
+ @string.format_chars(:included => ['h', 'l']) { |c|
+ c.upcase
+ }.should == 'HeLLo'
+ end
+
+ it "should not format specific bytes in a String" do
+ @string.format_chars(:excluded => ['e', 'o']) { |c|
+ c.upcase
+ }.should == 'HeLLo'
+ end
+
+ it "should format ranges of chars in a String" do
+ @string.format_chars(:included => ('h'..'l')) { |c|
+ c.upcase
+ }.should == 'HeLLo'
+ end
+
+ it "should not format ranges of chars in a String" do
+ @string.format_chars(:excluded => ('h'..'l')) { |c|
+ c.upcase
+ }.should == 'hEllO'
+ end
end
describe "format_bytes" do
it "should format each byte in the String" do
@string.format_bytes { |b|
sprintf("%%%x",b)
}.should == "%68%65%6c%6c%6f"
+ end
+
+ it "should format specific bytes in a String" do
+ @string.format_bytes(:included => [104, 108]) { |b|
+ b - 32
+ }.should == 'HeLLo'
+ end
+
+ it "should not format specific bytes in a String" do
+ @string.format_bytes(:excluded => [101, 111]) { |b|
+ b - 32
+ }.should == 'HeLLo'
+ end
+
+ it "should format ranges of bytes in a String" do
+ @string.format_bytes(:included => (104..108)) { |b|
+ b - 32
+ }.should == 'HeLLo'
+ end
+
+ it "should not format ranges of bytes in a String" do
+ @string.format_bytes(:excluded => (104..108)) { |b|
+ b - 32
+ }.should == 'hEllO'
+ end
+
+ it "should format specific chars in a String" do
+ @string.format_bytes(:included => ['h', 'l']) { |b|
+ b - 32
+ }.should == 'HeLLo'
+ end
+
+ it "should not format specific bytes in a String" do
+ @string.format_bytes(:excluded => ['e', 'o']) { |b|
+ b - 32
+ }.should == 'HeLLo'
+ end
+
+ it "should format ranges of chars in a String" do
+ @string.format_bytes(:included => ('h'..'l')) { |b|
+ b - 32
+ }.should == 'HeLLo'
+ end
+
+ it "should not format ranges of chars in a String" do
+ @string.format_bytes(:excluded => ('h'..'l')) { |b|
+ b - 32
+ }.should == 'hEllO'
end
end
describe "random_case" do
it "should capitalize each character when :probability is 1.0" do