diff options
-rw-r--r-- | lib/elixir/test/elixir/kernel/fn_test.exs | 12 | ||||
-rw-r--r-- | lib/elixir/test/elixir/kernel/warning_test.exs | 14 | ||||
-rw-r--r-- | lib/elixir/test/elixir/record_test.exs | 16 | ||||
-rw-r--r-- | lib/elixir/test/elixir/stream_test.exs | 48 |
4 files changed, 47 insertions, 43 deletions
diff --git a/lib/elixir/test/elixir/kernel/fn_test.exs b/lib/elixir/test/elixir/kernel/fn_test.exs index 104917a0f..16f52ce44 100644 --- a/lib/elixir/test/elixir/kernel/fn_test.exs +++ b/lib/elixir/test/elixir/kernel/fn_test.exs @@ -20,7 +20,7 @@ defmodule Kernel.FnTest do test "case function hoisting does not affect anonymous fns" do result = - if is_a?(:atom, 0) do + if atom?(0) do user = :defined user else @@ -53,9 +53,9 @@ defmodule Kernel.FnTest do end test "capture local with question mark" do - assert (&is_a?/2).(:atom, :a) - assert (&(is_a?/2)).(:atom, :a) - assert (&is_a?(&1, &2)).(:atom, :a) + assert (&atom?/1).(:a) + assert (&(atom?/1)).(:a) + assert (&atom?(&1)).(:a) end test "capture imported" do @@ -177,8 +177,8 @@ defmodule Kernel.FnTest do "&(&())" end - defp is_a?(:atom, atom) when is_atom(atom), do: true - defp is_a?(_, _), do: false + defp atom?(atom) when is_atom(atom), do: true + defp atom?(_), do: false defp atl(arg) do :erlang.atom_to_list(arg) diff --git a/lib/elixir/test/elixir/kernel/warning_test.exs b/lib/elixir/test/elixir/kernel/warning_test.exs index 8eb620de8..a926bde6a 100644 --- a/lib/elixir/test/elixir/kernel/warning_test.exs +++ b/lib/elixir/test/elixir/kernel/warning_test.exs @@ -351,8 +351,8 @@ defmodule Kernel.WarningTest do test "unused guard" do assert capture_err(fn -> Code.eval_string """ - defmodule Sample1 do - def is_atom_case do + defmodule Sample do + def atom_case do v = "bc" case v do _ when is_atom(v) -> :ok @@ -362,11 +362,15 @@ defmodule Kernel.WarningTest do end """ end) =~ "this check/guard will always yield the same result" + after + purge Sample + end + test "previous clause always matches" do assert capture_err(fn -> Code.eval_string """ - defmodule Sample2 do - def is_binary_cond do + defmodule Sample do + def binary_cond do v = "bc" cond do is_binary(v) -> :bin @@ -377,7 +381,7 @@ defmodule Kernel.WarningTest do """ end) =~ "this clause cannot match because a previous clause at line 5 always matches" after - purge [Sample1, Sample2] + purge Sample end test "empty clause" do diff --git a/lib/elixir/test/elixir/record_test.exs b/lib/elixir/test/elixir/record_test.exs index 5c59e6f2f..cce0ab65f 100644 --- a/lib/elixir/test/elixir/record_test.exs +++ b/lib/elixir/test/elixir/record_test.exs @@ -63,22 +63,22 @@ defmodule RecordTest do refute record?({}) end - def is_record_in_guard(term) when Record.is_record(term), + def record_in_guard?(term) when Record.is_record(term), do: true - def is_record_in_guard(_), + def record_in_guard?(_), do: false - def is_record_in_guard(term, kind) when Record.is_record(term, kind), + def record_in_guard?(term, kind) when Record.is_record(term, kind), do: true - def is_record_in_guard(_, _), + def record_in_guard?(_, _), do: false test "is_record/1/2 (in guard)" do - assert is_record_in_guard({User, "john", 27}) - refute is_record_in_guard({"user", "john", 27}) + assert record_in_guard?({User, "john", 27}) + refute record_in_guard?({"user", "john", 27}) - assert is_record_in_guard({User, "john", 27}, User) - refute is_record_in_guard({"user", "john", 27}, "user") + assert record_in_guard?({User, "john", 27}, User) + refute record_in_guard?({"user", "john", 27}, "user") end Record.defrecord :timestamp, [:date, :time] diff --git a/lib/elixir/test/elixir/stream_test.exs b/lib/elixir/test/elixir/stream_test.exs index 714136beb..7f732691c 100644 --- a/lib/elixir/test/elixir/stream_test.exs +++ b/lib/elixir/test/elixir/stream_test.exs @@ -34,10 +34,10 @@ defmodule StreamTest do test "streams are composable" do stream = Stream.map([1, 2, 3], &(&1 * 2)) - assert is_lazy(stream) + assert lazy?(stream) stream = Stream.map(stream, &(&1 + 1)) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [3, 5, 7] end @@ -81,7 +81,7 @@ defmodule StreamTest do test "chunk_by/2" do stream = Stream.chunk_by([1, 2, 2, 3, 4, 4, 6, 7, 7], &(rem(&1, 2) == 1)) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [[1], [2, 2], [3], [4, 4, 6], [7, 7]] assert stream |> Stream.take(3) |> Enum.to_list == @@ -158,7 +158,7 @@ defmodule StreamTest do end test "dedup/1 is lazy" do - assert is_lazy Stream.dedup([1, 2, 3]) + assert lazy? Stream.dedup([1, 2, 3]) end test "dedup/1" do @@ -179,7 +179,7 @@ defmodule StreamTest do test "drop/2" do stream = Stream.drop(1..10, 5) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [6, 7, 8, 9, 10] assert Enum.to_list(Stream.drop(1..5, 0)) == [1, 2, 3, 4, 5] @@ -191,7 +191,7 @@ defmodule StreamTest do test "drop/2 with negative count" do stream = Stream.drop(1..10, -5) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 2, 3, 4, 5] stream = Stream.drop(1..10, -5) @@ -255,7 +255,7 @@ defmodule StreamTest do test "drop_while/2" do stream = Stream.drop_while(1..10, &(&1 <= 5)) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [6, 7, 8, 9, 10] assert Enum.to_list(Stream.drop_while(1..5, &(&1 <= 0))) == [1, 2, 3, 4, 5] @@ -272,14 +272,14 @@ defmodule StreamTest do Process.put(:stream_each, [x | Process.get(:stream_each)]) end) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 2, 3] assert Process.get(:stream_each) == [3, 2, 1] end test "filter/2" do stream = Stream.filter([1, 2, 3], fn(x) -> rem(x, 2) == 0 end) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [2] nats = Stream.iterate(1, &(&1 + 1)) @@ -288,7 +288,7 @@ defmodule StreamTest do test "filter_map/3" do stream = Stream.filter_map([1, 2, 3], fn(x) -> rem(x, 2) == 0 end, &(&1 * 2)) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [4] nats = Stream.iterate(1, &(&1 + 1)) @@ -298,7 +298,7 @@ defmodule StreamTest do test "flat_map/2" do stream = Stream.flat_map([1, 2, 3], &[&1, &1 * 2]) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 2, 2, 4, 3, 6] nats = Stream.iterate(1, &(&1 + 1)) @@ -404,7 +404,7 @@ defmodule StreamTest do stream = Stream.into([1, 2, 3], %Pdict{}) - assert is_lazy(stream) + assert lazy?(stream) assert Stream.run(stream) == :ok assert Process.get(:stream_cont) == [3, 2, 1] assert Process.get(:stream_done) @@ -422,7 +422,7 @@ defmodule StreamTest do stream = Stream.into([1, 2, 3], %Pdict{}, fn x -> x*2 end) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 2, 3] assert Process.get(:stream_cont) == [6, 4, 2] assert Process.get(:stream_done) @@ -436,7 +436,7 @@ defmodule StreamTest do stream = Stream.into([1, 2, 3], %Pdict{}) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.take(stream, 1) == [1] assert Process.get(:stream_cont) == [1] assert Process.get(:stream_done) @@ -445,7 +445,7 @@ defmodule StreamTest do test "transform/3" do stream = Stream.transform([1, 2, 3], 0, &{[&1, &2], &1 + &2}) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 0, 2, 1, 3, 3] nats = Stream.iterate(1, &(&1 + 1)) @@ -494,7 +494,7 @@ defmodule StreamTest do test "map/2" do stream = Stream.map([1, 2, 3], &(&1 * 2)) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [2, 4, 6] nats = Stream.iterate(1, &(&1 + 1)) @@ -536,7 +536,7 @@ defmodule StreamTest do test "reject/2" do stream = Stream.reject([1, 2, 3], fn(x) -> rem(x, 2) == 0 end) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 3] nats = Stream.iterate(1, &(&1 + 1)) @@ -769,21 +769,21 @@ defmodule StreamTest do test "scan/2" do stream = Stream.scan(1..5, &(&1 + &2)) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 3, 6, 10, 15] assert Stream.scan([], &(&1 + &2)) |> Enum.to_list == [] end test "scan/3" do stream = Stream.scan(1..5, 0, &(&1 + &2)) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 3, 6, 10, 15] assert Stream.scan([], 0, &(&1 + &2)) |> Enum.to_list == [] end test "take/2" do stream = Stream.take(1..1000, 5) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 2, 3, 4, 5] assert Enum.to_list(Stream.take(1..1000, 0)) == [] @@ -823,7 +823,7 @@ defmodule StreamTest do Process.put(:stream_each, []) stream = Stream.take(1..100, -5) - assert is_lazy(stream) + assert lazy?(stream) stream = Stream.each(stream, &Process.put(:stream_each, [&1 | Process.get(:stream_each)])) assert Enum.to_list(stream) == [96, 97, 98, 99, 100] @@ -872,7 +872,7 @@ defmodule StreamTest do test "take_while/2" do stream = Stream.take_while(1..1000, &(&1 <= 5)) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [1, 2, 3, 4, 5] assert Enum.to_list(Stream.take_while(1..1000, &(&1 <= 0))) == [] @@ -984,7 +984,7 @@ defmodule StreamTest do test "with_index/2" do stream = Stream.with_index([1, 2, 3]) - assert is_lazy(stream) + assert lazy?(stream) assert Enum.to_list(stream) == [{1, 0}, {2, 1}, {3, 2}] stream = Stream.with_index([1, 2, 3], 10) @@ -994,7 +994,7 @@ defmodule StreamTest do assert Stream.with_index(nats) |> Enum.take(3) == [{1, 0}, {2, 1}, {3, 2}] end - defp is_lazy(stream) do + defp lazy?(stream) do match?(%Stream{}, stream) or is_function(stream, 2) end |