-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support opaque types in doctest results (#18)
* Support opaque types in doctest results * Smoke tests
- Loading branch information
1 parent
7915b2b
commit 7bd8635
Showing
9 changed files
with
150 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -53,4 +53,17 @@ defmodule ProjectWithFormattedCode do | |
def subtract(a, b) do | ||
a - b | ||
end | ||
|
||
defmodule User do | ||
@derive {Inspect, only: [:name]} | ||
defstruct [:name, :email] | ||
end | ||
|
||
@doc """ | ||
iex> ProjectWithFormattedCode.alice() | ||
#ProjectWithFormattedCode.User<name: "Alice", ...> | ||
""" | ||
def alice do | ||
%User{name: "Alice", email: "[email protected]"} | ||
end | ||
end |
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 |
---|---|---|
|
@@ -34,4 +34,17 @@ defmodule ProjectWithUnformattedCode do | |
def subtract(a, b) do | ||
a - b | ||
end | ||
|
||
defmodule User do | ||
@derive {Inspect, only: [:name]} | ||
defstruct [:name, :email] | ||
end | ||
|
||
@doc """ | ||
iex> ProjectWithUnformattedCode.alice() | ||
#ProjectWithUnformattedCode.User<name: "Alice", ...> | ||
""" | ||
def alice do | ||
%User{name: "Alice", email: "[email protected]"} | ||
end | ||
end |
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 |
---|---|---|
|
@@ -53,4 +53,17 @@ defmodule ProjectWithFormattedCode do | |
def subtract(a, b) do | ||
a - b | ||
end | ||
|
||
defmodule User do | ||
@derive {Inspect, only: [:name]} | ||
defstruct [:name, :email] | ||
end | ||
|
||
@doc """ | ||
iex> ProjectWithFormattedCode.alice() | ||
#ProjectWithFormattedCode.User<name: "Alice", ...> | ||
""" | ||
def alice do | ||
%User{name: "Alice", email: "[email protected]"} | ||
end | ||
end |
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 |
---|---|---|
|
@@ -34,4 +34,17 @@ defmodule ProjectWithUnformattedCode do | |
def subtract(a, b) do | ||
a - b | ||
end | ||
|
||
defmodule User do | ||
@derive {Inspect, only: [:name]} | ||
defstruct [:name, :email] | ||
end | ||
|
||
@doc """ | ||
iex> ProjectWithUnformattedCode.alice() | ||
#ProjectWithUnformattedCode.User<name: "Alice", ...> | ||
""" | ||
def alice do | ||
%User{name: "Alice", email: "[email protected]"} | ||
end | ||
end |
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 |
---|---|---|
|
@@ -3,6 +3,37 @@ defmodule DoctestFormatter.FormatterTest do | |
|
||
import DoctestFormatter.Formatter | ||
|
||
test "exception_result?/1" do | ||
assert exception_result?("** (RuntimeError) some error") | ||
assert exception_result?(" ** (RuntimeError) some error ") | ||
assert exception_result?("\t** (SomeError) ") | ||
assert exception_result?(" ** ( ") | ||
|
||
refute exception_result?("**") | ||
refute exception_result?("*") | ||
refute exception_result?("") | ||
refute exception_result?("3 + 4") | ||
end | ||
|
||
test "opaque_type_result?/1" do | ||
assert opaque_type_result?("#User<>") | ||
assert opaque_type_result?(" #User<> ") | ||
assert opaque_type_result?("\t#User<> ") | ||
assert opaque_type_result?("#Accounts.User<>") | ||
assert opaque_type_result?("#Accounts.User<name: \"something\">") | ||
assert opaque_type_result?("#Accounts.User<name: \"something\", ...>") | ||
assert opaque_type_result?("#SomeModule345<>") | ||
assert opaque_type_result?("#Foo.SomeModule345<>") | ||
assert opaque_type_result?("#DateTime<2023-06-26 09:30:00+09:00 JST Asia/Tokyo>") | ||
|
||
refute opaque_type_result?("#") | ||
refute opaque_type_result?("# ") | ||
refute opaque_type_result?("# comment") | ||
refute opaque_type_result?("#not_a_module") | ||
refute opaque_type_result?("") | ||
refute opaque_type_result?("3 + 2") | ||
end | ||
|
||
describe "format/2 when no doctests" do | ||
test "works for empty strings" do | ||
assert format("", []) == "\n" | ||
|
@@ -1049,4 +1080,41 @@ defmodule DoctestFormatter.FormatterTest do | |
assert output == desired_output | ||
end | ||
end | ||
|
||
describe "format/2 on opaque types" do | ||
test "can handle exceptions in results" do | ||
input = | ||
""" | ||
defmodule Foo do | ||
defmodule User do | ||
@derive {Inspect, only: [:name]} | ||
defstruct [:name, :email] | ||
end | ||
@doc \""" | ||
iex> %Foo.User{name: "Bob", email: "[email protected]"} | ||
#Foo.User<name: "Bob", ...> | ||
\""" | ||
end | ||
""" | ||
|
||
desired_output = | ||
""" | ||
defmodule Foo do | ||
defmodule User do | ||
@derive {Inspect, only: [:name]} | ||
defstruct [:name, :email] | ||
end | ||
@doc \""" | ||
iex> %Foo.User{name: "Bob", email: "[email protected]"} | ||
#Foo.User<name: "Bob", ...> | ||
\""" | ||
end | ||
""" | ||
|
||
output = format(input, []) | ||
assert output == desired_output | ||
end | ||
end | ||
end |