Skip to content

Commit 66fecb2

Browse files
author
Tod Beardsley
committed
Add some specs around changed methods
See rapid7#4525
1 parent 01e3738 commit 66fecb2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

spec/lib/rex/text_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@
44
describe Rex::Text do
55
context "Class methods" do
66

7+
context ".to_ebcdic" do
8+
it "should convert ASCII to EBCDIC (both US standards)" do
9+
described_class.to_ebcdic("Hello, World!").should eq("\xc8\x85\x93\x93\x96\x6b\x40\xe6\x96\x99\x93\x84\x5a")
10+
end
11+
it "should raise on non-convertable characters" do
12+
lambda {described_class.to_ebcdic("\xff\xfe")}.should raise_exception(described_class::IllegalSequence)
13+
end
14+
end
15+
16+
context ".from_ebcdic" do
17+
it "should convert EBCDIC to ASCII (both US standards)" do
18+
described_class.from_ebcdic("\xc8\x85\x93\x93\x96\x6b\x40\xe6\x96\x99\x93\x84\x5a").should eq("Hello, World!")
19+
end
20+
it "should raise on non-convertable characters" do
21+
lambda {described_class.from_ebcdic("\xff\xfe")}.should raise_exception(described_class::IllegalSequence)
22+
end
23+
end
24+
25+
context ".to_utf8" do
26+
it "should convert a string to UTF-8, skipping badchars" do
27+
described_class.to_utf8("Hello, world!").should eq("Hello, world!")
28+
described_class.to_utf8("Oh no, \xff\xfe can't convert!").should eq("Oh no, can't convert!")
29+
end
30+
end
31+
732
context ".to_octal" do
833
it "should convert all chars 00 through ff" do
934
described_class.to_octal("\x7f"*100).should eq("\\177"*100)

0 commit comments

Comments
 (0)