Remove function single do: definition syntax

This commit is contained in:
José Valim
2012-05-13 17:36:54 +02:00
parent 53ba7e7e85
commit f9dd6f66a6
12 changed files with 126 additions and 130 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ defmodule Elixir.CLI do
end
defp print_stacktrace(stacktrace) do
Enum.each stacktrace, fn(s, do: IO.puts :standard_error, " #{format_stacktrace(s)}")
Enum.each stacktrace, fn s -> IO.puts :standard_error, " #{format_stacktrace(s)}" end
end
# Process shared options
+1 -1
View File
@@ -83,6 +83,6 @@ defmodule Elixir.IEx do
end
defp print_stacktrace(io, stacktrace) do
Enum.each stacktrace, fn(s, do: io.error " #{format_stacktrace(s)}")
Enum.each stacktrace, fn s -> io.error " #{format_stacktrace(s)}" end
end
end
+2 -2
View File
@@ -322,7 +322,7 @@ defmodule Elixir.SpecialForms do
## Examples
sum = fn(x, y, do: x + y)
sum = fn(x, y) -> x + y end
sum.(1, 2) #=> 3
Notice that a function needs to be invoked using the dot between
@@ -351,7 +351,7 @@ defmodule Elixir.SpecialForms do
One may define a function which expects different clauses as long
as all clauses expects the same number of arguments:
fun = fn do:
fun = fn do
[x, y] when y < 0 ->
x - y
[x, y] ->
+26 -26
View File
@@ -87,7 +87,7 @@ defmodule Enum do
flavours. If a given collection implements the mentioned protocol (like
list, for instance), you can do
Enum.map [1,2,3], fn(x, do: x * 2)
Enum.map [1,2,3], fn(x) -> x * 2 end
Depending on the type of the collection, the user-provided function will
accept a certain type of argument. For dicts, the argument is always a
@@ -101,10 +101,10 @@ defmodule Enum do
## Examples
Enum.all? [2,4,6], fn(x, do: rem(x, 2) == 0)
Enum.all? [2,4,6], fn(x) -> rem(x, 2) == 0 end
#=> true
Enum.all? [2,3,4], fn(x, do: rem(x, 2) == 0)
Enum.all? [2,3,4], fn(x) -> rem(x, 2) == 0 end
#=> false
If no function is given, it defaults to checking if
@@ -114,7 +114,7 @@ defmodule Enum do
Enum.all? [1,nil,3] #=> false
"""
def all?(collection, fun // fn(x, do: x)) do
def all?(collection, fun // fn(x) -> x end) do
{ iterator, pointer } = I.iterator(collection)
do_all?(pointer, iterator, fun)
end
@@ -125,10 +125,10 @@ defmodule Enum do
## Examples
Enum.any? [2,4,6], fn(x, do: rem(x, 2) == 1)
Enum.any? [2,4,6], fn(x) -> rem(x, 2) == 1 end
#=> false
Enum.any? [2,3,4], fn(x, do: rem(x, 2) == 1)
Enum.any? [2,3,4], fn(x) -> rem(x, 2) == 1 end
#=> true
If no function is given, it defaults to checking if
@@ -138,7 +138,7 @@ defmodule Enum do
Enum.any? [false,true,false] #=> true
"""
def any?(collection, fun // fn(x, do: x)) do
def any?(collection, fun // fn(x) -> x end) do
{ iterator, pointer } = I.iterator(collection)
do_any?(pointer, iterator, fun)
end
@@ -164,7 +164,7 @@ defmodule Enum do
## Examples
Enum.drop_while [1,2,3,4,5], fn(x, do: x < 3)
Enum.drop_while [1,2,3,4,5], fn(x) -> x < 3 end
#=> [3,4,5]
"""
def drop_while(collection, fun) do
@@ -179,7 +179,7 @@ defmodule Enum do
## Examples
Enum.each ['some', 'example'], fn(x, do: IO.puts x)
Enum.each ['some', 'example'], fn(x) -> IO.puts x end
"""
def each(collection, fun) do
@@ -212,7 +212,7 @@ defmodule Enum do
## Examples
Enum.filter [1, 2, 3], fn(x, do: rem(x, 2) == 0)
Enum.filter [1, 2, 3], fn(x) -> rem(x, 2) == 0 end
#=> [2]
"""
@@ -226,7 +226,7 @@ defmodule Enum do
## Examples
Enum.filter_map [1, 2, 3], fn(x, do: rem(x, 2) == 0), &1 * 2
Enum.filter_map [1, 2, 3], fn(x) -> rem(x, 2) == 0 end, &1 * 2
#=> [4]
"""
@@ -241,13 +241,13 @@ defmodule Enum do
## Examples
Enum.find [2,4,6], fn(x, do: rem(x, 2) == 1)
Enum.find [2,4,6], fn(x) -> rem(x, 2) == 1 end
#=> nil
Enum.find [2,4,6], 0, fn(x, do: rem(x, 2) == 1)
Enum.find [2,4,6], 0, fn(x) -> rem(x, 2) == 1 end
#=> 0
Enum.find [2,3,4], fn(x, do: rem(x, 2) == 1)
Enum.find [2,3,4], fn(x) -> rem(x, 2) == 1 end
#=> 3
"""
@@ -262,13 +262,13 @@ defmodule Enum do
## Examples
Enum.find_value [2,4,6], fn(x, do: rem(x, 2) == 1)
Enum.find_value [2,4,6], fn(x) -> rem(x, 2) == 1 end
#=> nil
Enum.find_value [2,4,6], 0, fn(x, do: rem(x, 2) == 1)
Enum.find_value [2,4,6], 0, fn(x) -> rem(x, 2) == 1 end
#=> 0
Enum.find_value [2,3,4], fn(x, do: rem(x, 2) == 1)
Enum.find_value [2,3,4], fn(x) -> rem(x, 2) == 1 end
#=> true
"""
@@ -314,10 +314,10 @@ defmodule Enum do
## Examples
Enum.map [1, 2, 3], fn(x, do: x * 2)
Enum.map [1, 2, 3], fn(x) -> x * 2 end
#=> [2, 4, 6]
Enum.map [a: 1, b: 2], fn({k, v}, do: { k, -v })
Enum.map [a: 1, b: 2], fn({k, v}) -> { k, -v } end
#=> [a: -1, b: -2]
"""
@@ -371,7 +371,7 @@ defmodule Enum do
## Examples
Enum.map_reduce [1, 2, 3], 0, fn(x, acc, do: { x * 2, x + acc })
Enum.map_reduce [1, 2, 3], 0, fn(x, acc) -> { x * 2, x + acc } end
#=> { [2, 4, 6], 6 }
"""
@@ -391,7 +391,7 @@ defmodule Enum do
## Examples
Enum.partition [1, 2, 3], fn(x, do: rem(x, 2) == 0)
Enum.partition [1, 2, 3], fn(x) -> rem(x, 2) == 0 end
#=> { [2], [1,3] }
"""
@@ -407,7 +407,7 @@ defmodule Enum do
## Examples
Enum.reduce [1, 2, 3], 0, fn(x, acc, do: x + acc)
Enum.reduce [1, 2, 3], 0, fn(x, acc) -> x + acc end
#=> 6
"""
@@ -490,11 +490,11 @@ defmodule Enum do
## Examples
Enum.take_while [1,2,3], fn(x, do: x < 3)
Enum.take_while [1,2,3], fn(x) -> x < 3 end
#=> [1, 2]
"""
def take_while(collection, fun // fn(x, do: x)) do
def take_while(collection, fun // fn(x) -> x end) do
{ iterator, pointer } = O.iterator(collection)
do_take_while(pointer, iterator, fun)
end
@@ -505,7 +505,7 @@ defmodule Enum do
## Examples
Enum.times 3, fn(x, do: IO.puts x)
Enum.times 3, fn(x) -> IO.puts x end
1
2
3
@@ -528,7 +528,7 @@ defmodule Enum do
## Examples
Enum.times 5, 0, fn(x, acc, do: acc + x)
Enum.times 5, 0, fn(x, acc) -> acc + x end
#=> 15
"""
+1 -1
View File
@@ -44,7 +44,7 @@ defmodule ExUnit.Formatter do
defp print_failure({test_case, test, { kind, reason, stacktrace }}, acc) do
IO.puts "#{acc}) #{test} (#{inspect test_case})"
IO.puts " ** #{format_catch(kind, reason)}\n stacktrace:"
Enum.each filter_stacktrace(stacktrace), fn(s, do: IO.puts " #{format_stacktrace(s)}")
Enum.each filter_stacktrace(stacktrace), fn(s) -> IO.puts " #{format_stacktrace(s)}" end
IO.print "\n"
acc + 1
end
+3 -3
View File
@@ -10,15 +10,15 @@ defmodule ExUnit.Server do
end
def add_case(name) do
check fn(do: Erlang.gen_server.call(:exunit_server, { :add_case, name }))
check fn -> Erlang.gen_server.call(:exunit_server, { :add_case, name }) end
end
def add_sync_case(name) do
check fn(do: Erlang.gen_server.call(:exunit_server, { :add_sync_case, name }))
check fn -> Erlang.gen_server.call(:exunit_server, { :add_sync_case, name }) end
end
def merge_options(options) do
check fn(do: Erlang.gen_server.call(:exunit_server, { :merge_options, options }))
check fn -> Erlang.gen_server.call(:exunit_server, { :merge_options, options }) end
end
def options do
+1 -1
View File
@@ -127,7 +127,7 @@ defmodule Binary.Inspect.AnyTest do
use ExUnit.Case
test :funs do
bin = inspect(fn(x, do: x + 1))
bin = inspect(fn(x) -> x + 1 end)
assert_match '#Fun<' ++ _, binary_to_list(bin)
end
end
+73 -73
View File
@@ -6,9 +6,9 @@ defmodule EnumTest.Common do
test :times_with_arity_0 do
try do
Process.put(:times_with_arity, nil)
assert Enum.times(0, fn do: Process.put(:times_with_arity, :ok)) == 0
assert Enum.times(0, fn -> Process.put(:times_with_arity, :ok) end) == 0
assert Process.get(:times_with_arity) == nil
assert Enum.times(3, fn do: Process.put(:times_with_arity, :ok)) == 3
assert Enum.times(3, fn -> Process.put(:times_with_arity, :ok) end) == 3
assert Process.get(:times_with_arity) == :ok
after
Process.delete(:times_with_arity)
@@ -17,7 +17,7 @@ defmodule EnumTest.Common do
test :times_with_arity_1 do
try do
assert Enum.times(5, fn(x, do: Process.put(:times_with_arity, x))) == 5
assert Enum.times(5, fn x -> Process.put(:times_with_arity, x) end) == 5
assert Process.get(:times_with_arity) == 5
after
Process.delete(:times_with_arity)
@@ -33,8 +33,8 @@ defmodule EnumTest.List do
use ExUnit.Case
test :all? do
assert Enum.all?([2,4,6], fn(x, do: rem(x, 2) == 0))
refute Enum.all?([2,3,4], fn(x, do: rem(x, 2) == 0))
assert Enum.all?([2,4,6], fn(x) -> rem(x, 2) == 0 end)
refute Enum.all?([2,3,4], fn(x) -> rem(x, 2) == 0 end)
assert Enum.all?([2,4,6])
refute Enum.all?([2,nil,4])
@@ -43,8 +43,8 @@ defmodule EnumTest.List do
end
test :any? do
refute Enum.any?([2,4,6], fn(x, do: rem(x, 2) == 1))
assert Enum.any?([2,3,4], fn(x, do: rem(x, 2) == 1))
refute Enum.any?([2,4,6], fn(x) -> rem(x, 2) == 1 end)
assert Enum.any?([2,3,4], fn(x) -> rem(x, 2) == 1 end)
refute Enum.any?([false,false,false])
assert Enum.any?([false,true,false])
@@ -62,22 +62,22 @@ defmodule EnumTest.List do
end
test :drop_while do
assert Enum.drop_while([1,2,3,4,3,2,1], fn(x, do: x <= 3)) == [4,3,2,1]
assert Enum.drop_while([1,2,3], fn(_, do: false)) == [1,2,3]
assert Enum.drop_while([1,2,3], fn(x, do: x <= 3)) == []
assert Enum.drop_while([], fn(_, do: false)) == []
assert Enum.drop_while([1,2,3,4,3,2,1], fn(x) -> x <= 3 end) == [4,3,2,1]
assert Enum.drop_while([1,2,3], fn(_) -> false end) == [1,2,3]
assert Enum.drop_while([1,2,3], fn(x) -> x <= 3 end) == []
assert Enum.drop_while([], fn(_) -> false end) == []
end
test :find do
assert Enum.find([2,4,6], fn(x, do: rem(x, 2) == 1)) == nil
assert Enum.find([2,4,6], 0, fn(x, do: rem(x, 2) == 1)) == 0
assert Enum.find([2,3,4], fn(x, do: rem(x, 2) == 1)) == 3
assert Enum.find([2,4,6], fn(x) -> rem(x, 2) == 1 end) == nil
assert Enum.find([2,4,6], 0, fn(x) -> rem(x, 2) == 1 end) == 0
assert Enum.find([2,3,4], fn(x) -> rem(x, 2) == 1 end) == 3
end
test :find_value do
assert Enum.find_value([2,4,6], fn(x, do: rem(x, 2) == 1)) == nil
assert Enum.find_value([2,4,6], 0, fn(x, do: rem(x, 2) == 1)) == 0
assert Enum.find_value([2,3,4], fn(x, do: rem(x, 2) == 1))
assert Enum.find_value([2,4,6], fn(x) -> rem(x, 2) == 1 end) == nil
assert Enum.find_value([2,4,6], 0, fn(x) -> rem(x, 2) == 1 end) == 0
assert Enum.find_value([2,3,4], fn(x) -> rem(x, 2) == 1 end)
end
test :empty? do
@@ -87,9 +87,9 @@ defmodule EnumTest.List do
test :each do
try do
assert Enum.each([], fn(x, do: x)) == []
assert Enum.each([], fn(x) -> x end) == []
assert Enum.each([1,2,3], fn(x, do: Process.put(:enum_test_each, x * 2))) == [1,2,3]
assert Enum.each([1,2,3], fn(x) -> Process.put(:enum_test_each, x * 2) end) == [1,2,3]
assert Process.get(:enum_test_each) == 6
after
Process.delete(:enum_test_each)
@@ -97,8 +97,8 @@ defmodule EnumTest.List do
end
test :filter do
assert Enum.filter([1,2,3], fn(x, do: rem(x, 2) == 0)) == [2]
assert Enum.filter([2,4,6], fn(x, do: rem(x, 2) == 0)) == [2,4,6]
assert Enum.filter([1,2,3], fn(x) -> rem(x, 2) == 0 end) == [2]
assert Enum.filter([2,4,6], fn(x) -> rem(x, 2) == 0 end) == [2,4,6]
end
test :filter_with_match do
@@ -108,13 +108,13 @@ defmodule EnumTest.List do
end
test :filter_map do
assert Enum.filter_map([1,2,3], fn(x, do: rem(x, 2) == 0), &1 * 2) == [4]
assert Enum.filter_map([2,4,6], fn(x, do: rem(x, 2) == 0), &1 * 2) == [4,8,12]
assert Enum.filter_map([1,2,3], fn(x) -> rem(x, 2) == 0 end, &1 * 2) == [4]
assert Enum.filter_map([2,4,6], fn(x) -> rem(x, 2) == 0 end, &1 * 2) == [4,8,12]
end
test :reduce do
assert Enum.reduce([], 1, fn(x, acc, do: x + acc)) == 1
assert Enum.reduce([1,2,3], 1, fn(x, acc, do: x + acc)) == 7
assert Enum.reduce([], 1, fn(x, acc) -> x + acc end) == 1
assert Enum.reduce([1,2,3], 1, fn(x, acc) -> x + acc end) == 7
end
test :join_with_bin do
@@ -147,13 +147,13 @@ defmodule EnumTest.List do
end
test :map_reduce do
assert Enum.map_reduce([], 1, fn(x, acc, do: { x * 2, x + acc })) == { [], 1 }
assert Enum.map_reduce([1,2,3], 1, fn(x, acc, do: { x * 2, x + acc })) == { [2,4,6], 7 }
assert Enum.map_reduce([], 1, fn(x, acc) -> { x * 2, x + acc } end) == { [], 1 }
assert Enum.map_reduce([1,2,3], 1, fn(x, acc) -> { x * 2, x + acc } end) == { [2,4,6], 7 }
end
test :partition do
assert Enum.partition([1,2,3], fn(x, do: rem(x, 2) == 0)) == { [2], [1,3] }
assert Enum.partition([2,4,6], fn(x, do: rem(x, 2) == 0)) == { [2,4,6], [] }
assert Enum.partition([1,2,3], fn(x) -> rem(x, 2) == 0 end) == { [2], [1,3] }
assert Enum.partition([2,4,6], fn(x) -> rem(x, 2) == 0 end) == { [2,4,6], [] }
end
test :qsort do
@@ -170,12 +170,12 @@ defmodule EnumTest.List do
end
test :split_with do
assert Enum.split_with([1,2,3], fn(_, do: false)) == { [], [1,2,3] }
assert Enum.split_with([1,2,3], fn(_, do: true)) == { [1,2,3], [] }
assert Enum.split_with([1,2,3], fn(x, do: x > 2)) == { [], [1,2,3] }
assert Enum.split_with([1,2,3], fn(x, do: x > 3)) == { [], [1,2,3] }
assert Enum.split_with([1,2,3], fn(x, do: x < 3)) == { [1,2], [3] }
assert Enum.split_with([], fn(_, do: true)) == { [], [] }
assert Enum.split_with([1,2,3], fn(_) -> false end) == { [], [1,2,3] }
assert Enum.split_with([1,2,3], fn(_) -> true end) == { [1,2,3], [] }
assert Enum.split_with([1,2,3], fn(x) -> x > 2 end) == { [], [1,2,3] }
assert Enum.split_with([1,2,3], fn(x) -> x > 3 end) == { [], [1,2,3] }
assert Enum.split_with([1,2,3], fn(x) -> x < 3 end) == { [1,2], [3] }
assert Enum.split_with([], fn(_) -> true end) == { [], [] }
end
test :take do
@@ -188,10 +188,10 @@ defmodule EnumTest.List do
end
test :take_while do
assert Enum.take_while([1,2,3], fn(x, do: x > 3)) == []
assert Enum.take_while([1,2,3], fn(x, do: x <= 1)) == [1]
assert Enum.take_while([1,2,3], fn(x, do: x <= 3)) == [1,2,3]
assert Enum.take_while([], fn(_, do: true)) == []
assert Enum.take_while([1,2,3], fn(x) -> x > 3 end) == []
assert Enum.take_while([1,2,3], fn(x) -> x <= 1 end) == [1]
assert Enum.take_while([1,2,3], fn(x) -> x <= 3 end) == [1,2,3]
assert Enum.take_while([], fn(_) -> true end) == []
end
end
@@ -202,33 +202,33 @@ defmodule EnumTest.Dict.Common do
test :all? do
dict = unquote(module).new [{2,2}, {3,4}, {4,6}]
assert Enum.all?(dict, fn({_, v}, do: rem(v, 2) == 0))
refute Enum.all?(dict, fn({k, _}, do: rem(k, 2) == 0))
assert Enum.all?(dict, fn({_, v}) -> rem(v, 2) == 0 end)
refute Enum.all?(dict, fn({k, _}) -> rem(k, 2) == 0 end)
assert Enum.all?(unquote(module).new)
end
test :any? do
dict = unquote(module).new [{2,2}, {3,4}, {4,6}]
refute Enum.any?(dict, fn({_, v}, do: rem(v, 2) == 1))
assert Enum.any?(dict, fn({k, _}, do: rem(k, 2) == 1))
refute Enum.any?(dict, fn({_, v}) -> rem(v, 2) == 1 end)
assert Enum.any?(dict, fn({k, _}) -> rem(k, 2) == 1 end)
refute Enum.any?(unquote(module).new)
end
test :find do
dict = unquote(module).new [a: 1, b: 2, c: 3]
assert nil == Enum.find(dict, fn({_, v}, do: v == 0))
assert :ok == Enum.find(dict, :ok, fn({_, v}, do: v == 0))
assert {:a, 1} == Enum.find(dict, fn({_, v}, do: rem(v, 2) == 1))
assert {:b, 2} == Enum.find(dict, fn({_, v}, do: rem(v, 2) == 0))
assert nil == Enum.find(dict, fn({_, v}) -> v == 0 end)
assert :ok == Enum.find(dict, :ok, fn({_, v}) -> v == 0 end)
assert {:a, 1} == Enum.find(dict, fn({_, v}) -> rem(v, 2) == 1 end)
assert {:b, 2} == Enum.find(dict, fn({_, v}) -> rem(v, 2) == 0 end)
end
test :find_value do
dict = unquote(module).new [a: 1, b: 2, c: 3]
assert nil == Enum.find_value(dict, fn({_, v}, do: v == 0))
assert :ok == Enum.find_value(dict, :ok, fn({_, v}, do: v == 0))
assert Enum.find_value(dict, fn({_, v}, do: rem(v, 2) == 1))
assert nil == Enum.find_value(dict, fn({_, v}) -> v == 0 end)
assert :ok == Enum.find_value(dict, :ok, fn({_, v}) -> v == 0 end)
assert Enum.find_value(dict, fn({_, v}) -> rem(v, 2) == 1 end)
end
test :empty? do
@@ -239,10 +239,10 @@ defmodule EnumTest.Dict.Common do
test :each do
try do
empty_dict = unquote(module).new
assert empty_dict == Enum.each(empty_dict, fn(x, do: x))
assert empty_dict == Enum.each(empty_dict, fn(x) -> x end)
dict = unquote(module).new [{"one",1}, {"two",2}, {"three",3}]
assert dict == Enum.each(dict, fn({k, v}, do: Process.put(k, v * 2)))
assert dict == Enum.each(dict, fn({k, v}) -> Process.put(k, v * 2) end)
assert 2 == Process.get("one")
assert 4 == Process.get("two")
assert 6 == Process.get("three")
@@ -259,9 +259,9 @@ defmodule EnumTest.Dict.Common do
even = [b: 2, d: 4]
dict = unquote(module).new(all)
assert Enum.filter(dict, fn({_, v}, do: rem(v, 2) == 1)) == odd
assert Enum.filter(dict, fn({_, v}, do: rem(v, 2) == 0)) == even
assert Enum.filter(dict, fn(x, do: x)) == all
assert Enum.filter(dict, fn({_, v}) -> rem(v, 2) == 1 end) == odd
assert Enum.filter(dict, fn({_, v}) -> rem(v, 2) == 0 end) == even
assert Enum.filter(dict, fn(x) -> x end) == all
end
test :filter_map do
@@ -269,12 +269,12 @@ defmodule EnumTest.Dict.Common do
even_dict = unquote(module).new [a: 2, b: 4, c: 6]
assert Enum.filter_map(odd_dict,
fn({_, v}, do: rem(v, 2) == 0),
fn({k, v}, do: { k, v * 2 })) == [b: 4]
fn({_, v}) -> rem(v, 2) == 0 end,
fn({k, v}) -> { k, v * 2 } end) == [b: 4]
assert Enum.filter_map(even_dict,
fn({_, v}, do: rem(v, 2) == 0),
fn({k, v}, do: { k, v * 2 })) == [a: 4, b: 8, c: 12]
fn({_, v}) -> rem(v, 2) == 0 end,
fn({k, v}) -> { k, v * 2 } end) == [a: 4, b: 8, c: 12]
end
test :join do
@@ -290,8 +290,8 @@ defmodule EnumTest.Dict.Common do
test :reduce do
dict = unquote(module).new [a: 1, b: 2, c: 3]
assert 1 == Enum.reduce(unquote(module).new, 1, fn(x, acc, do: x + acc))
assert 7 == Enum.reduce(dict, 1, fn({_, v}, acc, do: v + acc))
assert 1 == Enum.reduce(unquote(module).new, 1, fn(x, acc) -> x + acc end)
assert 7 == Enum.reduce(dict, 1, fn({_, v}, acc) -> v + acc end)
end
test :map do
@@ -303,8 +303,8 @@ defmodule EnumTest.Dict.Common do
test :map_reduce do
dict = unquote(module).new [a: 1, b: 2, c: 3]
double = [a: 2, b: 4, c: 6]
assert Enum.map_reduce(dict, 1, fn({k, v}, acc, do: { {k, v * 2}, v + acc })) == { double, 7 }
assert Enum.map_reduce(unquote(module).new, 1, fn(x, acc, do: { x * 2, x + acc })) == { [], 1 }
assert Enum.map_reduce(dict, 1, fn({k, v}, acc) -> { {k, v * 2}, v + acc } end) == { double, 7 }
assert Enum.map_reduce(unquote(module).new, 1, fn(x, acc) -> { x * 2, x + acc } end) == { [], 1 }
end
test :partition do
@@ -313,8 +313,8 @@ defmodule EnumTest.Dict.Common do
above_4 = [d: 4, e: 5, f: 6, g: 7]
dict = unquote(module).new all
assert { below_4, above_4 } == Enum.partition(dict, fn({_k, v}, do: v < 4))
assert { all, [] } == Enum.partition(dict, fn({_k, v}, do: v < 10))
assert { below_4, above_4 } == Enum.partition(dict, fn({_k, v}) -> v < 4 end)
assert { all, [] } == Enum.partition(dict, fn({_k, v}) -> v < 10 end)
end
test :qsort do
@@ -337,7 +337,7 @@ defmodule EnumTest.HashDict do
test :drop_while do
assert_raise Protocol.UndefinedError, fn ->
Enum.drop_while HashDict.new, fn(x, do: x)
Enum.drop_while HashDict.new, fn(x) -> x end
end
end
@@ -349,7 +349,7 @@ defmodule EnumTest.HashDict do
test :split_with do
assert_raise Protocol.UndefinedError, fn ->
Enum.split_with HashDict.new, fn(x, do: x)
Enum.split_with HashDict.new, fn(x) -> x end
end
end
@@ -361,7 +361,7 @@ defmodule EnumTest.HashDict do
test :take_while do
assert_raise Protocol.UndefinedError, fn ->
Enum.take_while HashDict.new, fn(x, do: x)
Enum.take_while HashDict.new, fn(x) -> x end
end
end
end
@@ -379,7 +379,7 @@ defmodule EnumTest.Orddict do
test :drop_while do
dict = Orddict.new [a: 1, b: 2, c: 3]
assert Enum.drop_while(dict, fn({_k, v}, do: v < 3)) == [c: 3]
assert Enum.drop_while(dict, fn({_k, v}) -> v < 3 end) == [c: 3]
end
test :split do
@@ -392,7 +392,7 @@ defmodule EnumTest.Orddict do
test :split_with do
dict = Orddict.new [a: 1, b: 3, c: 2, d: 4]
assert Enum.split_with(dict, fn({_k, v}, do: rem(v, 2) == 1)) == { [a: 1, b: 3], [c: 2, d: 4] }
assert Enum.split_with(dict, fn({_k, v}) -> rem(v, 2) == 1 end) == { [a: 1, b: 3], [c: 2, d: 4] }
end
test :take do
@@ -405,8 +405,8 @@ defmodule EnumTest.Orddict do
test :take_while do
dict = Orddict.new [a: 1, b: 3, c: 2, d: 4]
assert Enum.take_while(dict, fn({_k, v}, do: rem(v, 2) == 1)) == [a: 1, b: 3]
assert Enum.take_while(dict, fn({_k, v}, do: v < 10)) == [a: 1, b: 3, c: 2, d: 4]
assert Enum.take_while(dict, fn({_k, v}, do: v < 1)) == []
assert Enum.take_while(dict, fn({_k, v}) -> rem(v, 2) == 1 end) == [a: 1, b: 3]
assert Enum.take_while(dict, fn({_k, v}) -> v < 10 end) == [a: 1, b: 3, c: 2, d: 4]
assert Enum.take_while(dict, fn({_k, v}) -> v < 1 end) == []
end
end
+2 -2
View File
@@ -1,8 +1,8 @@
defmodule AtExit do
def at_exit(str) do
System.at_exit fn(_, do: IO.print str)
System.at_exit fn(_) -> IO.print(str) end
end
end
System.at_exit fn(status, do: IO.puts "cruel world with status #{status}")
System.at_exit fn(status) -> IO.puts "cruel world with status #{status}" end
AtExit.at_exit("goodbye ")
exit(0)
+1 -1
View File
@@ -180,7 +180,7 @@ defmodule Kernel.RescueTest do
end
test :badarity_error do
fun = fn(x, do: x)
fun = fn(x) -> x end
string = "bad arity error: #{inspect(fun)} called with [1,2]"
result = try do
+4 -4
View File
@@ -44,7 +44,7 @@ defmodule ProtocolTest do
test :protocol_with_all do
assert_undef(ProtocolTest.WithAll, Atom, :foo)
assert_undef(ProtocolTest.WithAll, Function, fn(x, do: x))
assert_undef(ProtocolTest.WithAll, Function, fn(x) -> x end)
assert_undef(ProtocolTest.WithAll, Number, 1)
assert_undef(ProtocolTest.WithAll, Number, 1.1)
assert_undef(ProtocolTest.WithAll, List, [])
@@ -63,12 +63,12 @@ defmodule ProtocolTest do
assert_undef(ProtocolTest.WithExcept, Any, :foo)
assert_undef(ProtocolTest.WithExcept, Any, 1)
assert_undef(ProtocolTest.WithExcept, Any, [1,2,3])
assert_undef(ProtocolTest.WithExcept, Function, fn(x, do: x))
assert_undef(ProtocolTest.WithExcept, Function, fn(x) -> x end)
assert_undef(ProtocolTest.WithExcept, Tuple, {})
end
test :protocol_with_only do
assert_undef ProtocolTest.WithOnly, Function, fn(x, do: x)
assert_undef ProtocolTest.WithOnly, Function, fn(x) -> x end
assert ProtocolTest.WithOnly.blank(ProtocolTest.Foo.new) == true
end
@@ -87,7 +87,7 @@ defmodule ProtocolTest do
test :protocol_for do
assert_protocol_for(ProtocolTest.WithAll, Atom, :foo)
assert_protocol_for(ProtocolTest.WithAll, Function, fn(x, do: x))
assert_protocol_for(ProtocolTest.WithAll, Function, fn(x) -> x end)
assert_protocol_for(ProtocolTest.WithAll, Number, 1)
assert_protocol_for(ProtocolTest.WithAll, Number, 1.1)
assert_protocol_for(ProtocolTest.WithAll, List, [])
+11 -15
View File
@@ -13,28 +13,24 @@ function_arg_do_end_test() ->
{3, _} = eval("if date do\n1 + 2\nend"),
{nil, _} = eval("if date do end").
function_assignment_test() ->
{_, [{a, Fun}]} = eval("a = fn do: 1 + 2"),
3 = Fun().
function_stab_end_test() ->
{_, [{a, Fun}]} = eval("a = fn -> 1 + 2 end"),
3 = Fun().
function_with_args_test() ->
{Fun, _} = eval("fn(a, b, do: a + b)"),
{Fun, _} = eval("fn(a, b) -> a + b end"),
3 = Fun(1,2).
function_with_kv_args_test() ->
{Fun, _} = eval("fn(a, [other: b, another: c], do: a + b + c)"),
{Fun, _} = eval("fn(a, [other: b, another: c]) -> a + b + c end"),
6 = Fun(1,[{another,3},{other,2}]).
function_as_clojure_test() ->
{_, [{a, Res1}|_]} = eval("b = 1; a = fn do: b + 2"),
{_, [{a, Res1}|_]} = eval("b = 1; a = fn -> b + 2 end"),
3 = Res1().
function_apply_test() ->
{3,_} = eval("a = fn do: 3; apply a, []").
{3,_} = eval("a = fn -> 3 end; apply a, []").
function_apply_with_args_test() ->
{3,_} = eval("a = fn b -> b + 2 end; apply a, [1]").
@@ -45,25 +41,25 @@ function_apply_and_clojure_test() ->
%% Function calls
function_call_test() ->
{3, _} = eval("x = fn(a,b, do: a + b)\nx.(1,2)").
{3, _} = eval("x = fn a, b -> a + b end\nx.(1,2)").
function_call_without_arg_test() ->
{3, _} = eval("x = fn do: 2 + 1\nx.()").
{3, _} = eval("x = fn -> 2 + 1 end\nx.()").
function_call_do_end_test() ->
{[1,[{do,2},{else,3}]], _} = eval("x = fn(a, b, do: [a,b])\nx.(1) do\n2\nelse: 3\nend").
{[1,[{do,2},{else,3}]], _} = eval("x = fn a, b -> [a,b] end\nx.(1) do\n2\nelse 3\nend").
function_call_with_assignment_test() ->
{3, [{a,_},{c, 3}]} = eval("a = fn(x, do: x + 2); c = a.(1)").
{3, [{a,_},{c, 3}]} = eval("a = fn x -> x + 2 end; c = a.(1)").
function_calls_with_multiple_expressions_test() ->
{26, _} = eval("a = fn(a, b, do: a + b); a.((3 + 4 - 1), (2 * 10))").
{26, _} = eval("a = fn a, b -> a + b end; a.((3 + 4 - 1), (2 * 10))").
function_calls_with_multiple_args_with_line_breaks_test() ->
{5, _} = eval("a = fn(a, b, do: a + b); a.(\n3,\n2\n)").
{5, _} = eval("a = fn a, b -> a + b end; a.(\n3,\n2\n)").
function_calls_with_parenthesis_test() ->
{3, [{a,_},{b,1}]} = eval("a = fn(x, do: x + 2).(b = 1)").
{3, [{a,_},{b,1}]} = eval("a = (fn x -> x + 2 end).(b = 1)").
%% Partial application