Permalink
Browse files

added new testsuite

  • Loading branch information...
1 parent e13d250 commit 8406c54f0e01fc1f3ec42dd39a1c21446831b782 @rsaccon rsaccon committed Feb 11, 2008
Showing with 1,082 additions and 11 deletions.
  1. +3 −2 Emakefile
  2. +14 −7 src/erlydtl/erlydtl.erl
  3. +11 −2 src/erlydtl/erlydtl_compiler.erl
  4. +169 −0 src/tests/erlydtl_tests.erl
  5. +166 −0 src/tests/erlydtl_testsuite.erl
  6. +8 −0 tests/out/test_autoescape
  7. +15 −0 tests/out/test_comment
  8. +26 −0 tests/out/test_custom_call
  9. +33 −0 tests/out/test_custom_tag
  10. +11 −0 tests/out/test_extends
  11. +42 −0 tests/out/test_filters
  12. +13 −0 tests/out/test_for
  13. +7 −0 tests/out/test_for_list
  14. +7 −0 tests/out/test_for_list_preset
  15. +13 −0 tests/out/test_for_preset
  16. +13 −0 tests/out/test_for_records
  17. +23 −0 tests/out/test_for_records_preset
  18. +7 −0 tests/out/test_for_tuple
  19. +4 −0 tests/out/test_if
  20. +4 −0 tests/out/test_if_preset
  21. +28 −0 tests/out/test_ifequal
  22. +28 −0 tests/out/test_ifequal_preset
  23. +28 −0 tests/out/test_ifnotequal
  24. +28 −0 tests/out/test_ifnotequal_preset
  25. +2 −0 tests/out/test_include
  26. +5 −0 tests/out/test_var
  27. +9 −0 tests/out/test_var_preset
  28. +11 −0 tests/templates/base
  29. +1 −0 tests/templates/include
  30. +8 −0 tests/templates/test_autoescape
  31. +17 −0 tests/templates/test_comment
  32. +7 −0 tests/templates/test_custom_call
  33. +13 −0 tests/templates/test_custom_tag
  34. +12 −0 tests/templates/test_custom_tag_error
  35. +3 −0 tests/templates/test_extends
  36. +42 −0 tests/templates/test_filters
  37. +9 −0 tests/templates/test_for
  38. +3 −0 tests/templates/test_for_list
  39. +3 −0 tests/templates/test_for_list_preset
  40. +9 −0 tests/templates/test_for_preset
  41. +9 −0 tests/templates/test_for_records
  42. +15 −0 tests/templates/test_for_records_preset
  43. +3 −0 tests/templates/test_for_tuple
  44. +4 −0 tests/templates/test_if
  45. +4 −0 tests/templates/test_if_preset
  46. +43 −0 tests/templates/test_ifequal
  47. +43 −0 tests/templates/test_ifequal_preset
  48. +43 −0 tests/templates/test_ifnotequal
  49. +43 −0 tests/templates/test_ifnotequal_preset
  50. +1 −0 tests/templates/test_include
  51. +5 −0 tests/templates/test_var
  52. +5 −0 tests/templates/test_var_error
  53. +9 −0 tests/templates/test_var_preset
View
@@ -1,2 +1,3 @@
-{"src/erlydtl/*", [debug_info, {d, debug}, {outdir, "ebin"}]}.
-{"src/demo/*", [debug_info, {d, debug}, {outdir, "ebin"}]}.
+{"src/erlydtl/*", [debug_info, {outdir, "ebin"}]}.
+{"src/tests/*", [debug_info, {outdir, "ebin"}]}.
+{"src/demo/*", [debug_info, {outdir, "ebin"}]}.
@@ -37,27 +37,34 @@
-author('emmiller@gmail.com').
%% API
--export([create_parser/0]).
+-export([create_parser/0, parser_src/0]).
%% --------------------------------------------------------------------
%% Definitions
%% --------------------------------------------------------------------
--ifdef(debug).
-define(PRINT_ERR_WARNS, [report_warnings, report_errors]).
--else.
--define(PRINT_ERR_WARNS, []).
--endif.
%%--------------------------------------------------------------------
-%% @spec () -> any()
+%% @spec () -> Ok::atom() | Err::tuple()
%% @doc creates the yecc-based ErlyDTL parser
%% @end
%%--------------------------------------------------------------------
create_parser() ->
create_parser("src/erlydtl/erlydtl_parser", "ebin").
-
+
+%%--------------------------------------------------------------------
+%% @spec () -> string()
+%% @doc creates the yecc-based ErlyDTL parser
+%% @end
+%%--------------------------------------------------------------------
+parser_src() ->
+ {file, Ebin} = code:is_loaded(?MODULE),
+ filename:join([filename:dirname(filename:dirname(Ebin)),
+ "src", "erlydtl", "erlydtl_parser.yrl"]).
+
+
%%====================================================================
%% Internal functions
%%====================================================================
@@ -35,6 +35,11 @@
-author('rsaccon@gmail.com').
-author('emmiller@gmail.com').
+%% --------------------------------------------------------------------
+%% Definitions
+%% --------------------------------------------------------------------
+-define(COMPILE_OPTIONS, [verbose, report_errors, report_warnings]).
+
-export([compile/2, compile/3]).
-record(dtl_context, {
@@ -70,8 +75,12 @@ compile(File, Module, Options) ->
ok;
{ok, DjangoParseTree, CheckSum} ->
try body_ast(DjangoParseTree, Context, #treewalker{}) of
- {{Ast, Info}, _} ->
- case compile:forms(forms(File, Module, Ast, Info, CheckSum), []) of
+ {{Ast, Info}, _} ->
+ CompileOptions = case proplists:get_value(verbose, Options, false) of
+ true -> ?COMPILE_OPTIONS;
+ _ -> []
+ end,
+ case compile:forms(forms(File, Module, Ast, Info, CheckSum), CompileOptions) of
{ok, Module1, Bin} ->
OutDir = proplists:get_value(out_dir, Options, "ebin"),
BeamFile = filename:join([OutDir, atom_to_list(Module1) ++ ".beam"]),
@@ -0,0 +1,169 @@
+%%%-------------------------------------------------------------------
+%%% File: erlydtl_tests.erl
+%%% @author Roberto Saccon <rsaccon@gmail.com> [http://rsaccon.com]
+%%% @author Evan Miller <emmiller@gmail.com>
+%%% @copyright 2008 Roberto Saccon, Evan Miller
+%%% @doc ErlyDTS test suite
+%%% @end
+%%%
+%%% The MIT License
+%%%
+%%% Copyright (c) 2007 Roberto Saccon
+%%%
+%%% 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.
+%%%
+%%% @since 2008-02-11 by Roberto Saccon
+%%%-------------------------------------------------------------------
+-module(erlydtl_tests).
+-author('rsaccon@gmail.com').
+-author('emmiller@gmail.com').
+
+
+%% API
+-export([setup/1]).
+
+%%====================================================================
+%% API
+%%====================================================================
+%%--------------------------------------------------------------------
+%% @spec (Name::string()) -> {CompileStatus::atom(), PresetVars::List, RenderStatus::atom(), RenderVars::List}
+%% @doc
+%% @end
+%%--------------------------------------------------------------------
+setup("autoescape") ->
+ CompileVars = [],
+ RenderVars = [{var1, "<b>bold</b>"}],
+ {ok, CompileVars, ok, RenderVars};
+setup("comment") ->
+ CompileVars = [],
+ RenderVars =[],
+ {ok, CompileVars, ok, RenderVars};
+setup("extends") ->
+ CompileVars = [],
+ RenderVars = [{base_var, "base-barstring"}, {test_var, "test-barstring"}],
+ {ok, CompileVars, ok, RenderVars};
+setup("filters") ->
+ CompileVars = [],
+ RenderVars = [{'list', ["eins", "zwei", "drei"]}],
+ {ok, CompileVars, ok, RenderVars};
+setup("for") ->
+ CompileVars = [],
+ RenderVars = [{fruit_list, ["apple", "banana", "coconut"]}],
+ {ok, CompileVars, ok, RenderVars};
+setup("for_list") ->
+ CompileVars = [],
+ RenderVars = [{fruit_list, [["apple", "apples", "$1"], ["banana", "bananas", "$2"], ["coconut", "coconuts", "$500"]]}],
+ {ok, CompileVars, ok, RenderVars};
+setup("for_tuple") ->
+ CompileVars = [],
+ RenderVars = [{fruit_list, [{"apple", "apples"}, {"banana", "bananas"}, {"coconut", "coconuts"}]}],
+ {ok, CompileVars, ok, RenderVars};
+setup("for_list_preset") ->
+ CompileVars = [{fruit_list, [["apple", "apples"], ["banana", "bananas"], ["coconut", "coconuts"]]}],
+ RenderVars = [],
+ {ok, CompileVars, ok, RenderVars};
+setup("for_preset") ->
+ CompileVars = [{fruit_list, ["preset-apple", "preset-banana", "preset-coconut"]}],
+ RenderVars = [],
+ {ok, CompileVars, ok, RenderVars};
+setup("for_records") ->
+ CompileVars = [],
+ Link1 = [{name, "Amazon"}, {url, "http://amazon.com"}],
+ Link2 = [{name, "Google"}, {url, "http://google.com"}],
+ Link3 = [{name, "Microsoft"}, {url, "http://microsoft.com"}],
+ RenderVars = [{link_list, [Link1, Link2, Link3]}],
+ {ok, CompileVars, ok, RenderVars};
+setup("for_records_preset") ->
+ Link1a = [{name, "Amazon (preset)"}, {url, "http://amazon.com"}],
+ Link2a = [{name, "Google (preset)"}, {url, "http://google.com"}],
+ Link3a = [{name, "Microsoft (preset)"}, {url, "http://microsoft.com"}],
+ CompileVars = [{software_links, [Link1a, Link2a, Link3a]}],
+ Link1b = [{name, "Canon"}, {url, "http://canon.com"}],
+ Link2b = [{name, "Leica"}, {url, "http://leica.com"}],
+ Link3b = [{name, "Nikon"}, {url, "http://nikon.com"}],
+ RenderVars = [{photo_links, [Link1b, Link2b, Link3b]}],
+ {ok, CompileVars, ok, RenderVars};
+setup("include") ->
+ CompileVars = [],
+ RenderVars = [{var1, "foostring1"}, {var2, "foostring2"}],
+ {ok, CompileVars, ok, RenderVars};
+setup("if") ->
+ CompileVars = [],
+ RenderVars = [{var1, "something"}],
+ {ok, CompileVars, ok, RenderVars};
+setup("if_preset") ->
+ CompileVars = [{var1, "something"}],
+ RenderVars = [],
+ {ok, CompileVars, ok, RenderVars};
+setup("ifequal") ->
+ CompileVars = [],
+ RenderVars = [{var1, "foo"}, {var2, "foo"}, {var3, "bar"}],
+ {ok, CompileVars, ok, RenderVars};
+setup("ifequal_preset") ->
+ CompileVars = [{var1, "foo"}, {var2, "foo"}],
+ RenderVars = [{var3, "bar"}],
+ {ok, CompileVars, ok, RenderVars};
+setup("ifnotequal") ->
+ CompileVars = [],
+ RenderVars = [{var1, "foo"}, {var2, "foo"}, {var3, "bar"}],
+ {ok, CompileVars, ok, RenderVars};
+setup("ifnotequal_preset") ->
+ CompileVars = [{var1, "foo"}, {var2, "foo"}],
+ RenderVars = [],
+ {ok, CompileVars, ok, RenderVars};
+setup("var") ->
+ CompileVars = [],
+ RenderVars = [{var1, "foostring1"}, {var2, "foostring2"}, {var_not_used, "foostring3"}],
+ {ok, CompileVars, ok, RenderVars};
+setup("var_preset") ->
+ CompileVars = [{preset_var1, "preset-var1"}, {preset_var2, "preset-var2"}],
+ RenderVars = [{var1, "foostring1"}, {var2, "foostring2"}],
+ {ok, CompileVars, ok, RenderVars};
+setup("var_error") ->
+ CompileVars = [],
+ RenderVars = [{var1, "foostring1"}],
+ {ok, CompileVars, error, RenderVars};
+%% Custom tag
+setup("custom_tag") ->
+ CompileVars = [],
+ RenderVars = [],
+ {ok, CompileVars, ok, RenderVars};
+%% Custom tag
+setup("custom_tag_error") ->
+ CompileVars = [],
+ RenderVars = [],
+ {error, CompileVars, ignore, RenderVars};
+%% Custom tag
+setup("custom_call") ->
+ CompileVars = [],
+ RenderVars = [{var1, "something"}],
+ {ok, CompileVars, ok, RenderVars};
+setup(_) ->
+ undefined.
+
+
+
+
+
+
+
+
+
+
+
Oops, something went wrong.

0 comments on commit 8406c54

Please sign in to comment.