spec/unibits_spec.rb in unibits-2.0.0 vs spec/unibits_spec.rb in unibits-2.1.0
- old
+ new
@@ -65,28 +65,68 @@
result.must_match "C"
result.must_match "43"
result.must_match "01000011"
end
- it "works with 'ISO-8859-' encodings" do
+ it "works with 'ISO-8859-X' encodings" do
string = "\xBC Idiosyncr\xE4tic\n\x91".force_encoding("ISO-8859-1")
result = Paint.unpaint(Unibits.visualize(string))
result.must_match "BC" # ¼
result.must_match "E4" # ä
result.must_match "␊" # \n
result.must_match "PU1" # C1 name for \x91
end
- it "works with 'Windows-125' encodings" do
+ it "works with 'Windows-125X' encodings" do
string = "\xBC Idiosyncr\xE4tic\n\x81".force_encoding("Windows-1252")
result = Paint.unpaint(Unibits.visualize(string))
result.must_match "BC" # ¼
result.must_match "E4" # ä
result.must_match "␊" # \n
result.must_match "n/a" # \x81 is not assigned
end
+ it "works with 'IBMX' encodings" do
+ string = "\xFE Idiosyncr\x84tic\n".force_encoding("IBM437")
+ result = Paint.unpaint(Unibits.visualize(string))
+ result.must_match "FE" # ■
+ result.must_match "84" # ä
+ result.must_match "␊" # \n
+ end
+
+ it "works with 'CP85X' encodings" do
+ string = "\xFE Idiosyncr\x84tic\n".force_encoding("CP850")
+ result = Paint.unpaint(Unibits.visualize(string))
+ result.must_match "FE" # ■
+ result.must_match "84" # ä
+ result.must_match "␊" # \n
+ end
+
+ it "works with 'macX' encodings" do
+ string = "\xBD Idiosyncr\x8Atic \x11 \xF0\n".force_encoding("macRoman")
+ result = Paint.unpaint(Unibits.visualize(string))
+ result.must_match "BD" # Ω
+ result.must_match "8A" # ä
+ result.must_match "Logo" # \xF0
+ result.must_match "⌘" # \x11
+ result.must_match "␊" # \n
+ end
+
+ it "works with 'TIS-620/Windows-874' encodings" do
+ string = "\xA4 Idiosyncratic\n".force_encoding("TIS-620")
+ result = Paint.unpaint(Unibits.visualize(string))
+ result.must_match "A4" # ค
+ result.must_match "␊" # \n
+ end
+
+ it "works with 'KOI8-X' encodings" do
+ string = "\xE9\xE4\xE9\xEF\xF3\xF9\xEE\xE3\xF2\xE1\xF4\xE9\xE3\n".force_encoding("KOI8-R")
+ result = Paint.unpaint(Unibits.visualize(string))
+ result.must_match "F9" # Ы
+ result.must_match "␊" # \n
+ end
+
describe "invalid UTF-8 encodings" do
it "- unexpected continuation byte (1/2)" do
string = "abc\x80efg"
result = Paint.unpaint(Unibits.visualize(string))
result.must_match "�"
@@ -216,9 +256,25 @@
string = "🌫".b[0..-2].force_encoding("UTF-32LE")
result = Paint.unpaint(Unibits.visualize(string))
result.must_match "incompl."
result.must_match "�"
end
+
+ # TODO implement when https://bugs.ruby-lang.org/issues/13292 is released
+
+ # it "- too large codepoint" do
+ # string = "\x00\x00\x11\x00".force_encoding("UTF-32LE")
+ # result = Paint.unpaint(Unibits.visualize(string))
+ # result.must_match "�"
+ # result.must_match /toolarge.*toolarge.*toolarge.*toolarge/m
+ # end
+
+ # it "- has surrogate" do
+ # string = "\x00\xD8\x00\x00".force_encoding("UTF-32LE")
+ # result = Paint.unpaint(Unibits.visualize(string))
+ # result.must_match "�"
+ # result.must_match "sur.gate"
+ # end
end
describe "invalid ASCII encodings" do
it "- contains bytes with 8th bit set" do
string = "abc\x80efg".force_encoding("ASCII")