[erlang-questions] How to use erl_parse, erl_scan, erl_eval?
Andreas Stenius
erlang@REDACTED
Wed Apr 2 09:34:48 CEST 2014
I haven't looked long enough on your problem statement to fully grasp what
you are trying to do, but from the feel of it, merl [1] may be a fit..
//Andreas
[1] https://github.com/richcarl/merl
2014-04-01 16:50 GMT+02:00 Max Lapshin <max.lapshin@REDACTED>:
> 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/20140402/7a418cff/attachment.htm>
More information about the erlang-questions
mailing list