[erlang-questions] How to use erl_parse, erl_scan, erl_eval?
Vlad Dumitrescu
vladdu55@REDACTED
Tue Apr 1 16:53:05 CEST 2014
You could also use a special value instead of _, for example '_'. Of
course, in this case you must match the patterns by hand, but it's not
difficult.
regards,
Vlad
On Tue, Apr 1, 2014 at 4:50 PM, Max Lapshin <max.lapshin@REDACTED> wrote:
> Hi.
>
> I want to write a test for a function that returns list of some tuples:
>
> my_logic:handle_event(Event, State1) -> {ok, Requests, State2}
>
>
>
> My idea is to write such test helper:
>
> step(Event, RequiredRequests) ->
> State1 = get(remembered_state),
> {ok, Requests, State2} = my_logic:handle_event(Event, State1),
> put(remembered_state, State2),
> true = lists:all(fun(Match) ->
> case lists:any(fun(Request) ->
> case Request of
> Match -> true;
> _ -> false
> end
> end, Requests), RequiredRequests),
> ok.
>
> and use this function like:
>
> step(playlist_ready, [{set_timer, download_playlist, _}]) %% This test
> should check if new timer is set with some not very important time
>
> Problem here is that I cannot pass a match into function "step".
>
>
> I have two ideas:
>
> 1) wrap each match into macros:
>
> -define(P(Match), fun(Request) -> case Request of Match -> true; _ ->
> false end end).
>
> and use it like:
>
> step(playlist_ready, [?P({set_timer, download_playlist, _})])
>
>
> 2) make a macro:
>
> -define(step(Event, RequiredRequests), step(Event, ??RequiredRequests)).
>
> Now it will be:
>
> ?step(playlist_ready, [{set_timer, download_playlist, _}])
>
> but I cannot find any guide how to use those erl_parse, erl_scan,
> erl_eval to split string "[{set_timer, download_playlist, _}]" into some
> tokens and create a list of matches from it.
>
>
>
>
> Should I don't try to make new problems and just use first option?
> Or there is some possibility to scan/parse/eval string with matches in
> runtime?
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140401/5bd4fe03/attachment.htm>
More information about the erlang-questions
mailing list