1 %% The contents of this file are subject to the Mozilla Public License
2 %% Version 1.1 (the "License"); you may not use this file except in
3 %% compliance with the License. You may obtain a copy of the License
4 %% at http://www.mozilla.org/MPL/
6 %% Software distributed under the License is distributed on an "AS IS"
7 %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8 %% the License for the specific language governing rights and
9 %% limitations under the License.
11 %% The Original Code is Erlando.
13 %% The Initial Developer of the Original Code is VMware, Inc.
14 %% Copyright (c) 2011-2011 VMware, Inc. All rights reserved.
18 -compile({parse_transform, cut}).
19 -compile({parse_transform, do}).
23 -record(r, { f1 = false,
28 F0 = foo(a, b, _, 5+6, _),
32 3 = F2(fun erlang:'+'/2),
33 -1 = F2(fun erlang:'-'/2),
34 F3 = _:foo(a, b, c, _, e),
36 F4 = _:_(_), %% this isn't getting silly at all...
37 true = 3 == F4(math, sqrt, 9).
39 foo(a, b, c, 11, e) -> ok.
42 F = f1(1, f2(1 + _), _),
44 %% F = \X -> f1(1, f2(\Y -> 1 + Y), X)
47 f1(N, M, L) when N + M =:= L -> ok.
54 test_cut_unary_op() ->
59 {foo, _} = {foo, F} = {foo, {bar, _}},
63 true = #r{} =/= #r{f3 = _},
64 orange = ((#r{f3 = _})(orange))#r.f3,
65 {r, foo, bar, baz} = (#r{f1 = _, f3 = _, f2 = _})(foo, baz, bar),
67 F = R#r{f3 = _, f2 = _},
68 wobble = (F(orange, wobble))#r.f2,
71 Setter = _#r{f2 = gerbil},
72 gerbil = Getter(Setter(R)),
73 Setter2 = _#r{f2 = _},
74 hamster = Getter(Setter2(R, hamster)).
76 test_cut_record_nested() ->
77 F = #r{f1 = #r{f1 = _, f3 = _}, f2 = _},
80 #r{f1 = orange, f3 = banana} = F1(orange, banana).
83 <<"AbA", _/binary>> = (<<65, _, 65>>)($b),
87 <<1:1/unsigned, 1:1/unsigned, 1:1/unsigned, 1:1/unsigned>> = G(4).
95 H = [1, _, _, [_], 5 | [6, [_] | [_]]],
96 %% This is the same as:
97 %% [1, _, _, [_], 5, 6, [_], _]
99 %% \A, B, C -> [1, A, B, \D -> [D], 5, 6, \E -> [E], C]
100 [1, 2, 3, H1, 5, 6, H2, 8] = H(2, 3, 8),
110 N when is_integer(N) andalso 0 =:= (N rem 2) ->
112 N when is_integer(N) ->
119 not_a_number = F(my_atom).
121 test_cut_comprehensions() ->
122 F = << <<(1 + (X*2))>> || _ <- _, X <- _ >>, %% Note, this'll only be a /2 !
123 <<"AAA">> = F([a,b,c], [32]),
124 F1 = [ {X, Y, Z} || X <- _, Y <- _, Z <- _,
125 math:pow(X,2) + math:pow(Y,2) == math:pow(Z,2) ],
126 [{3,4,5}, {4,3,5}, {6,8,10}, {8,6,10}] =
127 lists:usort(F1(lists:seq(1,10), lists:seq(1,10), lists:seq(1,10))).
130 test:test([{?MODULE, [test_cut,
136 test_cut_record_nested,
140 test_cut_comprehensions]}],
141 [report, {name, ?MODULE}]).