<div dir="ltr">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. <div><br><div>regards,</div><div>Vlad</div><div>
<br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 1, 2014 at 4:50 PM, Max Lapshin <span dir="ltr"><<a href="mailto:max.lapshin@gmail.com" target="_blank">max.lapshin@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi.<div><br></div><div>I want to write a test for a function that returns list of some tuples:</div><div>
<br></div><div>my_logic:handle_event(Event, State1) -> {ok, Requests, State2}</div><div><br></div><div>
<br></div><div><br></div><div>My idea is to write such test helper:</div><div><br></div><div>step(Event, RequiredRequests) -></div><div> State1 = get(remembered_state),</div><div> {ok, Requests, State2} = my_logic:handle_event(Event, State1),</div>
<div> put(remembered_state, State2),</div><div> true = lists:all(fun(Match) -></div><div> case lists:any(fun(Request) -></div><div> case Request of</div><div> Match -> true;</div><div>
_ -> false</div><div> end</div><div> end, Requests), RequiredRequests),</div><div> ok.</div><div><br></div><div>and use this function like:</div><div><br></div><div>step(playlist_ready, [{set_timer, download_playlist, _}]) %% This test should check if new timer is set with some not very important time</div>
<div><br></div><div>Problem here is that I cannot pass a match into function "step".</div><div><br></div><div><br></div><div>I have two ideas:</div><div><br></div><div>1) wrap each match into macros:</div><div>
<br></div><div>-define(P(Match), fun(Request) -> case Request of Match -> true; _ -> false end end).</div><div><br></div><div>and use it like:</div><div><br></div><div>step(playlist_ready, [?P({set_timer, download_playlist, _})])<br>
</div><div><br></div><div><br></div><div>2) make a macro:</div><div><br></div><div>-define(step(Event, RequiredRequests), step(Event, ??RequiredRequests)).</div><div><br></div><div>Now it will be:</div><div><br></div><div>
?step(playlist_ready, [{set_timer, download_playlist, _}])</div><div><br></div><div>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.</div>
<div><br></div><div><br></div><div><br></div><div><br></div><div>Should I don't try to make new problems and just use first option?</div><div>Or there is some possibility to scan/parse/eval string with matches in runtime?</div>
<div><br></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>