File: ec_plists_tests.erl

package info (click to toggle)
erlang-erlware-commons 1.3.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 400 kB
  • sloc: erlang: 4,338; makefile: 7
file content (84 lines) | stat: -rw-r--r-- 2,854 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
%%% @copyright Erlware, LLC.
-module(ec_plists_tests).

-include_lib("eunit/include/eunit.hrl").

%%%===================================================================
%%% Tests
%%%===================================================================

map_good_test() ->
    Results = ec_plists:map(fun(_) ->
                                    ok
                            end,
                            lists:seq(1, 5)),
    ?assertMatch([ok, ok, ok, ok, ok],
                 Results).

ftmap_good_test() ->
    Results = ec_plists:ftmap(fun(_) ->
                                      ok
                              end,
                              lists:seq(1, 3)),
    ?assertMatch([{value, ok}, {value, ok}, {value, ok}],
                 Results).

filter_good_test() ->
    Results = ec_plists:filter(fun(X) ->
                                       X == show
                               end,
                               [show, show, remove]),
    ?assertMatch([show, show],
                 Results).

map_timeout_test() ->
    ?assertExit(timeout,
                ec_plists:map(fun(T) ->
                                      timer:sleep(T),
                                      T
                              end,
                              [1, 100], {timeout, 10})).

ftmap_timeout_test() ->
    ?assertExit(timeout,
                ec_plists:ftmap(fun(X) ->
                                        timer:sleep(X),
                                        true
                                end,
                                [100, 1], {timeout, 10})).

filter_timeout_test() ->
    ?assertExit(timeout,
                 ec_plists:filter(fun(T) ->
                                          timer:sleep(T),
                                          T == 1
                                  end,
                                  [1, 100], {timeout, 10})).

map_bad_test() ->
    ?assertExit({{nocatch,test_exception}, _},
                 ec_plists:map(fun(_) ->
                                    erlang:throw(test_exception)
                            end,
                            lists:seq(1, 5))).


ftmap_bad_test() ->
    Results =
        ec_plists:ftmap(fun(2) ->
                                erlang:throw(test_exception);
                           (N) ->
                                N
                        end,
                        lists:seq(1, 5)),
    ?assertMatch([{value, 1}, {error,{throw,test_exception}}, {value, 3},
                  {value, 4}, {value, 5}] , Results).

external_down_message_test() ->
    erlang:spawn_monitor(fun() -> erlang:throw(fail) end),
    Results = ec_plists:map(fun(_) ->
                                    ok
                            end,
                            lists:seq(1, 5)),
    ?assertMatch([ok, ok, ok, ok, ok],
                 Results).