Skip to content

Commit 379ed02

Browse files
committed
better message, tests
1 parent adecd83 commit 379ed02

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

lib/elixir/lib/enum.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,8 @@ defmodule Enum do
780780
end
781781
end
782782

783-
def count_until(_enumerable, _limit) do
784-
raise ArgumentError, "Enum.count_until/2 only accepts limits greater than 0"
783+
def count_until(_enumerable, limit) do
784+
raise ArgumentError, "expected limit to be greater than 0, got: #{limit}"
785785
end
786786

787787
@doc """
@@ -805,8 +805,8 @@ defmodule Enum do
805805
end
806806
end
807807

808-
def count_until(_enumerable, _fun, _limit) do
809-
raise ArgumentError, "Enum.count_until/3 only accepts limits greater than 0"
808+
def count_until(_enumerable, _fun, limit) do
809+
raise ArgumentError, "expected limit to be greater than 0, got: #{limit}"
810810
end
811811

812812
@doc """

lib/elixir/test/elixir/enum_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ defmodule EnumTest do
225225
assert count_until_stream.([1, 2], 2) == 2
226226
end
227227

228+
test "count_until/2 with invalid limit" do
229+
assert_raise ArgumentError, "expected limit to be greater than 0, got: 0", fn ->
230+
Enum.count_until([1, 2, 3], 0)
231+
end
232+
233+
assert_raise ArgumentError, "expected limit to be greater than 0, got: -22", fn ->
234+
Enum.count_until([1, 2, 3], -22)
235+
end
236+
end
237+
228238
test "count_until/3" do
229239
assert Enum.count_until([1, 2, 3, 4, 5, 6], fn x -> rem(x, 2) == 0 end, 2) == 2
230240
assert Enum.count_until([1, 2], fn x -> rem(x, 2) == 0 end, 2) == 1
@@ -243,6 +253,16 @@ defmodule EnumTest do
243253
assert count_until_stream.([], fn x -> rem(x, 2) == 0 end, 2) == 0
244254
end
245255

256+
test "count_until/3 with invalid limit" do
257+
assert_raise ArgumentError, "expected limit to be greater than 0, got: 0", fn ->
258+
Enum.count_until([1, 2, 3], fn x -> rem(x, 2) == 0 end, 0)
259+
end
260+
261+
assert_raise ArgumentError, "expected limit to be greater than 0, got: -22", fn ->
262+
Enum.count_until([1, 2, 3], fn x -> rem(x, 2) == 0 end, -22)
263+
end
264+
end
265+
246266
test "dedup/1" do
247267
assert Enum.dedup([1, 1, 2, 1, 1, 2, 1]) == [1, 2, 1, 2, 1]
248268
assert Enum.dedup([2, 1, 1, 2, 1]) == [2, 1, 2, 1]

0 commit comments

Comments
 (0)