aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tools/test/emacs_SUITE_data/funcs
blob: 877f9820051faa734c2d1015df9b9200b5ba8dd9 (plain) (blame)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
%% -*- Mode: erlang; indent-tabs-mode: nil -*-
%% Copyright Ericsson AB 2017. All Rights Reserved.

%%% Function (and funs) indentation

%%% Not everything in these test are set in stone
%%% better indentation rules can be added but by having
%%% these tests we can see what changes in new implementations
%%% and notice when doing unintentional changes

-export([
         func1/0,
         func2/0,
         a_function_with_a_very_very_long_name/0,
         when1/2
        ]).

-compile([nowarn_unused_functions,
          {inline, [
                    func2/2,
                    func3/2
                   ]
          }
         ]).

func1() ->
    basic.

func2(A1,
      A2) ->
    ok.

func3(
  A1,
  A2
 ) ->
    ok.

%% Okeefe style
func4(A1
     ,A2
     ,A3
     ) ->
    ok.

func5(
  A41
 ,A42) ->
    ok.

a_function_with_a_very_very_long_name() ->
    A00 = #record{
             field1=1,
             field2=1
            },
    A00.

when1(W1, W2)
  when is_number(W1),
       is_number(W2) ->
    ok.

when2(W1,W2,W3) when
      W1 > W2,
      W2 > W3 ->
    ok.

when3(W1,W2,W3) when
      W1 > W2,
      W2 > W3
      ->
    ok.

when4(W1,W2,W3)
  when
      W1 > W2,
      W2 > W3 ->
    ok.

match1({[H|T],
        Other},
       M1A2) ->
    ok.

match2(
  {
   [H|T],
   Other
  },
  M2A2
 ) ->
    ok.

match3({
        M3A1,
        [
         H |
         T
        ],
        Other
       },
       M3A2
      ) ->
    ok.

match4(<<
         M4A:8,
         M4B:16/unsigned-integer,
         _/binary
       >>,
       M4C) ->
    ok.

match5(M5A,
       #record{
          b=M5B,
          c=M5C
         }
      ) ->
    ok.

match6(M6A,
       #{key6a := a6,
         key6b := b6
        }) ->
    ok.

funs(1)
  when
      X ->
    %% Changed fun to one indention level
    %% 'when' and several clause forces a depth of '4'
    Var = spawn(fun(X, _)
                      when X == 2;
                           X > 10 ->
                        hello,
                        case Hello() of
                            true when is_atom(X) ->
                                foo;
                            false ->
                                bar
                        end;
                   (Foo) when is_atom(Foo),
                              is_integer(X) ->
                        X = 6 * 45,
                        Y = true andalso
                            kalle
                end),
    Var;
funs(2) ->
    %% check EEP37 named funs
    Fn1 = fun
              Factory(N) when
                    N > 0 ->
                  F = Fact(N-1),
                  N * F;
              Factory(0) ->
                  1
          end,
    Fn1;
funs(3) ->
    %% check anonymous funs too
    Fn2 = fun(0) ->
                  1;
             (N) ->
                  N
          end,
    ok;
funs(4) ->
    X = lists:foldr(fun(M) ->
                            <<M/binary, " ">>
                    end, [], Z),
    A = <<X/binary, 0:8>>,
    A.