Permalink
Browse files

* More Erlang-y error messages

* Allow proplist variables to be keyed with strings (not just atoms)



git-svn-id: http://erlydtl.googlecode.com/svn/trunk@163 a5195066-8e3e-0410-a82a-05b01b1b9875
  • Loading branch information...
1 parent 280069a commit 8f3835dc8b415bc180741fa2bab79e67b037b498 emmiller committed Sep 27, 2009
@@ -195,6 +195,8 @@ parse(File, Context) ->
case parse(CheckSum, Data, Context) of
{error, Msg} when is_list(Msg) ->
{error, File ++ ": " ++ Msg};
+ {error, Msg} ->
+ {error, {File, Msg}};
Result ->
Result
end;
@@ -3,7 +3,7 @@
-compile(export_all).
find_value(Key, L) when is_list(L) ->
- proplists:get_value(Key, L);
+ proplists:get_value(Key, L, proplists:get_value(atom_to_list(Key), L));
find_value(Key, {GBSize, GBData}) when is_integer(GBSize) ->
case gb_trees:lookup(Key, {GBSize, GBData}) of
{value, Val} ->
@@ -194,15 +194,15 @@ scan([H | T], Scanned, {Row, Column}, {in_code, Closer}) ->
digit ->
scan(T, [{number_literal, {Row, Column}, [H]} | Scanned], {Row, Column + 1}, {in_number, Closer});
_ ->
- {error, io_lib:format("Illegal character line ~p column ~p", [Row, Column])}
+ {error, {illegal_character, {line, Row}, {column, Column}}}
end;
scan([H | T], Scanned, {Row, Column}, {in_number, Closer}) ->
case char_type(H) of
digit ->
scan(T, append_char(Scanned, H), {Row, Column + 1}, {in_number, Closer});
_ ->
- {error, io_lib:format("Illegal character line ~p column ~p", [Row, Column])}
+ {error, {illegal_character, {line, Row}, {column, Column}}}
end;
scan([H | T], Scanned, {Row, Column}, {in_identifier, Closer}) ->
@@ -212,7 +212,7 @@ scan([H | T], Scanned, {Row, Column}, {in_identifier, Closer}) ->
digit ->
scan(T, append_char(Scanned, H), {Row, Column + 1}, {in_identifier, Closer});
_ ->
- {error, io_lib:format("Illegal character line ~p column ~p", [Row, Column])}
+ {error, {illegal_character, {line, Row}, {column, Column}}}
end.
% internal functions
@@ -2,8 +2,6 @@
-export([run_tests/0]).
--define(DISPLAY_PASSES, false).
-
run_tests() ->
io:format("Running date format tests...~n"),
Failures = test_group_runner([
@@ -181,9 +179,6 @@ test_runner(DateParam, [{Input, Expect} | Rest], TestNum, PassCount) ->
IsPass = is(TestNum, Text, erlydtl_dateformat:format(DateParam, Input), Expect),
test_runner(DateParam, Rest, TestNum + 1, PassCount + IsPass).
-is(TestNum, Text, Input1, Input2) when Input1 =:= Input2, ?DISPLAY_PASSES ->
- io:format("~nok ~p - ~s", [TestNum, Text]),
- 1;
is(_TestNum, _Text, Input1, Input2) when Input1 =:= Input2 ->
1;
is(TestNum, Text, Input1, Input2) ->
@@ -58,6 +58,8 @@ tests() ->
<<"{{ var1 }} is my game">>, [{var1, "bar"}], <<"bar is my game">>},
{"Render variable with attribute",
<<"I enjoy {{ var1.game }}">>, [{var1, [{game, "Othello"}]}], <<"I enjoy Othello">>},
+ {"Render variable with string-key attribute",
+ <<"I also enjoy {{ var1.game }}">>, [{var1, [{"game", "Parcheesi"}]}], <<"I also enjoy Parcheesi">>},
{"Render variable in dict",
<<"{{ var1 }}">>, dict:store(var1, "bar", dict:new()), <<"bar">>},
{"Render variable in gb_tree",

0 comments on commit 8f3835d

Please sign in to comment.