Skip to content

Commit

Permalink
Improve NATFIXME markers in failing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m committed Jun 22, 2024
1 parent 1839164 commit ee99369
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions spec/core/string/encode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
end

it "replace multiple invalid bytes at the end with a single replacement character" do
NATFIXME 'encoding from utf-8 to utf-8 with invalid chars' do
NATFIXME 'same encoding with invalid chars', exception: SpecFailedException, message: /should be ==/ do
"\xE3\x81\x93\xE3\x81".encode("UTF-8", invalid: :replace).should == "\u3053\ufffd"
end
end
Expand Down Expand Up @@ -136,7 +136,7 @@

describe "when passed to, from" do
it "returns a copy in the destination encoding when both encodings are the same" do
NATFIXME 'src encoding' do
NATFIXME 'honor source encoding', exception: Encoding::UndefinedConversionError, message: /from ASCII-8BIT to UTF-8/ do
str = "あ".dup.force_encoding("binary")
encoded = str.encode("utf-8", "utf-8")

Expand All @@ -147,7 +147,7 @@
end

it "returns the transcoded string" do
NATFIXME 'not sure' do
NATFIXME 'honor source encoding', exception: SpecFailedException, message: /should be ==/ do
str = "\x00\x00\x00\x1F"
str.encode(Encoding::UTF_8, Encoding::UTF_16BE).should == "\u0000\u001f"
end
Expand All @@ -172,7 +172,7 @@
end

it "returns a copy in the destination encoding when both encodings are the same" do
NATFIXME 'encode options' do
NATFIXME 'honor source encoding', exception: Encoding::UndefinedConversionError, message: /from ASCII-8BIT to UTF-8/ do
str = "あ".dup.force_encoding("binary")
encoded = str.encode("utf-8", "utf-8", invalid: :replace)

Expand Down
50 changes: 25 additions & 25 deletions spec/core/string/shared/encode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

it "transcodes a 7-bit String despite no generic converting being available" do
NATFIXME 'converter not found' do
NATFIXME 'need Emacs_Mule encoding', exception: SpecFailedException, message: /uninitialized constant Encoding::Emacs_Mule/ do
-> do
Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY
end.should raise_error(Encoding::ConverterNotFoundError)
Expand All @@ -22,7 +22,7 @@
end

it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do
NATFIXME 'no conversion' do
NATFIXME 'need Emacs_Mule encoding', exception: NameError, message: /uninitialized constant Encoding::Emacs_Mule/ do
Encoding.default_internal = Encoding::Emacs_Mule
str = [0x80].pack('C').force_encoding Encoding::BINARY
-> { str.send(@method) }.should raise_error(Encoding::ConverterNotFoundError)
Expand Down Expand Up @@ -50,15 +50,15 @@
end

it "transcodes Japanese multibyte characters" do
NATFIXME 'not sure' do
NATFIXME 'need ISO_2022_JP encoding', exception: NameError, message: /uninitialized constant Encoding::ISO_2022_JP/ do
str = "あいうえお"
str.send(@method, Encoding::ISO_2022_JP).should ==
"\e\x24\x42\x24\x22\x24\x24\x24\x26\x24\x28\x24\x2A\e\x28\x42".force_encoding(Encoding::ISO_2022_JP)
end
end

it "transcodes a 7-bit String despite no generic converting being available" do
NATFIXME 'converter not found' do
NATFIXME 'need Emacs_Mule encoding', exception: SpecFailedException, message: /uninitialized constant Encoding::Emacs_Mule/ do
-> do
Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY
end.should raise_error(Encoding::ConverterNotFoundError)
Expand All @@ -69,7 +69,7 @@
end

it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do
NATFIXME 'converter not found' do
NATFIXME 'need Emacs_Mule encoding', exception: SpecFailedException, message: /uninitialized constant Encoding::Emacs_Mule/ do
str = [0x80].pack('C').force_encoding Encoding::BINARY
-> do
str.send(@method, Encoding::Emacs_Mule)
Expand All @@ -78,7 +78,7 @@
end

it "raises an Encoding::ConverterNotFoundError for an invalid encoding" do
NATFIXME 'converter not found' do
NATFIXME 'wrong error', exception: SpecFailedException, message: /ConverterNotFoundError.*but instead.*ArgumentError/ do
-> do
"abc".send(@method, "xyz")
end.should raise_error(Encoding::ConverterNotFoundError)
Expand Down Expand Up @@ -107,7 +107,7 @@
end

it "raises an Encoding::ConverterNotFoundError when no conversion is possible despite 'invalid: :replace, undef: :replace'" do
NATFIXME 'undef option' do
NATFIXME 'need Emacs_Mule encoding', exception: NameError, message: /uninitialized constant Encoding::Emacs_Mule/ do
Encoding.default_internal = Encoding::Emacs_Mule
str = [0x80].pack('C').force_encoding Encoding::BINARY
-> do
Expand All @@ -117,7 +117,7 @@
end

it "replaces invalid characters when replacing Emacs-Mule encoded strings" do
NATFIXME 'Emacs-Mule' do
NATFIXME 'need Emacs_Mule encoding', exception: ArgumentError, message: 'unknown encoding name - "Emacs-Mule"' do
got = [0x80].pack('C').force_encoding('Emacs-Mule').send(@method, invalid: :replace)

got.should == "?".encode('Emacs-Mule')
Expand All @@ -127,7 +127,7 @@

describe "when passed to, from" do
it "transcodes between the encodings ignoring the String encoding" do
NATFIXME 'src encoding' do
NATFIXME 'honor source encoding', exception: SpecFailedException, message: /should be ==/ do
str = "あ"
result = [0xA6, 0xD0, 0x8F, 0xAB, 0xE4, 0x8F, 0xAB, 0xB1].pack('C8')
result.force_encoding Encoding::EUC_JP
Expand All @@ -136,7 +136,7 @@
end

it "calls #to_str to convert the from object to an Encoding" do
NATFIXME 'src encoding' do
NATFIXME 'honor source encoding', exception: SpecFailedException, message: /should be ==/ do
enc = mock("string encode encoding")
enc.should_receive(:to_str).and_return("ibm437")

Expand Down Expand Up @@ -174,7 +174,7 @@

describe "when passed to, from, options" do
it "replaces undefined characters in the destination encoding" do
NATFIXME 'undef option and src encoding' do
NATFIXME 'honor source encoding', exception: Encoding::UndefinedConversionError, message: /to UTF-8 in conversion from ASCII-8BIT to UTF-8 to EUC-JP/ do
str = "あ?あ".force_encoding Encoding::BINARY
result = str.send(@method, "euc-jp", "utf-8", undef: :replace)
xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding('utf-8')
Expand All @@ -183,15 +183,15 @@
end

it "replaces invalid characters in the destination encoding" do
NATFIXME 'src encoding' do
NATFIXME 'honor source encoding', exception: Encoding::UndefinedConversionError, message: /to UTF-8 in conversion from ASCII-8BIT to UTF-8 to ISO-8859-1/ do
xFF = [0xFF].pack('C').force_encoding('utf-8')
str = "ab#{xFF}c".force_encoding Encoding::BINARY
str.send(@method, "iso-8859-1", "utf-8", invalid: :replace).should == "ab?c"
end
end

it "calls #to_str to convert the to object to an encoding" do
NATFIXME 'src encoding' do
NATFIXME 'honor source encoding', exception: Encoding::UndefinedConversionError, message: /to UTF-8 in conversion from ASCII-8BIT to UTF-8 to ISO-8859-1/ do
to = mock("string encode to encoding")
to.should_receive(:to_str).and_return("iso-8859-1")

Expand All @@ -202,7 +202,7 @@
end

it "calls #to_str to convert the from object to an encoding" do
NATFIXME 'src encoding' do
NATFIXME 'honor source encoding', exception: Encoding::UndefinedConversionError, message: /to UTF-8 in conversion from ASCII-8BIT to UTF-8 to ISO-8859-1/ do
from = mock("string encode to encoding")
from.should_receive(:to_str).and_return("utf-8")

Expand All @@ -226,69 +226,69 @@

describe "given the xml: :text option" do
it "replaces all instances of '&' with '&'" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'& and &'.send(@method, "UTF-8", xml: :text).should == '& and &'
end
end

it "replaces all instances of '<' with '&lt;'" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'< and <'.send(@method, "UTF-8", xml: :text).should == '&lt; and &lt;'
end
end

it "replaces all instances of '>' with '&gt;'" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'> and >'.send(@method, "UTF-8", xml: :text).should == '&gt; and &gt;'
end
end

it "does not replace '\"'" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'" and "'.send(@method, "UTF-8", xml: :text).should == '" and "'
end
end

it "replaces undefined characters with their upper-case hexadecimal numeric character references" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'ürst'.send(@method, Encoding::US_ASCII, xml: :text).should == '&#xFC;rst'
end
end
end

describe "given the xml: :attr option" do
it "surrounds the encoded text with double-quotes" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'abc'.send(@method, "UTF-8", xml: :attr).should == '"abc"'
end
end

it "replaces all instances of '&' with '&amp;'" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'& and &'.send(@method, "UTF-8", xml: :attr).should == '"&amp; and &amp;"'
end
end

it "replaces all instances of '<' with '&lt;'" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'< and <'.send(@method, "UTF-8", xml: :attr).should == '"&lt; and &lt;"'
end
end

it "replaces all instances of '>' with '&gt;'" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'> and >'.send(@method, "UTF-8", xml: :attr).should == '"&gt; and &gt;"'
end
end

it "replaces all instances of '\"' with '&quot;'" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'" and "'.send(@method, "UTF-8", xml: :attr).should == '"&quot; and &quot;"'
end
end

it "replaces undefined characters with their upper-case hexadecimal numeric character references" do
NATFIXME 'xml option' do
NATFIXME 'xml option', exception: ArgumentError, message: 'unknown keyword: :xml' do
'ürst'.send(@method, Encoding::US_ASCII, xml: :attr).should == '"&#xFC;rst"'
end
end
Expand Down

0 comments on commit ee99369

Please sign in to comment.