Skip to content

Commit

Permalink
Test encode ASCII characters as integer (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
kianmeng authored Feb 4, 2022
1 parent 81b4e0e commit 89608b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/makeup/formatters/html/html_formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ defmodule Makeup.Formatters.HTML.HTMLFormatter do
end

defp escape(c) when is_integer(c) do
#
[escape_for(c)]
end

Expand Down
18 changes: 12 additions & 6 deletions test/html_formatter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule MakeupTest.Lexer.HTMLFormatterTest do
# Handles an edge case in the HTML formatter (already fixed),
# in which the case c == 128 wasn't handled.
# The previous version would raise an error.

# Encode the right hand side as a concatenation of binaries
# to make it more obvious:
assert HTMLFormatter.format_as_binary([{:string, %{}, [128]}]) ==
Expand All @@ -22,32 +22,38 @@ defmodule MakeupTest.Lexer.HTMLFormatterTest do
# Handles an edge case in the HTML formatter (already fixed),
# in which the case c == 128 wasn't handled.
# The previous version would raise an error.

# Encode the right hand side as a concatenation of binaries
# to make it more obvious:
check all c <- StreamData.integer(1..127),
not(c in [?&, ?<, ?>, ?", ?']) do
assert HTMLFormatter.format_as_binary([{:string, %{}, [c]}]) ==
html =
~S[<pre class="highlight"><code>] <>
~S[<span class="s">] <>
<< c >> <>
~S[</span>] <>
~S[</code></pre>]

assert HTMLFormatter.format_as_binary([{:string, %{}, [c]}]) == html
assert HTMLFormatter.format_as_binary([{:string, %{}, c}]) == html
end
end

test "encode ASCII character (c >= 128)" do
# Some of these characters won't be valid unicode but that doesn't matter

# Encode the right hand side as a concatenation of binaries
# to make it more obvious:
check all c <- StreamData.integer(128..16666) do
assert HTMLFormatter.format_as_binary([{:string, %{}, [c]}]) ==
html =
~S[<pre class="highlight"><code>] <>
~S[<span class="s">] <>
<< c :: utf8 >> <>
~S[</span>] <>
~S[</code></pre>]

assert HTMLFormatter.format_as_binary([{:string, %{}, [c]}]) == html
assert HTMLFormatter.format_as_binary([{:string, %{}, c}]) == html
end
end

Expand All @@ -67,4 +73,4 @@ defmodule MakeupTest.Lexer.HTMLFormatterTest do
~S[</code></pre>]
end
end
end
end

0 comments on commit 89608b8

Please sign in to comment.