aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2018-03-20 10:42:18 +0100
committerGitHub <[email protected]>2018-03-20 10:42:18 +0100
commit269814984a005f23fd1b5305c99cd92b68fd1641 (patch)
tree466154699c1150650b11e2e1c90e775dd9e1e86a /lib/stdlib/test
parent01460976cfa3222f618ac494f462eccd0ba9a1c8 (diff)
parent5c7209c2874849a5a7339e23fdbd9aed1bb935b2 (diff)
downloadotp-269814984a005f23fd1b5305c99cd92b68fd1641.tar.gz
otp-269814984a005f23fd1b5305c99cd92b68fd1641.tar.bz2
otp-269814984a005f23fd1b5305c99cd92b68fd1641.zip
Merge pull request #1744 from uabboli/hasse/stdlib/lists_search/OTP-14675
stdlib: Add function lists:search/2
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r--lib/stdlib/test/lists_SUITE.erl20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/stdlib/test/lists_SUITE.erl b/lib/stdlib/test/lists_SUITE.erl
index 7c99244b36..837ab4e97e 100644
--- a/lib/stdlib/test/lists_SUITE.erl
+++ b/lib/stdlib/test/lists_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2017. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@
filter_partition/1,
join/1,
otp_5939/1, otp_6023/1, otp_6606/1, otp_7230/1,
- suffix/1, subtract/1, droplast/1, hof/1]).
+ suffix/1, subtract/1, droplast/1, search/1, hof/1]).
%% Sort randomized lists until stopped.
%%
@@ -121,7 +121,7 @@ groups() ->
{zip, [parallel], [zip_unzip, zip_unzip3, zipwith, zipwith3]},
{misc, [parallel], [reverse, member, dropwhile, takewhile,
filter_partition, suffix, subtract, join,
- hof, droplast]}
+ hof, droplast, search]}
].
init_per_suite(Config) ->
@@ -2615,6 +2615,20 @@ droplast(Config) when is_list(Config) ->
ok.
+%% Test lists:search/2
+search(Config) when is_list(Config) ->
+ F = fun(I) -> I rem 2 =:= 0 end,
+ F2 = fun(A, B) -> A > B end,
+
+ {value, 2} = lists:search(F, [1,2,3,4]),
+ false = lists:search(F, [1,3,5,7]),
+ false = lists:search(F, []),
+
+ %% Error cases.
+ {'EXIT',{function_clause,_}} = (catch lists:search(badfun, [])),
+ {'EXIT',{function_clause,_}} = (catch lists:search(F2, [])),
+ ok.
+
%% Briefly test the common high-order functions to ensure they
%% are covered.
hof(Config) when is_list(Config) ->