Skip to content

Commit 3ec014f

Browse files
committed
Merge pull request #1128 from alco/1020-extended-doctest
Implement extended doctests
2 parents a459e35 + 4ce444a commit 3ec014f

File tree

9 files changed

+256
-124
lines changed

9 files changed

+256
-124
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ test_erlang: compile
127127
@ $(ERL) -pa lib/elixir/test/ebin -s test_helper test -s erlang halt;
128128
@ echo
129129

130-
test_elixir: test_kernel test_doctest test_mix test_ex_unit test_eex test_iex
130+
test_elixir: test_kernel test_ex_unit test_doctest test_mix test_eex test_iex
131131

132132
test_doctest: compile
133133
@ echo "==> doctest (exunit)"

lib/elixir/lib/bitwise.ex

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ defmodule Bitwise do
77
your module:
88
99
iex> use Bitwise
10-
...> bnot 1
10+
iex> bnot 1
1111
-2
12-
13-
iex> use Bitwise
14-
...> 1 &&& 1
12+
iex> 1 &&& 1
1513
1
1614
1715
You can select to include only or skip operators by passing options:
@@ -127,4 +125,4 @@ defmodule Bitwise do
127125
defmacro left >>> right do
128126
quote do: __op__ :bsr, unquote(left), unquote(right)
129127
end
130-
end
128+
end

lib/elixir/lib/dict.ex

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,9 @@ defmodule Dict do
131131
## Examples
132132
133133
iex> d = HashDict.new([a: 1])
134-
...> Dict.has_key?(d, :a)
134+
iex> Dict.has_key?(d, :a)
135135
true
136-
137-
iex> d = HashDict.new([a: 1])
138-
...> Dict.has_key?(d, :b)
136+
iex> Dict.has_key?(d, :b)
139137
false
140138
141139
"""
@@ -151,15 +149,11 @@ defmodule Dict do
151149
## Examples
152150
153151
iex> d = HashDict.new([a: 1])
154-
...> Dict.get(d, :a)
152+
iex> Dict.get(d, :a)
155153
1
156-
157-
iex> d = HashDict.new([a: 1])
158-
...> Dict.get(d, :b)
154+
iex> Dict.get(d, :b)
159155
nil
160-
161-
iex> d = HashDict.new([a: 1])
162-
...> Dict.get(d, :b, 3)
156+
iex> Dict.get(d, :b, 3)
163157
3
164158
"""
165159
@spec get(t, key, value) :: value
@@ -179,11 +173,9 @@ defmodule Dict do
179173
## Examples
180174
181175
iex> d = HashDict.new([a: 1])
182-
...> Dict.fetch(d, :a)
176+
iex> Dict.fetch(d, :a)
183177
{ :ok, 1 }
184-
185-
iex> d = HashDict.new([a: 1])
186-
...> Dict.fetch(d, :b)
178+
iex> Dict.fetch(d, :b)
187179
:error
188180
189181
"""
@@ -199,10 +191,9 @@ defmodule Dict do
199191
## Examples
200192
201193
iex> d = HashDict.new([a: 1])
202-
...> Dict.fetch!(d, :a)
194+
iex> Dict.fetch!(d, :a)
203195
1
204-
iex> d = HashDict.new([a: 1])
205-
...> Dict.fetch!(d, :b)
196+
iex> Dict.fetch!(d, :b)
206197
** (KeyError) key not found: :b
207198
208199
"""
@@ -425,11 +416,11 @@ defmodule Dict do
425416
## Examples
426417
427418
iex> d = HashDict.new([a: 1, b: 2])
419+
...>
428420
...> d = Dict.take(d, [:a, :c, :d])
429421
...> Dict.to_list(d)
430422
[a: 1]
431-
432-
iex> d = HashDict.new([a: 1, b: 2])
423+
...>
433424
...> d = Dict.take(d, [:c, :d])
434425
...> Dict.to_list(d)
435426
[]

lib/elixir/lib/enum.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,10 @@ defmodule Enum do
372372
373373
iex> Enum.fetch!([2,4,6], 0)
374374
2
375+
375376
iex> Enum.fetch!([2,4,6], 2)
376377
6
378+
377379
iex> Enum.fetch!([2,4,6], 4)
378380
** (Enum.OutOfBoundsError) out of bounds error
379381

lib/elixir/lib/keyword.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ defmodule Keyword do
152152
153153
iex> Keyword.fetch!([a: 1], :a)
154154
1
155+
155156
iex> Keyword.fetch!([a: 1], :b)
156157
** (KeyError) key not found: :b
157158
@@ -357,6 +358,7 @@ defmodule Keyword do
357358
358359
iex> Keyword.update([a: 1], :a, &1 * 2)
359360
[a: 2]
361+
360362
iex> Keyword.update([a: 1], :b, &1 * 2)
361363
** (KeyError) key not found: :b
362364

lib/elixir/lib/string.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ defmodule String do
752752
753753
"""
754754
@spec to_integer(t) :: {integer, t} | :error
755-
755+
756756
def to_integer(string) do
757757
{result, remainder} = :string.to_integer(binary_to_list(string))
758758
case result do
@@ -785,7 +785,7 @@ defmodule String do
785785
charlist = binary_to_list(string)
786786
{result, remainder} = :string.to_float(charlist)
787787
case result do
788-
:error ->
788+
:error ->
789789
{int_result, int_remainder} = :string.to_integer(charlist)
790790
case int_result do
791791
:error -> :error

lib/elixir/test/doctest.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ defmodule KernelTest do
1616
doctest Code
1717
doctest Dict
1818
doctest Enum
19+
doctest ExUnit.CaptureIO, import: true
1920
doctest IO.ANSI
2021
doctest Regex
2122
doctest String

0 commit comments

Comments
 (0)