diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-03-10 20:07:37 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-03-10 20:07:37 +0000 |
commit | 2a7d9061e4ec9c763053b078db2d98400bd08dd5 (patch) | |
tree | a6f36c30dc08db6a85cd1dad4b99031380e81832 /gen | |
parent | d74af16e6a527f46730c3d35554ef55677c9caf4 (diff) | |
download | gleam_stdlib-2a7d9061e4ec9c763053b078db2d98400bd08dd5.tar.gz gleam_stdlib-2a7d9061e4ec9c763053b078db2d98400bd08dd5.zip |
Surround Fn's in parens if called directly
Closes https://github.com/lpil/gleam/issues/88
Diffstat (limited to 'gen')
-rw-r--r-- | gen/bool.erl | 20 | ||||
-rw-r--r-- | gen/list.erl | 66 | ||||
-rw-r--r-- | gen/map.erl | 28 | ||||
-rw-r--r-- | gen/order.erl | 66 | ||||
-rw-r--r-- | gen/result.erl | 68 |
5 files changed, 125 insertions, 123 deletions
diff --git a/gen/bool.erl b/gen/bool.erl index 52a9379..9024a16 100644 --- a/gen/bool.erl +++ b/gen/bool.erl @@ -14,10 +14,10 @@ max(A, B) -> -ifdef(TEST). max_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, true) end(max(true, true)), - _ = fun(Capture1) -> expect:equal(Capture1, true) end(max(true, false)), - _ = fun(Capture1) -> expect:equal(Capture1, false) end(max(false, false)), - fun(Capture1) -> expect:equal(Capture1, true) end(max(false, true)). + _ = (fun(Capture1) -> expect:equal(Capture1, true) end)(max(true, true)), + _ = (fun(Capture1) -> expect:equal(Capture1, true) end)(max(true, false)), + _ = (fun(Capture1) -> expect:equal(Capture1, false) end)(max(false, false)), + (fun(Capture1) -> expect:equal(Capture1, true) end)(max(false, true)). -endif. min(A, B) -> @@ -31,10 +31,10 @@ min(A, B) -> -ifdef(TEST). min_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, true) end(min(true, true)), - _ = fun(Capture1) -> expect:equal(Capture1, false) end(min(true, false)), - _ = fun(Capture1) -> expect:equal(Capture1, false) end(min(false, false)), - fun(Capture1) -> expect:equal(Capture1, false) end(min(false, true)). + _ = (fun(Capture1) -> expect:equal(Capture1, true) end)(min(true, true)), + _ = (fun(Capture1) -> expect:equal(Capture1, false) end)(min(true, false)), + _ = (fun(Capture1) -> expect:equal(Capture1, false) end)(min(false, false)), + (fun(Capture1) -> expect:equal(Capture1, false) end)(min(false, true)). -endif. to_int(Bool) -> @@ -48,6 +48,6 @@ to_int(Bool) -> -ifdef(TEST). to_int_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, 1) end(to_int(true)), - fun(Capture1) -> expect:equal(Capture1, 0) end(to_int(false)). + _ = (fun(Capture1) -> expect:equal(Capture1, 1) end)(to_int(true)), + (fun(Capture1) -> expect:equal(Capture1, 0) end)(to_int(false)). -endif. diff --git a/gen/list.erl b/gen/list.erl index 2d87a6a..0e5f1f2 100644 --- a/gen/list.erl +++ b/gen/list.erl @@ -8,10 +8,10 @@ length(A) -> -ifdef(TEST). length_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, 0) end(length([])), - _ = fun(Capture1) -> expect:equal(Capture1, 1) end(length([1])), - _ = fun(Capture1) -> expect:equal(Capture1, 2) end(length([1, 1])), - fun(Capture1) -> expect:equal(Capture1, 3) end(length([1, 1, 1])). + _ = (fun(Capture1) -> expect:equal(Capture1, 0) end)(length([])), + _ = (fun(Capture1) -> expect:equal(Capture1, 1) end)(length([1])), + _ = (fun(Capture1) -> expect:equal(Capture1, 2) end)(length([1, 1])), + (fun(Capture1) -> expect:equal(Capture1, 3) end)(length([1, 1, 1])). -endif. reverse(A) -> @@ -19,8 +19,8 @@ reverse(A) -> -ifdef(TEST). reverse_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, 0) end(length([])), - fun(Capture1) -> expect:equal(Capture1, 5) end(length([1, 2, 3, 4, 5])). + _ = (fun(Capture1) -> expect:equal(Capture1, 0) end)(length([])), + (fun(Capture1) -> expect:equal(Capture1, 5) end)(length([1, 2, 3, 4, 5])). -endif. is_empty(List) -> @@ -59,10 +59,10 @@ head(List) -> -ifdef(TEST). head_test() -> - _ = fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, {ok, 0}) - end(head([0, 4, 5, 7])), - fun(Capture1) -> expect:equal(Capture1, {error, empty}) end(head([])). + end)(head([0, 4, 5, 7])), + (fun(Capture1) -> expect:equal(Capture1, {error, empty}) end)(head([])). -endif. tail(List) -> @@ -76,11 +76,11 @@ tail(List) -> -ifdef(TEST). tail_test() -> - _ = fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, {ok, [4, 5, 7]}) - end(tail([0, 4, 5, 7])), - _ = fun(Capture1) -> expect:equal(Capture1, {ok, []}) end(tail([0])), - fun(Capture1) -> expect:equal(Capture1, {error, empty}) end(tail([])). + end)(tail([0, 4, 5, 7])), + _ = (fun(Capture1) -> expect:equal(Capture1, {ok, []}) end)(tail([0])), + (fun(Capture1) -> expect:equal(Capture1, {error, empty}) end)(tail([])). -endif. do_map(List, Fun, Acc) -> @@ -97,14 +97,14 @@ map(List, Fun) -> -ifdef(TEST). map_test() -> - _ = fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, []) - end(fun(Capture1) -> map(Capture1, fun(X) -> X * 2 end) end([])), - fun(Capture1) -> + end)((fun(Capture1) -> map(Capture1, fun(X) -> X * 2 end) end)([])), + (fun(Capture1) -> expect:equal(Capture1, [0, 8, 10, 14, 6]) - end(fun(Capture1) -> - map(Capture1, fun(X) -> X * 2 end) - end([0, 4, 5, 7, 3])). + end)((fun(Capture1) -> + map(Capture1, fun(X) -> X * 2 end) + end)([0, 4, 5, 7, 3])). -endif. do_traverse(List, Fun, Acc) -> @@ -127,19 +127,19 @@ traverse(List, Fun) -> -ifdef(TEST). traverse_test() -> - Fun = fun(X) -> case X =:= 6 orelse X =:= 5 of + Fun = fun(X) -> case X =:= 6 orelse X =:= 5 orelse X =:= 4 of true -> {ok, X * 2}; false -> {error, X} end end, - _ = fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, {ok, [10, 12, 10, 12]}) - end(fun(Capture1) -> traverse(Capture1, Fun) end([5, 6, 5, 6])), - fun(Capture1) -> + end)((fun(Capture1) -> traverse(Capture1, Fun) end)([5, 6, 5, 6])), + (fun(Capture1) -> expect:equal(Capture1, {error, 7}) - end(fun(Capture1) -> traverse(Capture1, Fun) end([6, 5, 7, 3])). + end)((fun(Capture1) -> traverse(Capture1, Fun) end)([4, 6, 5, 7, 3])). -endif. new() -> @@ -147,7 +147,7 @@ new() -> -ifdef(TEST). new_test() -> - fun(Capture1) -> expect:equal(Capture1, []) end(new()). + (fun(Capture1) -> expect:equal(Capture1, []) end)(new()). -endif. foldl(List, Acc, Fun) -> @@ -161,11 +161,11 @@ foldl(List, Acc, Fun) -> -ifdef(TEST). foldl_test() -> - fun(Capture1) -> + (fun(Capture1) -> expect:equal(Capture1, [3, 2, 1]) - end(fun(Capture1) -> - foldl(Capture1, [], fun(X, Acc) -> [X | Acc] end) - end([1, 2, 3])). + end)((fun(Capture1) -> + foldl(Capture1, [], fun(X, Acc) -> [X | Acc] end) + end)([1, 2, 3])). -endif. foldr(List, Acc, Fun) -> @@ -179,9 +179,9 @@ foldr(List, Acc, Fun) -> -ifdef(TEST). foldr_test() -> - fun(Capture1) -> + (fun(Capture1) -> expect:equal(Capture1, [1, 2, 3]) - end(fun(Capture1) -> - foldr(Capture1, [], fun(X, Acc) -> [X | Acc] end) - end([1, 2, 3])). + end)((fun(Capture1) -> + foldr(Capture1, [], fun(X, Acc) -> [X | Acc] end) + end)([1, 2, 3])). -endif. diff --git a/gen/map.erl b/gen/map.erl index b6327cd..db29fd0 100644 --- a/gen/map.erl +++ b/gen/map.erl @@ -19,8 +19,8 @@ from_list(A) -> from_list_test() -> Proplist = [{4, 0}, {1, 0}], Map = from_list(Proplist), - _ = fun(Capture1) -> expect:equal(Capture1, 2) end(size(Map)), - fun(Capture1) -> expect:equal(Capture1, Proplist) end(to_list(Map)). + _ = (fun(Capture1) -> expect:equal(Capture1, 2) end)(size(Map)), + (fun(Capture1) -> expect:equal(Capture1, Proplist) end)(to_list(Map)). -endif. fetch(A, B) -> @@ -30,12 +30,12 @@ fetch(A, B) -> fetch_test() -> Proplist = [{4, 0}, {1, 1}], Map = from_list(Proplist), - _ = fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, {ok, 0}) - end(fun(Capture1) -> fetch(Capture1, 4) end(Map)), - fun(Capture1) -> + end)((fun(Capture1) -> fetch(Capture1, 4) end)(Map)), + (fun(Capture1) -> expect:equal(Capture1, {ok, 1}) - end(fun(Capture1) -> fetch(Capture1, 1) end(Map)). + end)((fun(Capture1) -> fetch(Capture1, 1) end)(Map)). -endif. erl_map_values(A, B) -> @@ -46,11 +46,11 @@ map_values(Map, Fun) -> -ifdef(TEST). map_values_test() -> - fun(Capture1) -> + (fun(Capture1) -> expect:equal(Capture1, from_list([{1, 0}, {2, 3}, {3, 5}])) - end(fun(Capture1) -> - map_values(Capture1, fun(K, V) -> K + V end) - end(from_list([{1, 0}, {2, 1}, {3, 2}]))). + end)((fun(Capture1) -> + map_values(Capture1, fun(K, V) -> K + V end) + end)(from_list([{1, 0}, {2, 1}, {3, 2}]))). -endif. keys(A) -> @@ -58,9 +58,9 @@ keys(A) -> -ifdef(TEST). keys_test() -> - fun(Capture1) -> + (fun(Capture1) -> expect:equal(Capture1, [<<"a">>, <<"b">>, <<"c">>]) - end(keys(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]))). + end)(keys(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]))). -endif. values(A) -> @@ -68,9 +68,9 @@ values(A) -> -ifdef(TEST). values_test() -> - fun(Capture1) -> + (fun(Capture1) -> expect:equal(Capture1, [0, 1, 2]) - end(values(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]))). + end)(values(from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]))). -endif. erl_filter(A, B) -> diff --git a/gen/order.erl b/gen/order.erl index 10b5dd7..edf63a7 100644 --- a/gen/order.erl +++ b/gen/order.erl @@ -17,9 +17,9 @@ reverse(Order) -> -ifdef(TEST). reverse_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, gt) end(reverse(lt)), - _ = fun(Capture1) -> expect:equal(Capture1, eq) end(reverse(eq)), - fun(Capture1) -> expect:equal(Capture1, lt) end(reverse(gt)). + _ = (fun(Capture1) -> expect:equal(Capture1, gt) end)(reverse(lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, eq) end)(reverse(eq)), + (fun(Capture1) -> expect:equal(Capture1, lt) end)(reverse(gt)). -endif. to_int(Order) -> @@ -36,9 +36,9 @@ to_int(Order) -> -ifdef(TEST). to_int_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, -1) end(to_int(lt)), - _ = fun(Capture1) -> expect:equal(Capture1, 0) end(to_int(eq)), - fun(Capture1) -> expect:equal(Capture1, 1) end(to_int(gt)). + _ = (fun(Capture1) -> expect:equal(Capture1, -1) end)(to_int(lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, 0) end)(to_int(eq)), + (fun(Capture1) -> expect:equal(Capture1, 1) end)(to_int(gt)). -endif. compare(A, B) -> @@ -64,15 +64,15 @@ compare(A, B) -> -ifdef(TEST). compare_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, eq) end(compare(lt, lt)), - _ = fun(Capture1) -> expect:equal(Capture1, lt) end(compare(lt, eq)), - _ = fun(Capture1) -> expect:equal(Capture1, lt) end(compare(lt, gt)), - _ = fun(Capture1) -> expect:equal(Capture1, gt) end(compare(eq, lt)), - _ = fun(Capture1) -> expect:equal(Capture1, eq) end(compare(eq, eq)), - _ = fun(Capture1) -> expect:equal(Capture1, lt) end(compare(eq, gt)), - _ = fun(Capture1) -> expect:equal(Capture1, gt) end(compare(gt, lt)), - _ = fun(Capture1) -> expect:equal(Capture1, gt) end(compare(gt, eq)), - fun(Capture1) -> expect:equal(Capture1, eq) end(compare(gt, gt)). + _ = (fun(Capture1) -> expect:equal(Capture1, eq) end)(compare(lt, lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, lt) end)(compare(lt, eq)), + _ = (fun(Capture1) -> expect:equal(Capture1, lt) end)(compare(lt, gt)), + _ = (fun(Capture1) -> expect:equal(Capture1, gt) end)(compare(eq, lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, eq) end)(compare(eq, eq)), + _ = (fun(Capture1) -> expect:equal(Capture1, lt) end)(compare(eq, gt)), + _ = (fun(Capture1) -> expect:equal(Capture1, gt) end)(compare(gt, lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, gt) end)(compare(gt, eq)), + (fun(Capture1) -> expect:equal(Capture1, eq) end)(compare(gt, gt)). -endif. max(A, B) -> @@ -89,15 +89,15 @@ max(A, B) -> -ifdef(TEST). max_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, lt) end(max(lt, lt)), - _ = fun(Capture1) -> expect:equal(Capture1, eq) end(max(lt, eq)), - _ = fun(Capture1) -> expect:equal(Capture1, gt) end(max(lt, gt)), - _ = fun(Capture1) -> expect:equal(Capture1, eq) end(max(eq, lt)), - _ = fun(Capture1) -> expect:equal(Capture1, eq) end(max(eq, eq)), - _ = fun(Capture1) -> expect:equal(Capture1, gt) end(max(eq, gt)), - _ = fun(Capture1) -> expect:equal(Capture1, gt) end(max(gt, lt)), - _ = fun(Capture1) -> expect:equal(Capture1, gt) end(max(gt, eq)), - fun(Capture1) -> expect:equal(Capture1, gt) end(max(gt, gt)). + _ = (fun(Capture1) -> expect:equal(Capture1, lt) end)(max(lt, lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, eq) end)(max(lt, eq)), + _ = (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(lt, gt)), + _ = (fun(Capture1) -> expect:equal(Capture1, eq) end)(max(eq, lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, eq) end)(max(eq, eq)), + _ = (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(eq, gt)), + _ = (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(gt, lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(gt, eq)), + (fun(Capture1) -> expect:equal(Capture1, gt) end)(max(gt, gt)). -endif. min(A, B) -> @@ -114,13 +114,13 @@ min(A, B) -> -ifdef(TEST). min_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, lt) end(min(lt, lt)), - _ = fun(Capture1) -> expect:equal(Capture1, lt) end(min(lt, eq)), - _ = fun(Capture1) -> expect:equal(Capture1, lt) end(min(lt, gt)), - _ = fun(Capture1) -> expect:equal(Capture1, lt) end(min(eq, lt)), - _ = fun(Capture1) -> expect:equal(Capture1, eq) end(min(eq, eq)), - _ = fun(Capture1) -> expect:equal(Capture1, eq) end(min(eq, gt)), - _ = fun(Capture1) -> expect:equal(Capture1, lt) end(min(gt, lt)), - _ = fun(Capture1) -> expect:equal(Capture1, eq) end(min(gt, eq)), - fun(Capture1) -> expect:equal(Capture1, gt) end(min(gt, gt)). + _ = (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(lt, lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(lt, eq)), + _ = (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(lt, gt)), + _ = (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(eq, lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, eq) end)(min(eq, eq)), + _ = (fun(Capture1) -> expect:equal(Capture1, eq) end)(min(eq, gt)), + _ = (fun(Capture1) -> expect:equal(Capture1, lt) end)(min(gt, lt)), + _ = (fun(Capture1) -> expect:equal(Capture1, eq) end)(min(gt, eq)), + (fun(Capture1) -> expect:equal(Capture1, gt) end)(min(gt, gt)). -endif. diff --git a/gen/result.erl b/gen/result.erl index d3337e2..9bbf1e1 100644 --- a/gen/result.erl +++ b/gen/result.erl @@ -44,12 +44,12 @@ map(Result, Fun) -> -ifdef(TEST). map_test() -> - _ = fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, {ok, 2}) - end(fun(Capture1) -> map(Capture1, fun(X) -> X + 1 end) end({ok, 1})), - fun(Capture1) -> + end)((fun(Capture1) -> map(Capture1, fun(X) -> X + 1 end) end)({ok, 1})), + (fun(Capture1) -> expect:equal(Capture1, {error, 1}) - end(fun(Capture1) -> map(Capture1, fun(X) -> X + 1 end) end({error, 1})). + end)((fun(Capture1) -> map(Capture1, fun(X) -> X + 1 end) end)({error, 1})). -endif. map_error(Result, Fun) -> @@ -63,14 +63,16 @@ map_error(Result, Fun) -> -ifdef(TEST). map_error_test() -> - _ = fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, {ok, 1}) - end(fun(Capture1) -> map_error(Capture1, fun(X) -> X + 1 end) end({ok, 1})), - fun(Capture1) -> + end)((fun(Capture1) -> + map_error(Capture1, fun(X) -> X + 1 end) + end)({ok, 1})), + (fun(Capture1) -> expect:equal(Capture1, {error, 2}) - end(fun(Capture1) -> - map_error(Capture1, fun(X) -> X + 1 end) - end({error, 1})). + end)((fun(Capture1) -> + map_error(Capture1, fun(X) -> X + 1 end) + end)({error, 1})). -endif. flatten(Result) -> @@ -84,18 +86,18 @@ flatten(Result) -> -ifdef(TEST). flatten_test() -> - _ = fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, {ok, 1}) - end(flatten({ok, {ok, 1}})), - _ = fun(Capture1) -> + end)(flatten({ok, {ok, 1}})), + _ = (fun(Capture1) -> expect:equal(Capture1, {error, 1}) - end(flatten({ok, {error, 1}})), - _ = fun(Capture1) -> + end)(flatten({ok, {error, 1}})), + _ = (fun(Capture1) -> expect:equal(Capture1, {error, 1}) - end(flatten({error, 1})), - fun(Capture1) -> + end)(flatten({error, 1})), + (fun(Capture1) -> expect:equal(Capture1, {error, {error, 1}}) - end(flatten({error, {error, 1}})). + end)(flatten({error, {error, 1}})). -endif. flat_map(Result, Fun) -> @@ -115,21 +117,21 @@ flat_map(Result, Fun) -> -ifdef(TEST). flat_map_test() -> - _ = fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, {error, 1}) - end(fun(Capture1) -> - flat_map(Capture1, fun(X) -> {ok, X + 1} end) - end({error, 1})), - _ = fun(Capture1) -> + end)((fun(Capture1) -> + flat_map(Capture1, fun(X) -> {ok, X + 1} end) + end)({error, 1})), + _ = (fun(Capture1) -> expect:equal(Capture1, {ok, 2}) - end(fun(Capture1) -> - flat_map(Capture1, fun(X) -> {ok, X + 1} end) - end({ok, 1})), - fun(Capture1) -> + end)((fun(Capture1) -> + flat_map(Capture1, fun(X) -> {ok, X + 1} end) + end)({ok, 1})), + (fun(Capture1) -> expect:equal(Capture1, {error, 1}) - end(fun(Capture1) -> - flat_map(Capture1, fun(Unused) -> {error, 1} end) - end({ok, 1})). + end)((fun(Capture1) -> + flat_map(Capture1, fun(Unused) -> {error, 1} end) + end)({ok, 1})). -endif. unwrap(Result, Default) -> @@ -143,8 +145,8 @@ unwrap(Result, Default) -> -ifdef(TEST). unwrap_test() -> - _ = fun(Capture1) -> expect:equal(Capture1, 1) end(unwrap({ok, 1}, 50)), - fun(Capture1) -> + _ = (fun(Capture1) -> expect:equal(Capture1, 1) end)(unwrap({ok, 1}, 50)), + (fun(Capture1) -> expect:equal(Capture1, 50) - end(unwrap({error, <<"nope">>}, 50)). + end)(unwrap({error, <<"nope">>}, 50)). -endif. |