Skip to content

Commit

Permalink
Move tests to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
pusewicz committed Aug 11, 2012
1 parent 3b00210 commit 6fa88e7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/mustache.erl
Expand Up @@ -31,10 +31,6 @@
section_re = undefined,
tag_re = undefined}).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.

compile(Body) when is_list(Body) ->
State = #mstate{},
CompiledTemplate = pre_compile(Body, State),
Expand Down Expand Up @@ -218,17 +214,3 @@ escape([X | Rest], Acc) ->
start([T]) ->
Out = render(list_to_atom(T)),
io:format(Out ++ "~n", []).

-ifdef(TEST).

simple_test() ->
Ctx = dict:from_list([{name, "world"}]),
Result = render("Hello {{name}}!", Ctx),
?assertEqual("Hello world!", Result).

integer_values_too_test() ->
Ctx = dict:from_list([{name, "Chris"}, {value, 10000}]),
Result = render("Hello {{name}}~nYou have just won ${{value}}!", Ctx),
?assertEqual("Hello Chris~nYou have just won $10000!", Result).

-endif.
40 changes: 40 additions & 0 deletions test/mustache_tests.erl
@@ -0,0 +1,40 @@
%% The MIT License
%%
%% Copyright (c) 2009 Tom Preston-Werner <tom@mojombo.com>
%%
%% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal
%% in the Software without restriction, including without limitation the rights
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%% copies of the Software, and to permit persons to whom the Software is
%% furnished to do so, subject to the following conditions:
%%
%% The above copyright notice and this permission notice shall be included in
%% all copies or substantial portions of the Software.
%%
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
%% THE SOFTWARE.

%% See the README at http://github.com/mojombo/mustache.erl for additional
%% documentation and usage examples.

-module(mustache_tests).

-compile(export_all).

-include_lib("eunit/include/eunit.hrl").

simple_test() ->
Ctx = dict:from_list([{name, "world"}]),
Result = mustache:render("Hello {{name}}!", Ctx),
?assertEqual("Hello world!", Result).

integer_values_too_test() ->
Ctx = dict:from_list([{name, "Chris"}, {value, 10000}]),
Result = mustache:render("Hello {{name}}~nYou have just won ${{value}}!", Ctx),
?assertEqual("Hello Chris~nYou have just won $10000!", Result).

0 comments on commit 6fa88e7

Please sign in to comment.