add Recovery.Encoding module
This commit is contained in:
1 parent
6292f38993
commit
acc78f419a
2 files changed
+77
No files matched your search
@@ -0,0 +1,32 @@
|
||||
defmodule FeedReader.Recovery.EncodingTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias FeedReader.Recovery.Encoding
|
||||
|
||||
test "passes UTF-8 input through unchanged" do
|
||||
chunks = ["<title>", "café", "</title>"]
|
||||
|
||||
assert Encoding.transcode(chunks, :utf8) == chunks
|
||||
assert Encoding.normalize_declaration(chunks, :utf8) == chunks
|
||||
end
|
||||
|
||||
test "transcodes Latin-1 chunks to UTF-8" do
|
||||
chunks = ["<title>caf", <<0xE9>>, "</title>"]
|
||||
|
||||
assert chunks |> Encoding.transcode(:latin1) |> Enum.join() == "<title>café</title>"
|
||||
end
|
||||
|
||||
test "rewrites a Latin-1 declaration to UTF-8" do
|
||||
chunks = ["<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>", "<rss/>"]
|
||||
|
||||
assert chunks |> Encoding.normalize_declaration(:latin1) |> Enum.join() ==
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss/>"
|
||||
end
|
||||
|
||||
test "rewrites declarations split across chunks" do
|
||||
chunks = ["<?xml version=\"1.0\" enc", "oding=\"latin1\"?>", "<rss/>"]
|
||||
|
||||
assert chunks |> Encoding.normalize_declaration(:latin1) |> Enum.join() ==
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss/>"
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user