刚刚学习了 Elixir 中的 doctest,我正在尝试编写一个 Elixir doctest 来验证一个结构是否包含两个空的 MapSet。
defstruct [:coordinates, :hit_coordinates]
@doc """
Creates a new Island structure
## Examples
iex> IslandsEngine.Island.new()
%IslandsEngine.Island { coordinates: #MapSet<[]>, hit_coordinates: #MapSet<[]> }
"""
def new(), do:
%Island{ coordinates: MapSet.new(), hit_coordinates: MapSet.new() }
当我使用它运行时mix test
,出现以下错误:
Compiling 1 file (.ex)
1) doctest IslandsEngine.Island.new/0 (1) (IslandsEngine.IslandTest)
test/islands_engine/island_test.exs:3
Doctest did not compile, got: (TokenMissingError) lib/islands_engine/island.ex:19: missing terminator: } (for "{" starting at line 19)
code: %IslandsEngine.Island { coordinates: #MapSet<[]>, hit_coordinates: #MapSet<[]> }
stacktrace:
lib/islands_engine/island.ex:19: IslandsEngine.Island (module)
.......
Finished in 0.1 seconds
6 doctests, 2 tests, 1 failure
然而,在 IEx 会话中一切运行良好:
iex> IslandsEngine.Island.new()
%IslandsEngine.Island{coordinates: #MapSet<[]>, hit_coordinates: #MapSet<[]>}
iex>
谢谢你的帮助!