Browse Source

ft: 添加三目运算宏变体

master
SisMaker 2 years ago
parent
commit
6ab43aac3a
2 changed files with 72 additions and 1 deletions
  1. +1
    -1
      include/utComMisc.hrl
  2. +71
    -0
      src/testCase/funTest.erl

+ 1
- 1
include/utComMisc.hrl View File

@ -1,10 +1,10 @@
%%
-define(IIF(Cond, Then, That), case Cond of true -> Then; _ -> That end).
-define(IIF(Expr, Expect, Then, ExprRet, That), case Expr of Expect -> Then; ExprRet -> That end).
%% IF-DO表达式
-define(IF(IFTure, DoThat), (IFTure) andalso (DoThat)).
%%unicode编码范围 0x4e00 - 0x9fa5
-define(UNICODE_CHINESE_BEGIN, (4 * 16 * 16 * 16 + 14 * 16 * 16)).
-define(UNICODE_CHINESE_END, (9 * 16 * 16 * 16 + 15 * 16 * 16 + 10 * 16 + 5)).

+ 71
- 0
src/testCase/funTest.erl View File

@ -0,0 +1,71 @@
-module(funTest).
-include("utComMisc.hrl").
-compile([export_all, nowarn_function, nowarn_unused_vars, nowarn_export_all]).
test2(A) ->
Fun1 = fun(A1, A2, A3, A4, A5, Fun1) ->
if A1 > 100 ->
A1 + A2;
true ->
Fun1(A1, A2, A3, A4, A5, A2) end
end,
Fun1(A, A, A, A, A, Fun1).
test3(A) ->
[O * 2 || O <- A],
ok.
-define(types, [1, 1.1, [], [1], {1}, #{}, <<"123">>, self()]).
type1() ->
[dataType(One) || One <- ?types],
ok.
dataType(Data) when is_list(Data) -> list_do;
dataType(Data) when is_integer(Data) -> integer_do;
dataType(Data) when is_binary(Data) -> binary_do;
dataType(Data) when is_function(Data) -> function_do;
dataType(Data) when is_tuple(Data) -> tuple_do;
dataType(Data) when is_atom(Data) -> atom_do;
dataType(Data) when is_float(Data) -> float_do;
dataType(Data) when is_number(Data) -> number_do;
dataType(Data) when is_pid(Data) -> pid_do;
dataType(Data) when is_port(Data) -> port_do;
dataType(_Data) -> not_know_do.
type2() ->
[erts_internal:term_type(One) || One <- ?types],
ok.
dataType(nil, Data) when is_list(Data) -> list_do;
dataType(list, Data) when is_list(Data) -> list_do;
dataType(fixnum, Data) when is_integer(Data) -> integer_do;
dataType(bignum, Data) when is_integer(Data) -> integer_do;
dataType(refc_binary, Data) when is_binary(Data) -> binary_do;
dataType(heap_binary, Data) when is_binary(Data) -> binary_do;
dataType(sub_binary, Data) when is_binary(Data) -> binary_do;
dataType(tuple, Data) when is_tuple(Data) -> tuple_do;
dataType(atom, Data) when is_atom(Data) -> atom_do;
dataType(hfloat, Data) when is_float(Data) -> float_do;
dataType(pid, Data) when is_pid(Data) -> pid_do;
dataType(pid, Data) when is_pid(Data) -> pid_do;
dataType(external_pid, Data) when is_port(Data) -> port_do;
dataType(_, _Data) -> not_know_do.
type3() ->
[dataType(eTermType:termType(One), One) || One <- ?types],
ok.
ok(0) ->
ok;
ok(N) ->
ok(N - 1).
test(A) ->
?IIF(lists:keyfind(a, 1, A), false, none, {_, V}, V).

Loading…
Cancel
Save