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
|
%% -*- Mode: erlang; indent-tabs-mode: nil -*-
%% Copyright Ericsson AB 2017. All Rights Reserved.
%%% indentation of if case receive statements
%%% 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
indent_if(1, Z) ->
%% If
if Z >= 0 ->
X = 43 div Z,
X;
Z =< 10 ->
X = 43 div Z,
X;
Z == 5 orelse
Z == 7 ->
X = 43 div Z,
X;
is_number(Z),
Z < 32 ->
Z;
is_number(Z);
Z < 32 ->
Z * 32;
true ->
if_works
end;
indent_if(2, Z) ->
%% If
if
Z >= 0 ->
X = 43 div Z,
X
; Z =< 10 ->
43 div Z
; Z == 5 orelse
Z == 7 ->
X = 43 div Z,
X
; is_number(Z),
Z < 32 ->
Z
; true ->
if_works
end.
indent_case(1, Z) ->
%% Case
case {Z, foo, bar} of
{Z,_,_} ->
X = 43 div 4,
foo(X);
{Z,_,_} when
Z =:= 42 -> % line should be indented as a when
X = 43 div 4,
foo(X);
{Z,_,_}
when Z < 10 orelse
Z =:= foo -> % Binary op alignment here !!!
X = 43 div 4,
Bool = Z < 5 orelse % Binary op args align differently after when
Z =:= foo, % and elsewhere ???
foo(X);
{Z,_,_}
when % when should be indented
Z < 10 % and the guards should follow when
andalso % unsure about how though
true ->
X = 43 div 4,
foo(X)
end;
indent_case(2, Z) ->
%% Case
case {Z, foo, bar} of
{Z,_,_} ->
X = 43 div 4,
foo(X)
; {Z,_,_} when
Z =:= 42 -> % line should be indented as a when
X = 43 div 4,
foo(X)
; {Z,_,_}
when Z < 10 -> % when should be indented
X = 43 div 4,
foo(X)
; {Z,_,_}
when % when should be indented
Z < 10 % and the guards should follow when
andalso % unsure about how though
true ->
X = 43 div 4,
foo(X)
end.
indent_begin(Z) ->
%% Begin
begin
sune,
Z = 74234 +
foo(8456) +
345 div 43,
Foo = begin
ok,
foo(234),
begin
io:format("Down here\n")
end
end,
{Foo,
bar}
end.
indent_receive(1) ->
%% receive
receive
{Z,_,_} ->
X = 43 div 4,
foo(X)
; Z ->
X = 43 div 4,
foo(X)
end,
ok;
indent_receive(2) ->
receive
{Z,_,_} ->
X = 43 div 4,
foo(X);
Z % added clause
when Z =:= 1 -> % This line should be indented by 2
X = 43 div 4,
foo(X);
Z when % added clause
Z =:= 2 -> % This line should be indented by 2
X = 43 div 4,
foo(X);
Z ->
X = 43 div 4,
foo(X)
after infinity ->
foo(X),
asd(X),
5*43
end,
ok;
indent_receive() ->
receive
after 10 ->
foo(X),
asd(X),
5*43
end,
ok.
|