-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
html_entities
dependency and use built-in entities module (#434
) * WIP: using built in code for decode * Fix encoding/decoding * Remove html_entities as dependency Also remove old unused deps. * Change "generate_entities" mix task to use another file This is because we now have some rules in the main file. * Add tests to Entities module * Better organize
- Loading branch information
Showing
9 changed files
with
2,375 additions
and
2,248 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
defmodule Floki.EntitiesTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Floki.Entities | ||
|
||
describe "encode/1" do | ||
test "encode single-quote" do | ||
assert Entities.encode("'") == "'" | ||
end | ||
|
||
test "encode double-quote" do | ||
assert Entities.encode("\"") == """ | ||
end | ||
|
||
test "ampersand" do | ||
assert Entities.encode("&") == "&" | ||
end | ||
|
||
test "encode less-than sign" do | ||
assert Entities.encode("<") == "<" | ||
end | ||
|
||
test "encode greater-than sign" do | ||
assert Entities.encode(">") == ">" | ||
end | ||
|
||
test "does not encode others" do | ||
assert Entities.encode("!") == "!" | ||
assert Entities.encode("?") == "?" | ||
assert Entities.encode("aaaa") == "aaaa" | ||
end | ||
end | ||
|
||
describe "decode/1" do | ||
test "decode all known entities" do | ||
{:ok, json} = Jason.decode(File.read!("priv/entities.json")) | ||
entities = Map.keys(json) | ||
|
||
for entity <- entities do | ||
assert {:ok, valid} = Entities.decode(entity) | ||
assert String.valid?(valid) | ||
end | ||
end | ||
|
||
test "decode some numeric references" do | ||
entities = | ||
~w(‫ ر ق م ا ل ه ا ت ف ‮) | ||
|
||
for entity <- entities do | ||
assert {:ok, valid} = Entities.decode(entity) | ||
assert String.valid?(valid) | ||
end | ||
end | ||
|
||
test "returns not found for unknown entities" do | ||
assert {:error, :not_found} = Entities.decode("&pastel;") | ||
assert {:error, :not_found} = Entities.decode("&churrasco;") | ||
end | ||
end | ||
end |