Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 20, 2021
1 parent b88db58 commit 1511fbc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/ex_doc/formatter/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ defmodule ExDoc.Formatter.HTML do
group = GroupMatcher.match_extra(groups, input)
title = title || title_text || filename_to_title(input)

source_path = Path.relative_to(input, ".")
source_path = input |> Path.relative_to(File.cwd!()) |> String.replace_leading("./", "")

source_url =
if url = config.source_url_pattern do
Expand Down
34 changes: 28 additions & 6 deletions test/ex_doc/formatter/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ defmodule ExDoc.Formatter.HTMLTest do
assets: "test/tmp/html_assets",
output: output_dir(),
source_beam: beam_dir(),
source_url: "https://github.com/elixir-lang/elixir",
logo: "test/fixtures/elixir.png",
extras: [
"test/fixtures/LICENSE",
Expand Down Expand Up @@ -349,6 +350,9 @@ defmodule ExDoc.Formatter.HTMLTest do

assert content =~ "<p><strong>raw content</strong></p>"

assert content =~
~s{<a href="https://github.com/elixir-lang/elixir/blob/master/test/fixtures/README.md#L1" title="View Source"}

content = File.read!("#{output_dir()}/plaintextfiles.html")

assert content =~
Expand All @@ -359,21 +363,39 @@ defmodule ExDoc.Formatter.HTMLTest do
assert plain_text_file =~
~R{<pre>\nThis is plain\n text and nothing\n.+\s+good bye\n</pre>}s

assert plain_text_file =~ ~R{\n## Neither formatted\n}
assert plain_text_file =~ ~R{\n `t:term/0`\n}
assert plain_text_file =~ ~s{\n## Neither formatted\n}
assert plain_text_file =~ ~s{\n `t:term/0`\n}

plain_text_file = File.read!("#{output_dir()}/license.html")
license = File.read!("#{output_dir()}/license.html")

assert plain_text_file =~
assert license =~
~s{<pre>\nLicensed under the Apache License, Version 2.0 (the &quot;License&quot;)}

content = File.read!("#{output_dir()}/livebookfile.html")

assert content =~
~R{<p>Read <code class="inline">.livemd</code> files generated by <a href="https://github.com/livebook-dev/livebook">livebook</a>.}
~s{<a href="https://github.com/elixir-lang/elixir/blob/master/test/fixtures/LivebookFile.livemd#L1" title="View Source"}

assert content =~
~R{<img src="https://livebook.dev/badge/v1/blue.svg" alt="Run in Livebook" width="150" />}
~s{<p>Read <code class="inline">.livemd</code> files generated by <a href="https://github.com/livebook-dev/livebook">livebook</a>.}

assert content =~
~s{<img src="https://livebook.dev/badge/v1/blue.svg" alt="Run in Livebook" width="150" />}
end

test "with absolute and dot-relative paths for extra" do
config = doc_config(extras: ["./test/fixtures/README.md", Path.expand("test/fixtures/LivebookFile.livemd")])
generate_docs(config)

content = File.read!("#{output_dir()}/readme.html")

assert content =~
~s{<a href="https://github.com/elixir-lang/elixir/blob/master/test/fixtures/README.md#L1" title="View Source"}

content = File.read!("#{output_dir()}/livebookfile.html")

assert content =~
~s{<a href="https://github.com/elixir-lang/elixir/blob/master/test/fixtures/LivebookFile.livemd#L1" title="View Source"}
end

test "without any other content" do
Expand Down

0 comments on commit 1511fbc

Please sign in to comment.