sources_parser_tests.erl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. -module(sources_parser_tests).
  2. -include_lib("eunit/include/eunit.hrl").
  3. all_sources_parser_test_() ->
  4. [{Title, [test_fun(Test) || Test <- Tests]}
  5. || {Title, Tests} <- test_defs()].
  6. test_fun({Name, Content, Output}) ->
  7. {Name, fun () ->
  8. Tokens = (catch sources_parser:process_content("dummy_path", Content)),
  9. ?assertMatch(Output, Tokens)
  10. end}.
  11. test_defs() ->
  12. [{"trans",
  13. [{"block with no trans",
  14. <<"<html>{% block main %} {% endblock %}</html>">>,
  15. []},
  16. {"block with trans",
  17. <<"<html>{% block main %} {% trans \"Hello\" %} {% endblock %}</html>">>,
  18. [{"Hello",{"dummy_path",1,33}}]},
  19. {"for with trans",
  20. <<"<html>{% block main %} {%for thing in things %}{% trans \"Hello inside a for\" %} {% endfor %} {% endblock %}</html>">>,
  21. [{"Hello inside a for",{"dummy_path",1,57}}]},
  22. {"if with trans",
  23. <<"<html>{% block content %}{% if thing %} {% trans \"Hello inside an if\" %} {% endif %} {% endblock %}</html>">>,
  24. [{"Hello inside an if",{"dummy_path",1,50}}]},
  25. {"if with trans inside a for",
  26. <<"<html>{% block content %}{%for thin in things %}{% if thing %} {% trans \"Hello inside an if inside a for\" %} {% endif %} {% endfor %}{% endblock %}</html>">>,
  27. [{"Hello inside an if inside a for",{"dummy_path",1,73}}]},
  28. {"if and else both with trans",
  29. <<"<html>{% block content %}{% if thing %} {% trans \"Hello inside an if\" %} {% else %} {% trans \"Hello inside an else\" %} {% endif %} {% endblock %}</html>">>,
  30. [ {"Hello inside an else",{"dummy_path",1,94}}, {"Hello inside an if",{"dummy_path",1,50}}]}
  31. ]}
  32. ].