Skip to content
This repository
tree: 2f8504aaf9
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 41 lines (30 sloc) 2.081 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
-module(sources_parser_unittests).

-export([run_tests/0]).

tests() ->
    [
{"trans", [
                    {"block with no trans", <<"<html>{% block main %} {% endblock %}</html>">>, []},

                    {"block with trans", <<"<html>{% block main %} {% trans \"Hello\" %} {% endblock %}</html>">>, [{"Hello",{"dummy_path",1,33}}]},

                    {"for with trans", <<"<html>{% block main %} {%for thing in things %}{% trans \"Hello inside a for\" %} {% endfor %} {% endblock %}</html>">>, [{"Hello inside a for",{"dummy_path",1,57}}]},

{"if with trans", <<"<html>{% block content %}{% if thing %} {% trans \"Hello inside an if\" %} {% endif %} {% endblock %}</html>">>, [{"Hello inside an if",{"dummy_path",1,50}}]},

{"if with trans inside a for", <<"<html>{% block content %}{%for thin in things %}{% if thing %} {% trans \"Hello inside an if inside a for\" %} {% endif %} {% endfor %}{% endblock %}</html>">>, [{"Hello inside an if inside a for",{"dummy_path",1,73}}]},

{"if and else both with trans", <<"<html>{% block content %}{% if thing %} {% trans \"Hello inside an if\" %} {% else %} {% trans \"Hello inside an else\" %} {% endif %} {% endblock %}</html>">>, [ {"Hello inside an else",{"dummy_path",1,94}}, {"Hello inside an if",{"dummy_path",1,50}}]}
]}
    ].

run_tests() ->
    io:format("Running unit tests...~n"),
    Failures = lists:foldl(
        fun({Group, Assertions}, GroupAcc) ->
                io:format(" Test group ~p...~n", [Group]),
                lists:foldl(fun({Name, Content, Output}, Acc) ->
process_unit_test(Content, Output, Acc, Group, Name)
                            end, GroupAcc, Assertions)
        end, [], tests()),
    
    io:format("Unit test failures: ~p~n", [Failures]).

process_unit_test(Content, Output,Acc, Group, Name) ->
Tokens = sources_parser:process_content("dummy_path", Content),
%%io:format("Tokens are: ~p~n", [Tokens]),
case Tokens of
Output -> Acc;
_ -> [{Group, Name, 'binary', {expected, Output}, {found, Tokens} } | Acc]
end.
Something went wrong with that request. Please try again.