Skip to content

Commit

Permalink
Compile false as false (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmzeeman authored Jun 7, 2022
1 parent a600e32 commit 321bec7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/filter_template_compiler_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ template_compiler_test(Value, _Context) when is_integer(Value) ->
template_compiler_test(Value, _Context) ->
2*z_convert:to_integer(iolist_to_binary(Value)).

template_compiler_test(A, <<"w">>, _Context) ->
io_lib:format("~w", [A]);
template_compiler_test(A, B, _Context) ->
[
z_convert:to_binary(A),
Expand Down
2 changes: 1 addition & 1 deletion src/template_compiler_expr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ compile({ast, Ast}, _CState, Ws) ->
compile(true, _CState, Ws) ->
{Ws, erl_syntax:atom(true)};
compile(false, _CState, Ws) ->
{Ws, erl_syntax:atom(true)};
{Ws, erl_syntax:atom(false)};
compile(undefined, _CState, Ws) ->
{Ws, erl_syntax:atom(undefined)};
compile({string_literal, SrcPos, Text}, _CState, Ws) when is_binary(Text) ->
Expand Down
13 changes: 13 additions & 0 deletions test/template_compiler_expr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ groups() ->
[expr_test
,expr_op_test
,expr_filter
,expr_literals
,expr_nested
,expr_autoid
,expr_map
Expand Down Expand Up @@ -70,6 +71,18 @@ expr_filter(_Config) ->
<<"*1:2*1:3:2*">> = iolist_to_binary(Bin2),
ok.

expr_literals(_Config) ->
{ok, Bin1} = template_compiler:render("literals.tpl", #{}, [], undefined),
<<"true
false
undefined
42
<<104,101,108,108,111,32,119,111,114,108,100>>
atom
[a,b,c]
#{<<97>> => 1,<<98>> => 2}\n">>, iolist_to_binary(Bin1),
ok.

expr_nested(_Config) ->
Vars1 = #{
a => #{
Expand Down
8 changes: 8 additions & 0 deletions test/test-data/literals.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ true | template_compiler_test:"w" }}
{{ false | template_compiler_test:"w" }}
{{ undefined | template_compiler_test:"w" }}
{{ 42 | template_compiler_test:"w" }}
{{ "hello world" | template_compiler_test:"w" }}
{{ `atom` | template_compiler_test:"w" }}
{{ [`a`, `b`, `c`] | template_compiler_test:"w" }}
{{ %{ a : 1, b: 2 } | template_compiler_test:"w" }}

0 comments on commit 321bec7

Please sign in to comment.